John Horton Conway (born 1937) is a British mathematician. He is well known for inventing the cellular automaton usually called the "Game of Life". This problem comes from a game Conway invented in the 1970s.
The game is played with a rectangular sheet of brownies fresh out of the oven. The players are Harry, who cuts only horizontally, and Vicky, who cuts only vertically. At the start there is a single piece made of B×D connected squares, where B is the breadth of the sheet and D is its depth.
On each turn a player picks one of the remaining pieces and, if a cut is possible, cuts it into two smaller pieces whose breadth and depth are both integers. A horizontal cut by Harry splits the depth of a piece into two positive integers, and a vertical cut by Vicky splits its breadth into two positive integers. Pieces may not be rotated before or after a cut. A player who cannot cut any remaining piece on their turn loses.
Look at a few examples. The simplest game is 1×1. Neither Harry nor Vicky can move, so whoever starts loses. A 1×2 sheet is a win for Harry no matter who starts, and for the same reason a 2×1 sheet is a win for Vicky no matter who starts.
A 2×2 sheet is a loss for whoever starts. If Vicky starts, her only move leaves Harry with 1×2 and 1×2, and once he cuts either piece Vicky is left with 1×1, 1×1, 1×2 and no move at all. By symmetry Harry loses if he has to start.
Intuition suggests that Vicky tends to win when the sheet is broader than it is deep, since such a sheet allows more vertical cuts, but look at 3×2. If Harry starts, his only possible move leaves Vicky with 3×1 and 3×1, which she wins. If Vicky starts, every move of hers leaves Harry with 1×2 and 2×2. Harry answers and leaves Vicky with 1×1, 1×1, 2×2, which she eventually loses, because the two 1×1 pieces allow no move and the 2×2 game is lost by whoever moves in it first.
A 4×2 sheet is a win for Vicky no matter who starts. If Harry starts, he runs out of moves after his first cut. If Vicky starts, her best move is to cut down the middle, leaving Harry with 2×2 and 2×2, which he loses because each 2×2 game is lost by whoever moves in it first.
Given the initial size of the sheet and the name of the player who starts, write a program that decides whether the starting player has a strategy that forces a win.
The first line contains an integer N (1≤N≤10), the number of test cases. Each of the next N lines holds one test case: two integers B and D and a string S, separated by spaces. B is the initial breadth of the sheet (1≤B≤500), D is its initial depth (1≤D≤500), and S is either Harry or Vicky, depending on who moves first.
For each test case, print on one line whether the player who starts can force a win. Print the name of the starting player, followed by can win or cannot win.