欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1634C.OKEA
OKEA
People worry that computers will get too smart and take over the world, but the real problem is that they're too stupid and they've already taken over the world.— Pedro Domingos
You work for a well-known department store that uses leading technologies and employs mechanistic work — that is, robots!
The department you work in sells items. The first item costs dollar, the second item costs dollars, and so on: -th item costs dollars. The items are situated on shelves. The items form a rectangular grid: there are shelves in total, and each shelf contains exactly items. We will denote by the price of -th item (counting from the left) on the -th shelf, .
Occasionally robots get curious and ponder on the following question: what is the mean price (arithmetic average) of items for some shelf and indices ? Unfortunately, the old robots can only work with whole numbers. If the mean price turns out not to be an integer, they break down.
You care about robots' welfare. You want to arrange the items in such a way that the robots cannot theoretically break. Formally, you want to choose such a two-dimensional array that:
- Every number from to (inclusively) occurs exactly once.
- For each , the mean price of items from to on -th shelf is an integer.
Find out if such an arrangement is possible, and if it is, give any example of such arrangement.
Input
The first line contains a single integer () — the number of test cases.
The first and only line of each test case contains two integers and () — the number of shelves and length of each shelf, respectively.
It is guaranteed that the sum over all test cases does not exceed and the sum over all test cases does not exceed .
Output
Print the answer for each test case.
If such an arrangement exists, print "YES" on a single line. After that, print any example on lines of numbers each, one line per shelf. Each number from to must occur exactly once in the output.
If no good arrangement exists, print a single word "NO" on its own line.
Samples
4
1 1
2 2
3 3
3 1
YES
1
YES
1 3
2 4
NO
YES
1
2
3
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |