The Game of Master-Mind

Time limit1sMemory limit128 MB

Problem

Master-Mind is a classic two-player logic game.

One player chooses a secret code of P ordered pins. Each pin has one of a predefined set of C colours. Some colours may be absent from the code, and some may appear more than once.

The other player tries to guess the secret code. A guess is a sequence of P colours, formed the same way as the code. After each guess the first player returns a hint made of B black points and W white points:

  • a black point is awarded for every pin that has the right colour in the right position;
  • a white point is awarded for every pin that has the right colour but in the wrong position.

For example, if the secret code is (white, yellow, red, blue, white) and the guess is (white, red, white, white, blue), the hint is one black point (the white pin in the first position) and three white points (for the remaining white, the red, and the blue).

You are given a sequence of guesses that have already been played together with their hints. Make the next guess: any code that is still consistent with every hint seen so far.

Input

The first line contains a single positive integer T, the number of test cases.

Each test case begins with a line containing three integers P, C and M:

  • P (1 ≤ P ≤ 10) — the number of pins;
  • C (1 ≤ C ≤ 100) — the number of colours;
  • M (1 ≤ M ≤ 100) — the number of guesses already played.

Then 2·M lines follow, two per played guess. The first line lists P integers, the colours Gᵢ (1 ≤ Gᵢ ≤ C) of the guess; the second line contains two integers B and W, the black and white points of the corresponding hint.

Formally, for a secret code S₁ … S_P and a guess G₁ … G_P consider every set H of index pairs (I, J) with S_I = G_J such that no index is used twice on either side (for any two pairs (I₁, J₁) and (I₂, J₂) we have I₁ ≠ I₂ and J₁ ≠ J₂). Let B(H) be the number of pairs with I = J and W(H) the number of pairs with I ≠ J. Order the sets by (B(H), W(H)) lexicographically and take the maximal set H_max; then B(H_max) and W(H_max) are the black and white points of the hint.

Output

For every test case print a single line with P integers: the colours of the next guess.

The guess must be consistent with every previous guess and hint — that is, it must be a code that could still be the secret. If several codes are consistent, print the lexicographically smallest one. If no code is consistent, print the line You are cheating! instead.

(A code A is lexicographically smaller than a code B if, at the first position where they differ, A has the smaller colour.)