A. Little Artem_牛哄哄的柯南

题目链接:http://codeforces.com/contest/1333/problem/A

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 (1≤t≤201≤t≤20). Each of the next tt lines contains two integers n,mn,m (2≤n,m≤1002≤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=5, W=4. You can see the coloring in the statement.

题意:n行m列的方格,每个方块旁至少一个与其颜色相反的方块,B比W多一。

代码:

#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; // 方便B和W交替变换

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

        {

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

            {

                if(ans%2!=0)

                {

                    s[i][j]='B';  //先填B

                    ans++;

                }

                else

                {

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

                    ans++;

                }

            }

        }

        if(n*m%2!=0)  // 此时共奇数个方块,直接输出即可

        {

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

            {

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

                    cout<<s[i][j];

                cout<<endl;

            }

        }

        else {   // 此时共偶数个方块,此时B与W一样多,不行

            s[0][1]='B';   // B需要比W多一个,所以让前两个字符BW 变为BB

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

            {

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

                    cout<<s[i][j];

                cout<<endl;

            }

        }

    }

    return 0;

}

共同努力,加油!

本文为本人博客园复制过来,欢迎来踩https://www.cnblogs.com/Keafmd/category/1682381.html

猜你喜欢

转载自blog.csdn.net/weixin_43883917/article/details/105421392