B. Putting Platestime limit per test

To celebrate your birthday you have prepared a festive table! Now you want to seat as many guests as possible.

The table can be represented as a rectangle with height hh and width ww, divided into h×wh×w cells. Let (i,j)(i,j) denote the cell in the ii-th row and the jj-th column of the rectangle (1≤i≤h1≤i≤h; 1≤j≤w1≤j≤w).

Into each cell of the table you can either put a plate or keep it empty.

As each guest has to be seated next to their plate, you can only put plates on the edge of the table — into the first or the last row of the rectangle, or into the first or the last column. Formally, for each cell (i,j)(i,j) you put a plate into, at least one of the following conditions must be satisfied: i=1i=1, i=hi=h, j=1j=1, j=wj=w.

To make the guests comfortable, no two plates must be put into cells that have a common side or corner. In other words, if cell (i,j)(i,j) contains a plate, you can't put plates into cells (i−1,j)(i−1,j), (i,j−1)(i,j−1), (i+1,j)(i+1,j), (i,j+1)(i,j+1), (i−1,j−1)(i−1,j−1), (i−1,j+1)(i−1,j+1), (i+1,j−1)(i+1,j−1), (i+1,j+1)(i+1,j+1).

Put as many plates on the table as possible without violating the rules above.

Input

The first line contains a single integer tt (1≤t≤1001≤t≤100) — the number of test cases.

Each of the following tt lines describes one test case and contains two integers hh and ww (3≤h,w≤203≤h,w≤20) — the height and the width of the table.

Output

For each test case, print hh lines containing ww characters each. Character jj in line ii must be equal to 11 if you are putting a plate into cell (i,j)(i,j), and 00 otherwise. If there are multiple answers, print any.

All plates must be put on the edge of the table. No two plates can be put into cells that have a common side or corner. The number of plates put on the table under these conditions must be as large as possible.

You are allowed to print additional empty lines.

Example

input

Copy

3
3 5
4 4
5 6

output

Copy

10101
00000
10101

0100
0001
1000
0010

010101
000000
100001
000000
101010

Note

For the first test case, example output contains the only way to put 66 plates on the table.

For the second test case, there are many ways to put 44 plates on the table, example output contains one of them.

Putting more than 66 plates in the first test case or more than 44 plates in the second test case is impossible.

第一行和最后一行一样

都是1010101010101…………010101010

然后其他行

从第三行开始隔一行头和尾换成1

 倒数第二行必须是0000000000

#include<iostream>
using namespace std;
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n,m;
		cin>>n>>m;
		for(int i=0;i<n;i++)
		{	
			if(i==0||i==n-1)
			{
				for(int j=0;j<m;j++)
				{
					if(j%2==0)
					cout<<1;
					else
					cout<<0;
				}
			}
			else if(i%2==0&&i!=n-2)
			{
				for(int j=0;j<m;j++)
				{
					if(j==0||j==m-1)
					{
						cout<<1;
					}
					else
					cout<<0;
				}
			}
			else
			{
				for(int j=0;j<m;j++)
				{
					cout<<0;
				}
			}
			cout<<endl;
		}	
	}
}

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值