#include <bits/stdc++.h>
using namespace std;
string f(string s) {
  string s1 = "";
  for (int i = 0; i < s.length(); ++i)
    if (s[i] != '-' && s[i] != '_' && s[i] != ';') s1 += s[i];
  return s1;
}
bool d(string s, string s1) {
  if (s.length() != s1.length()) return false;
  for (int i = 0; i < s.length(); ++i)
    if (toupper(s[i]) != toupper(s1[i])) return false;
  return true;
}
int main() {
  string s, s1, s2, s3;
  int n;
  cin >> s >> s1 >> s2;
  s = f(s);
  s1 = f(s1);
  s2 = f(s2);
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> s3;
    s3 = f(s3);
    if (d(s + s1 + s2, s3) || d(s + s2 + s1, s3) || d(s1 + s2 + s, s3) ||
        d(s1 + s + s2, s3) || d(s2 + s1 + s, s3) || d(s2 + s + s1, s3))
      cout << "ACC\n";
    else
      cout << "WA\n";
  }
  return 0;
}
