CF2107B.Apples in Boxes

传统题 时间 2000 ms 内存 256 MiB 5 尝试 1 已通过 1 标签

Apples in Boxes

Tom and Jerry found some apples in the basement. They decided to play a game to get some apples.

There are nn boxes, and the ii-th box has aia_i apples inside. Tom and Jerry take turns picking up apples. Tom goes first. On their turn, they have to do the following:

  • Choose a box ii (1in1 \le i \le n) with a positive number of apples, i.e. ai>0a_i \gt 0, and pick 11 apple from this box. Note that this reduces aia_i by 11.
  • If no valid box exists, the current player loses.
  • If after the move, $\max(a_1, a_2, \ldots, a_n) - \min(a_1, a_2, \ldots, a_n) \gt k$ holds, then the current player (who made the last move) also loses.

If both players play optimally, predict the winner of the game.

Input

Each test contains multiple test cases. The first line contains the number of test cases tt (1t1041 \le t \le 10^4). The description of the test cases follows.

The first line of each test case contains two integers n,kn,k (2n105,1k1092 \le n \le 10^5,1\le k \le 10^9).

The second line of each test case contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n (1ai1091 \le a_i \le 10^9).

It is guaranteed that the sum of nn over all test cases does not exceed 10510^5.

Output

For each test case, print "Tom" (without quotes) if Tom will win, or "Jerry" (without quotes) otherwise.

Note

Note that neither player is necessarily playing an optimal strategy in the following games, just to give you an idea of how the game is going.

In the first test case of the example, one possible situation is shown as follows.

  • Tom takes an apple from the first box. The array aa becomes [1,1,2][1, 1, 2]. Tom does not lose because max(1,1,2)min(1,1,2)=1k\max(1, 1, 2) - \min(1, 1, 2) = 1 \le k.
  • Jerry takes an apple from the first box as well. The array aa becomes [0,1,2][0, 1, 2]. Jerry loses because max(0,1,2)min(0,1,2)=2>k\max(0, 1, 2) - \min(0, 1, 2) = 2 \gt k.

Samples

3
3 1
2 1 2
3 1
1 1 3
2 1
1 4
Tom
Tom
Jerry

在线编程 IDE

建议全屏模式获得最佳体验