Under construction

Still being built. Things may change

Conway

Time limit5sMemory limit512 MB

Summary
Roland and Patrick take turns toggling switch pairs wired to bulbs, and the task is to decide whether Roland can keep the lit bulbs' total power at least K.
Level

Hard8 of 10

Topics
Game theory, Bit manipulation, Divide and conquer, Math
Solved
No attempts yet

Problem

There are MM light bulbs in a room and NN switches outside of it. NN is guaranteed to be odd. Each bulb has its own power p_ip\_i and can only be fully on or fully off. If a bulb is on, it adds p_ip\_i units to the illumination of the room.

Some switches and bulbs are connected by cords. Toggling a switch changes the state of every bulb connected to it. There are no restrictions on connections: any switch can be connected to any subset of bulbs, and the reverse also holds.

John invented a game and invited his friends Roland and Patrick to play it. Roland likes light and tries to make the illumination as high as possible. Patrick wants the opposite and tries to make it as low as possible. John chooses a value KK to decide the winner. When the game ends, if the total power of the bulbs that are on is at least KK, Roland wins. Otherwise, Patrick wins. The game proceeds as follows.

  • Switches are numbered from 1 to NN.
  • Each player makes exactly N−12\dfrac{N - 1}{2} moves, alternating turns. Roland moves first.
  • On his ii-th move, Roland can toggle switches 2⋅i−12 \cdot i - 1 and 2⋅i2 \cdot i. On his first move these are switches 1 and 2, on his second move switches 3 and 4, and so on. He may toggle one of them, both, or neither. If a bulb is connected to both switches, its state changes once for each toggled switch.
  • Patrick follows the same rules with different switches. On his ii-th move, he can toggle switches 2⋅i2 \cdot i and 2⋅i+12 \cdot i + 1. On his first move these are switches 2 and 3, on his second move switches 4 and 5, and so on.

John already knows the result of each game. Write a program that determines the winner of each of the TT games, assuming both Roland and Patrick play optimally.

Input

The first line contains the number of test cases TT (1≤T≤51 \le T \le 5). Each test case describes one game.

The first line of each test case contains three integers NN, MM, and KK (3≤N≤333 \leq N \leq 33, NN is odd, 1≤M≤321 \leq M \leq 32, 0≤K≤2⋅1090 \leq K \leq 2 \cdot 10^{9}), where NN is the number of switches, MM is the number of bulbs, and KK is the illumination threshold.

The second line contains MM integers lil_i (1≤li≤5⋅1071 \leq l_i \leq 5 \cdot 10^{7}), the power of each bulb.

The next NN lines each contain MM characters. If switch ii is connected to bulb jj, the jj-th character of the ii-th line is '1'. Otherwise it is '0'.

Output

For each test case, print one line with the winner, either "Roland" or "Patrick".

Hint

In the first game, one optimal strategy for Roland is to toggle switches 1 and 2 on his first turn. After any move by Patrick, exactly one bulb is on at the end, so Roland wins regardless.

In the second game, whatever Roland does, Patrick can turn off all the bulbs.

Examples1

  1. Example 1

    Input
    2
    3 2 10
    10 10
    01
    00
    11
    3 5 1
    1 2 3 4 5
    01011
    11000
    10011
    
    Expected output
    Roland
    Patrick