#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000 + 5;
const double EPS = 1e-9;
const long long INF = 1e9;
char s[MAXN];
string word[10];
int main() {
  char c;
  string s2[5];
  for (int i = 0; i < 3; i++) {
    scanf("%s", s);
    scanf("%1c", &c);
    int n = strlen(s);
    s2[i] = "";
    for (int j = 0; j < n; j++) {
      if (s[j] >= 'A' && s[j] <= 'Z') {
        s[j] = (char)('a' + s[j] - 'A');
      }
      if (!(s[j] == '-' || s[j] == ';' || s[j] == '_')) {
        s2[i] += s[j];
      }
    }
  }
  int a[4];
  for (int i = 0; i < 3; i++) {
    a[i] = i;
  }
  for (int i = 0; i < 6; i++) {
    next_permutation(a, a + 3);
    word[i] = "";
    for (int j = 0; j < 3; j++) {
      word[i] += s2[a[j]];
    }
  }
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%1c", &c);
    scanf("%s", s);
    int len = strlen(s);
    string cur = "";
    for (int j = 0; j < len; j++) {
      if (s[j] >= 'A' && s[j] <= 'Z') {
        s[j] = (char)('a' + s[j] - 'A');
      }
      if (!(s[j] == '-' || s[j] == ';' || s[j] == '_')) {
        cur += s[j];
      }
    }
    bool good = false;
    for (int j = 0; j < 6; j++) {
      if (!cur.compare(word[j])) {
        good = true;
        break;
      }
    }
    if (good)
      printf("ACC\n");
    else
      printf("WA\n");
  }
  return 0;
}
