Under construction

Still being built. Things may change

Battleship

Time limit1sMemory limit128 MB

Summary
Given two ship maps and a list of unlabeled shots, decide which admiral won under the hit-and-shoot-again turn rules.
Level

Medium7 of 10

Topics
Simulation, Brute force, Implementation, Game theory
Solved
No attempts yet

Problem

When playing battleship, two players take turns trying to sink the other player's navy. Each shot is fired at a single coordinate. If a shot hits one of the enemy's ships and the enemy still has other ship parts left, the player may shoot again. Otherwise, the other player takes over. Once a ship part has been hit at some coordinate, shooting at that same coordinate again counts as a miss.

A navy is completely sunk when every part of every one of its ships has been hit. The first player starts, and both players take the same number of turns. Once one navy has been completely sunk the game ends at the end of that round; but because both players take the same number of turns, the second player still takes their turn during that round (even if all of their own ships have already been sunk), and that turn can still change the final result.

The result is then determined as follows. If exactly one navy has been completely sunk, the player whose navy survived wins. The game is a draw if both navies are completely sunk, or if neither navy is completely sunk after all shots have been fired (that is, ships still remain on both sides).

Tom, a little spy, watches a game of battleship between two fleet admirals. Having tapped the communication wires, he can intercept the shot orders, but he could not tell which admiral ordered which shot.

After the game he breaks into the super-secret game management facility and secures the fleet deployment maps. To decide which admiral is more dangerous, he wants to know who won.

He hands you the deployment maps and the shot orders and asks you to determine which admiral won.

Input

The input starts with a line containing the number of test cases tt (0<t≤200 < t \le 20).

Each test case starts with a line containing three integers ww, hh, and nn (1≤w,h≤301 \le w, h \le 30; 1≤n≤20001 \le n \le 2000): the width and height of the deployment maps and the number of shots.

The next hh lines contain the deployment map for player one. Each line has ww field descriptions, where _ means water and # means a ship. The following hh lines contain the deployment map for player two.

The next nn lines contain the shot orders; each order is two integers, the xx and yy coordinates of the shot. The xx coordinate is the column, from 00 to w−1w - 1, where 00 is the leftmost column. The yy coordinate is the row, from 00 to h−1h - 1, where 00 is the last (bottom) line and h−1h - 1 is the first (top) line of the corresponding map.

Note that there may be more shot orders than are needed to finish the game.

Output

For each test case, print one of "player one wins", "player two wins", or "draw" on its own line.

Examples1

  1. Example 1

    Input
    2
    4 4 5
    ____
    ____
    #___
    ____
    #___
    ___#
    ____
    ____
    0 0
    1 1
    0 3
    0 2
    0 1
    2 2 5
    _#
    #_
    #_
    #_
    1 0
    0 0
    0 0
    1 1
    0 1
    
    Expected output
    player two wins
    draw