```
#include "iostream"
using namespace std;

// problem A http://www.cs.ubc.ca/~acm-web/practice/2016-09-10/problems/problemset_2012.pdf

int main()
{
int t, w, h, n, x, y;
cin >> t;

char s;
// we need 2 matrixes that are w x h
// h rows and w columns

for (int i = 0; i < t; i++) {
int ships1 = 0, ships2 = 0;
int playerATurns = 0, playerBTurns = 0;

cin >> w >> h >> n;

// create maps
int** map1 = new int*[h];
for (int j = 0; j < h; ++j)
{
map1[j] = new int[w];

for (int k = 0; k < w; k++)
{
cin >> s;
if (s == '#') {
ships1++;
map1[j][k] = 1;
}
else {
map1[j][k] = 0;
}
}
}

int** map2 = new int*[h];
for (int j = 0; j < h; ++j)
{
map2[j] = new int[w];
for (int k = 0; k < w; k++)
{
cin >> s;
if (s == '#') {
ships2++;
map2[j][k] = 1;
}
else {
map2[j][k] = 0;
}
}
}

bool earlyVictory = false;
bool turn1 = true;
int j = 0;
// start game
for (j = 0; j < n; j++) {

if (turn1) {
// P1 attacks
while (true) {
if (j >= n) { break; }

cin >> x >> y;

if (map2[h - 1 - y][x] == 1) // a hit
{
ships2--;
map2[h - 1 - y][x] = 0;
j++;

// continue if they have ships left
if (ships2 == 0)
{
// we cannot continue turn anymore
j--;
turn1 = false;
break;
}

}
else {
turn1 = false;
break;
}
}
playerATurns++;
}
else {
// P2 attacks
while (true) {
if (j >= n) { break; }
cin >> x >> y;

if (map1[h - 1 - y][x] == 1) // a hit
{
ships1--;
map1[h - 1 - y][x] = 0;
j++;

// continue if they have ships left
if (ships1 == 0)
{
// we cannot continue turn anymore
j--;
turn1 = true;
break;
}

}
else {
turn1 = true;
break;
}
}
playerBTurns++;
}
// check if one player won already
if ((ships1 == 0 || ships2 == 0) && (playerATurns == playerBTurns)) {

earlyVictory = true;
break;
}
}

// eat the rest of the shit
if (earlyVictory) {
for (int l = 0; l < n - 1 - j; l++) {
cin >> x >> y;
}
}

// end game conditions
if ((ships1 == 0 && ships2 == 0) || (ships1 > 0 && ships2 > 0)) {
cout << "draw" << endl;
}
else {
if (ships1 > 0) {
cout << "player one wins" << endl;
}
else {
cout << "player two wins" << endl;
}
}

// cleanup
for (int j = 0; j < h; ++j)
{
free(map1[j]);
free(map2[j]);
}

free(map1);
free(map2);
}

return 0;
}

```