#P1371D. Grid-00100
Grid-00100
Description
A mad scientist Dr.Jubal has made a competitive programming task. Try to solve it!
You are given integers . Construct a grid with size consisting of integers and . The very important condition should be satisfied: the sum of all elements in the grid is exactly . In other words, the number of in the grid is equal to .
Let's define:
- as the integer in the -th row and the -th column.
- (for all ).
- (for all ).
- In other words, are row sums and are column sums of the grid .
- For the grid let's define the value (here for an integer sequence we define as the maximum value in and as the minimum value in ).
Find any grid , which satisfies the following condition. Among such grids find any, for which the value is the minimum possible. Among such tables, you can find any.
The input consists of multiple test cases. The first line contains a single integer () — the number of test cases. Next lines contain descriptions of test cases.
For each test case the only line contains two integers , .
It is guaranteed that the sum of for all test cases does not exceed .
For each test case, firstly print the minimum possible value of among all tables, for which the condition is satisfied.
After that, print lines contain characters each. The -th character in the -th line should be equal to .
If there are multiple answers you can print any.
Input
The input consists of multiple test cases. The first line contains a single integer () — the number of test cases. Next lines contain descriptions of test cases.
For each test case the only line contains two integers , .
It is guaranteed that the sum of for all test cases does not exceed .
Output
For each test case, firstly print the minimum possible value of among all tables, for which the condition is satisfied.
After that, print lines contain characters each. The -th character in the -th line should be equal to .
If there are multiple answers you can print any.
Note
In the first test case, the sum of all elements in the grid is equal to , so the condition is satisfied. and . Then, , which is the minimum possible value of .
In the second test case, the sum of all elements in the grid is equal to , so the condition is satisfied. and . Then, . It can be proven, that it is the minimum possible value of .