#include <bits/stdc++.h>
using namespace std;
bool caase(char c1, char c2) {
  char a1, a2, b1, b2;
  if (c1 >= 'a' && c1 <= 'z') {
    a1 = c1;
    a2 = c1 - 32;
  } else if (c1 >= 'A' && c1 <= 'Z') {
    a2 = c1;
    a1 = c1 + 32;
  }
  if (a1 == c2 || a2 == c2)
    return true;
  else
    return false;
}
bool comp(string a, string b) {
  int i = 0, j = 0, k, l1 = a.length(), l2 = b.length();
  while (i < l1 && j < l2) {
    if (a[i] == '_' || a[i] == ';' || a[i] == '-') {
      i++;
      continue;
    }
    if (b[j] == '_' || b[j] == ';' || b[j] == '-') {
      j++;
      continue;
    }
    if (!caase(a[i], b[j])) {
      return false;
    }
    i++;
    j++;
  }
  if (i == l1) {
    while (j < l2) {
      if (b[j] == '_' || b[j] == ';' || b[j] == '-') {
        j++;
        continue;
      }
      return false;
    }
    return true;
  }
  if (j == l2) {
    while (i < l1) {
      if (a[i] == '_' || a[i] == ';' || a[i] == '-') {
        i++;
        continue;
      }
      return false;
    }
    return true;
  }
  return true;
}
string str[3];
int main() {
  string a, b, c;
  int n;
  cin >> str[0] >> str[1] >> str[2];
  cin >> n;
  while (n--) {
    bool x = false;
    cin >> a;
    sort(str, str + 3);
    do {
      b.assign("");
      b.assign(str[0]);
      b.append(str[1]);
      b.append(str[2]);
      x = x || comp(a, b);
    } while (next_permutation(str, str + 3));
    if (x)
      cout << "ACC" << endl;
    else
      cout << "WA" << endl;
  }
  return 0;
}
