#include <bits/stdc++.h>
using namespace std;
const long long inf = (1LL) << 50;
enum { IDLE = -1, PUTR = 0, PUTL = 1, DRAW = 2, BACK = 3 };
bool isend(int *a) {
  for (int i = 0; i < 4; i++)
    if (a[i] != -1) return false;
  return true;
}
bool canput(int a, int b) {
  int vala = a / 4, valb = b / 4;
  return (vala + 1) % 13 == valb || (valb + 1) % 13 == vala;
}
bool isgreater(int a, int b) {
  if (a / 4 != b / 4)
    return a / 4 > b / 4;
  else
    return a % 4 > b % 4;
}
bool solve(queue<int> *deck) {
  long long now = 0, time[2];
  int have[2][4];
  int table[2];
  int state[2];
  int hand[2], place[2];
  int lastput[2];
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < 4; j++) have[i][j] = -1;
    for (int j = 0; j < 4 && deck[i].size(); j++) {
      have[i][j] = deck[i].front();
      deck[i].pop();
    }
  }
  state[0] = IDLE;
  state[1] = IDLE;
  while (true) {
    long long next = inf;
    if (state[0] == IDLE && state[1] == IDLE) {
      for (int i = 0; i < 2; i++) {
        if (deck[i].size()) {
          table[i] = deck[i].front();
          deck[i].pop();
        } else {
          for (int j = 0; j < 4; j++) {
            if (have[i][j] != -1) {
              lastput[i] = have[i][j];
              table[i] = have[i][j];
              have[i][j] = -1;
              break;
            }
          }
        }
      }
      next = 500;
      time[0] = time[1] = 0;
      state[0] = state[1] = IDLE;
    } else if (state[0] == IDLE) {
      next = time[1];
    } else if (state[1] == IDLE) {
      next = time[0];
    } else
      next = min(time[0], time[1]);
    if (next == inf)
      ;
    else
      now += next;
    for (int i = 0; i < 2; i++)
      if (state[i] != IDLE) time[i] -= next;
    for (int i = 0; i < 2; i++) {
      if ((state[i] == PUTR && state[1 - i] == PUTL && time[i] == 0) ||
          (state[i] == PUTL && state[1 - i] == PUTR && time[i] == 0)) {
        have[1 - i][place[1 - i]] = hand[1 - i];
        time[1 - i] = 500;
        state[1 - i] = BACK;
      }
    }
    for (int i = 0; i < 2; i++) {
      if (time[i] != 0) continue;
      if (state[i] == IDLE) {
      } else if (state[i] == PUTR || state[i] == PUTL) {
        if (state[i] == PUTR)
          table[i] = hand[i];
        else if (state[i] == PUTL)
          table[1 - i] = hand[i];
        lastput[i] = hand[i];
        if (deck[i].size()) {
          hand[i] = deck[i].front();
          deck[i].pop();
          time[i] = 300;
          state[i] = DRAW;
        } else
          have[i][place[i]] = -1;
      } else if (state[i] == DRAW) {
        have[i][place[i]] = hand[i];
      } else if (state[i] == BACK) {
      }
    }
    for (int i = 0; i < 2; i++) {
      if (time[i] != 0) continue;
      state[i] = IDLE;
      hand[i] = -1;
      for (int j = 0; j < 4; j++) {
        if (have[i][j] != -1 && canput(have[i][j], table[i]) &&
            (hand[i] == -1 || isgreater(hand[i], have[i][j]))) {
          hand[i] = have[i][j];
          place[i] = j;
          state[i] = PUTR;
          time[i] = 500;
        }
      }
      if (state[i] == IDLE) {
        for (int j = 0; j < 4; j++) {
          if (have[i][j] != -1 && canput(have[i][j], table[1 - i]) &&
              (hand[i] == -1 || isgreater(hand[i], have[i][j]))) {
            hand[i] = have[i][j];
            place[i] = j;
            state[i] = PUTL;
            time[i] = 700;
          }
        }
      }
    }
    if (isend(have[0]) && isend(have[1]))
      return lastput[0] > lastput[1];
    else if (isend(have[0]))
      return true;
    else if (isend(have[1]))
      return false;
  }
  assert(false);
}
int main() {
  string suit = "CDHS";
  string tmp = "23456789XJQKA";
  map<string, int> M;
  for (int j = 0; j < tmp.size(); j++) {
    for (int i = 0; i < suit.size(); i++) {
      string ins = string(1, suit[i]);
      ins += tmp[j];
      M[ins] = i + j * 4;
    }
  }
  int n;
  while (cin >> n && n) {
    queue<int> S[2];
    for (int i = 0; i < n; i++) {
      string in;
      cin >> in;
      S[0].push(M[in]);
    }
    cin >> n;
    for (int i = 0; i < n; i++) {
      string in;
      cin >> in;
      S[1].push(M[in]);
    }
    if (solve(S))
      cout << "A wins." << endl;
    else
      cout << "B wins." << endl;
  }
  return false;
}
