#include <bits/stdc++.h>
using namespace std;
double const pi = 3.1415926536;
string f(string s) {
  string b;
  for (int i = 0; i < s.length(); i++) {
    if ((s[i] >= 'A' && s[i] <= 'Z') || (s[i] >= 'a' && s[i] <= 'z')) b += s[i];
  }
  for (int i = 0; i < b.length(); i++) {
    if (b[i] >= 'A' && b[i] <= 'Z') b[i] += 32;
  }
  return (b);
}
int main() {
  string a, b, c;
  cin >> a >> b >> c;
  int n;
  cin >> n;
  string x, y, z;
  x = f(a);
  y = f(b);
  z = f(c);
  string v1, v2, v3, v4, v5, v6;
  v1 = x + y + z;
  v2 = x + z + y;
  v3 = y + x + z;
  v4 = y + z + x;
  v5 = z + y + x;
  v6 = z + x + y;
  while (n--) {
    string u, t;
    cin >> u;
    t = f(u);
    if (t == v1 || t == v2 || t == v3 || t == v4 || t == v5 || t == v6)
      cout << "ACC\n";
    else
      cout << "WA\n";
  }
}
