欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1996B.Scale
Scale
Tina has a square grid with rows and columns. Each cell in the grid is either or .
Tina wants to reduce the grid by a factor of ( is a divisor of ). To do this, Tina splits the grid into nonoverlapping blocks of cells such that every cell belongs to exactly one block.
Tina then replaces each block of cells with a single cell equal to the value of the cells in the block. It is guaranteed that every cell in the same block has the same value.
For example, the following demonstration shows a grid being reduced by factor of .
Original grid
Reduced grid
Help Tina reduce the grid by a factor of .
Input
The first line contains () – the number of test cases.
The first line of each test case contains two integers and (, , is a divisor of ) — the number of rows and columns of the grid, and the factor that Tina wants to reduce the grid by.
Each of the following lines contain characters describing the cells of the grid. Each character is either or . It is guaranteed every by block has the same value.
It is guaranteed the sum of over all test cases does not exceed .
Output
For each test case, output the grid reduced by a factor of on a new line.
Samples
4
4 4
0000
0000
0000
0000
6 3
000111
000111
000111
111000
111000
111000
6 2
001100
001100
111111
111111
110000
110000
8 1
11111111
11111111
11111111
11111111
11111111
11111111
11111111
11111111
0
01
10
010
111
100
11111111
11111111
11111111
11111111
11111111
11111111
11111111
11111111
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |