#include <bits/stdc++.h>
using namespace std;
set<string> SC;
template <class T>
inline T sqr(T x) {
  return x * x;
}
template <class T>
inline bool isPrime(T n) {
  if (n <= 1) return false;
  for (T i = 2; i * i <= n; i++)
    if (n % i == 0) return false;
  return true;
}
template <class T>
inline T Mod(T n, T m) {
  return (n % m + m) % m;
}
template <class T>
string toString(T n) {
  ostringstream oss;
  oss << n;
  oss.flush();
  return oss.str();
}
int toInt(string s) {
  int r = 0;
  istringstream sin(s);
  sin >> r;
  return r;
}
long long toLl(string s) {
  long long r = 0;
  istringstream sin(s);
  sin >> r;
  return r;
}
bool toLower(char ch) {
  if (ch >= 97 && ch <= 122) return true;
  return false;
}
bool toUpper(char ch) {
  if (ch >= 65 && ch <= 90) return true;
  return false;
}
bool SCP(char S[], char SS[]) {
  if (!strcmp(S, SS)) return true;
  return false;
}
int Digit(int num) {
  int cn = 0;
  while (num) {
    cn++;
    num /= 10;
  }
  return cn;
}
string BaseConversion(string xstr, int xbase, int ybase) {
  string str = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
  long long store[128], i, multi, sum;
  string ystr;
  for (i = sum = 0; i < str.size(); i++) store[str[i]] = i;
  multi = 1;
  for (i = xstr.size() - 1; i >= 0; i--) {
    sum += (store[xstr[i]] * multi);
    multi *= xbase;
  }
  while (true) {
    ystr.push_back(str[sum % ybase]);
    sum /= ybase;
    if (sum == 0) break;
  }
  reverse(ystr.begin(), ystr.end());
  return ystr;
}
long long BM(long long base, long long pow, long long mod) {
  long long temp, result, rem;
  temp = base % mod;
  result = 1;
  while (pow > 0) {
    rem = pow % 2;
    pow /= 2;
    if (rem == 1) result = (result * temp) % mod;
    temp = (temp * temp) % mod;
  }
  return result;
}
template <class T>
void debug(const T& e) {
  cout << e << endl;
}
template <class T1, class T2>
void debug(const T1& e1, const T2& e2) {
  cout << e1 << "\t" << e2 << endl;
}
template <class T1, class T2, class T3>
void debug(const T1& e1, const T2& e2, const T3& e3) {
  cout << e1 << "\t" << e2 << "\t" << e3 << endl;
}
template <class T1, class T2, class T3, class T4>
void debug(const T1& e1, const T2& e2, const T3& e3, const T4& e4) {
  cout << e1 << "\t" << e2 << "\t" << e3 << "\t" << e4 << endl;
}
template <class T1, class T2, class T3, class T4, class T5>
void debug(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
           const T5& e5) {
  cout << e1 << "\t" << e2 << "\t" << e3 << "\t" << e4 << "\t" << e5 << endl;
}
template <class T>
void debug(vector<T>& e) {
  int i;
  for (i = 0; i < (int)e.size(); i++) cout << e[i] << " ";
  cout << endl;
}
template <class T>
void debug(vector<basic_string<T> >& e) {
  int i, j;
  for (i = 0; i < (int)e.size(); i++) {
    for (j = 0; j < (int)e[i].size(); j++) cout << e[i][j];
    cout << endl;
  }
  cout << endl;
}
template <class T>
void debug(vector<vector<T> >& e) {
  int i, j;
  for (i = 0; i < (int)e.size(); i++) {
    for (j = 0; j < (int)e[i].size(); j++) cout << e[i][j] << "\t";
    cout << endl;
  }
  cout << endl;
}
template <class T>
void debug(T e[100][100], int row, int col) {
  int i, j;
  for (i = 0; i < row; i++) {
    for (j = 0; j < col; j++) cout << e[i][j] << " ";
    cout << endl;
  }
}
long long Pow(long long B, long long P) {
  long long R = 1;
  while (P > 0) {
    if (P % 2 == 1) R = (R * B);
    P /= 2;
    B = (B * B);
  }
  return R;
}
int a[3001];
int main() {
  int j, test, Case = 1;
  int i, n, t, s;
  string S, S1, S2, S3, S4, S5;
  string s1, s2, s3, s4, s5, s6;
  cin >> S >> S1 >> S2;
  for (i = 0; S[i]; i++)
    if (isalpha(S[i])) {
      S[i] = tolower(S[i]);
      S3.push_back(S[i]);
    }
  for (i = 0; S1[i]; i++)
    if (isalpha(S1[i])) {
      S1[i] = tolower(S1[i]);
      S4.push_back(S1[i]);
    }
  for (i = 0; S2[i]; i++)
    if (isalpha(S2[i])) {
      S2[i] = tolower(S2[i]);
      S5.push_back(S2[i]);
    }
  S1.clear();
  S2.clear();
  S1 = S3;
  S3.clear();
  S2 = S4;
  S3 = S5;
  s1 = S1 + S2 + S3;
  s2 = S1 + S3 + S2;
  s3 = S2 + S1 + S3;
  s4 = S2 + S3 + S1;
  s5 = S3 + S2 + S1;
  s6 = S3 + S1 + S2;
  cin >> t;
  S5.clear();
  for (i = 0; i < t; i++) {
    cin >> S;
    S5.clear();
    for (j = 0; S[j]; j++)
      if (isalpha(S[j])) {
        S[j] = tolower(S[j]);
        S5.push_back(S[j]);
      }
    if (S5 == s1 || S5 == s2 || S5 == s3 || S5 == s4 || S5 == s5 || S5 == s6)
      printf("ACC\n");
    else
      printf("WA\n");
  }
  return 0;
}
