A. Little Artem

time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Young boy Artem tries to paint a picture, and he asks his mother Medina to help him. Medina is very busy, that's why she asked for your help.

Artem wants to paint an n×mn×m board. Each cell of the board should be colored in white or black.

Lets BB be the number of black cells that have at least one white neighbor adjacent by the side. Let WW be the number of white cells that have at least one black neighbor adjacent by the side. A coloring is called good if B=W+1B=W+1.

The first coloring shown below has B=5B=5 and W=4W=4 (all cells have at least one neighbor with the opposite color). However, the second coloring is not good as it has B=4B=4, W=4W=4 (only the bottom right cell doesn't have a neighbor with the opposite color).

Please, help Medina to find any good coloring. It's guaranteed that under given constraints the solution always exists. If there are several solutions, output any of them.

Input

Each test contains multiple test cases.

The first line contains the number of test cases tt (1t201≤t≤20). Each of the next tt lines contains two integers n,mn,m (2n,m1002≤n,m≤100) — the number of rows and the number of columns in the grid.

Output

For each test case print nn lines, each of length mm, where ii-th line is the ii-th row of your colored matrix (cell labeled with 'B' means that the cell is black, and 'W' means white). Do not use quotes.

It's guaranteed that under given constraints the solution always exists.

Example
input
Copy
2
3 2
3 3
output
Copy
BW 
WB 
BB 
BWB 
BWW 
BWB
Note

In the first testcase, B=3,W=2.

In the second testcase, B=5W=4. You can see the coloring in the statement.

 

The meaning of problems: n- rows m square columns, a square next to each opposite thereto color block, at least B ratio W one more.

 

Code:

#include<iostream>

#include<cstdio>

#include<cstring>

#include<cstdlib>

#include<cmath>

#include<algorithm>

#include<set>

#include<stack>

#include<queue>

#include<vector>

using namespace std;

typedef long long ll;

int main ()

{

    int T;

    cin>>T;

    while(T--)

    {

        int n,m;

        cin>>n>>m;

        char s[105][105];

        int ans = 1; // convenience alternating B and W

        for(int i=0; i<n; i++)

        {

            for(int j=0; j<m; j++)

            {

                if(ans%2!=0)

                {

                    s [i] [j] = 'B'; // filling in B

                    ++ years;

                }

                else

                {

                    s[i][j]='W';

                    ++ years;

                }

            }

        }

        if (n * m% 2! = 0) // At this time a total of an odd number of blocks, can be directly output

        {

            for(int i=0;i<n;i++)

            {

                for(int j=0;j<m;j++)

                    cout<<s[i][j];

                cout<<endl;

            }

        }

        else {// At this time a total of an even number of blocks, this time as much as B and W, not

            s [0] [1] = 'B'; // B requires more than W one more, so let the first two characters BW becomes BB

            for(int i=0;i<n;i++)

            {

                for(int j=0;j<m;j++)

                    cout<<s[i][j];

                cout<<endl;

            }

        }

    }

    return 0;

}

Work together, come on!

Guess you like

Origin www.cnblogs.com/Keafmd/p/12669809.html