思路:国王和车手玩很快就出来规律了,马的话比较烦,可是不过手玩一下也是可以发现规律的...然后皇后其实就是一个威佐夫博弈



#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e6+7;
int sg[maxn];
void init()
{
	int cnt = 1;
	for(int i = 2;i<=1000;i++)
	{
		if(!sg[i])
		{
			sg[i]=i+cnt;
			sg[i+cnt]=i;
			cnt++;
		}
	}
}
int main()
{
	init();
    int T;
	scanf("%d",&T);
	while(T--)
	{
		int op,n,m;
		scanf("%d%d%d",&op,&n,&m);
		if(op==1)
		{
            if((n&1) && (m&1))
				printf("G\n");
			else
				printf("B\n");
		}
		else if(op==2)
		{
            if(n==m)
				printf("G\n");
			else
				printf("B\n");
		}
		else if (op==3)
		{
            if(n==m && (n-1)%3==0)
				printf("G\n");
			else if(n-1==m && (n%3==0) || (m-1==n) && (m%3==0))
				printf("B\n");
			else
				printf("D\n");
		}
		else
		{
            if(sg[n]==m)
				printf("G\n");
			else
				printf("B\n");
		}
	}
}






Problem Description


Bo is a "Life Winner".He likes playing chessboard games with his girlfriend G.

The size of the chessboard is  N×M.The top left corner is numbered (1,1) and the lower right corner is numberd  (N,M).

For each game,Bo and G take turns moving a chesspiece(Bo first).At first,the chesspiece is located at  (1,1).And the winner is the person who first moves the chesspiece to  (N,M).At one point,if the chess can't be moved and it isn't located at  (N,M),they end in a draw.

In general,the chesspiece can only be moved right or down.Formally,suppose it is located at  (x,y),it can be moved to the next point  (x′,y′) only if  x′≥x and  y′≥y.Also it can't be moved to the outside of chessboard.

Besides,There are four kinds of chess(They have movement rules respectively).

1.king.

2.rook(castle).

3.knight.

4.queen.

(The movement rule is as same as the chess.)

For each type of chess,you should find out that who will win the game if they both play in an optimal strategy.

Print the winner's name("B" or "G") or "D" if nobody wins the game.


 



Input


T as a case number.

In the next  T lines,there are three numbers type, N and  M.

"type" means the kind of the chess.

T≤1000,2≤N,M≤1000,1≤type≤4


 



Output


For each question,print the answer.


 



Sample Input


4 1 5 5 2 5 5 3 5 5 4 5 5


 



Sample Output


G G D B


 



Source


2016 Multi-University Training Contest 3