#include <bits/stdc++.h>
using std::cin;
using std::cout;
using std::endl;
using std::string;
string ai, bi, ci, a, b, c;
string abc, acb, bac, bca, cab, cba;
int n;
string di, d;
string acc = "ACC", wa = "WA";
string qwerty(string q) {
  int l = q.size();
  string ret = "";
  for (int i = 0; i < l; ++i) {
    if (isalpha(q[i])) {
      if (isupper(q[i])) {
        ret += tolower(q[i]);
      } else {
        ret += q[i];
      }
    }
  }
  return ret;
}
int main() {
  cin >> ai >> bi >> ci >> n;
  a = qwerty(ai), b = qwerty(bi), c = qwerty(ci);
  abc = a + b + c, acb = a + c + b, bac = b + a + c, bca = b + c + a,
  cab = c + a + b, cba = c + b + a;
  while (n--) {
    cin >> di;
    d = qwerty(di);
    if (d == abc || d == acb || d == bac || d == bca || d == cab || d == cba ||
        0) {
      cout << acc << endl;
    } else {
      cout << wa << endl;
    }
  }
  return 0;
}
