The divisibility game

Two players alternately delete numbers from a set; decide whether X can force the remaining sum to be divisible by P after exactly K deletions.

Hard8Game theoryCombinatoricsMathNo attempts yetTime limit2sMemory limit512 MB

Problem

Two players, X and Y, play the following game.

  • They are given a positive integer PP and a set A={a1,a2,,aN}A = \{a_1, a_2, \ldots, a_N\} of NN distinct nonnegative integers. Every aia_i is less than PP.
  • The players take turns alternately. On each turn, the player to move deletes one number from AA.
  • After exactly KK turns, if the sum of the numbers remaining in AA is divisible by PP, X wins. Otherwise, Y wins.

Write a program that determines who wins when both players play optimally.

Input

The first line contains a positive integer TT, the number of games in the input.

Then, for each i=0,1,,T1i = 0, 1, \ldots, T-1:

  • line 3i+23i+2 contains NN, KK, and PP, separated by spaces;
  • line 3i+33i+3 contains a single character, X or Y, which is the player who moves first;
  • line 3i+43i+4 contains a1,a2,,aNa_1, a_2, \ldots, a_N, separated by spaces.

Output

Print one line with TT characters and no separators, one character per game. The ii-th character is X if X wins the ii-th game no matter how Y plays, and Y otherwise.

Limits

  • 1KN50001 \le K \le N \le 5000
  • P1018P \le 10^{18}
  • 0ai<P0 \le a_i < P for every ii, and aiaja_i \ne a_j for every iji \ne j