#include <bits/stdc++.h>
const int inf = int(1e9);
const int mod = inf + 7;
const double PI = acos(-1.0);
using namespace std;
const int N = 1e5 + 155;
void remove(std::string& s) {
  std::string t;
  std::transform(s.begin(), s.end(), s.begin(), ::tolower);
  int N = s.size();
  for (int i = 0; i < N; ++i) {
    if ('a' <= s[i] && s[i] <= 'z') {
      t += s[i];
    }
  }
  std::swap(s, t);
}
int main() {
  std::vector<std::string> V(3, "");
  for (int i = 0; i < 3; ++i) {
    std::cin >> V[i];
    remove(V[i]);
  }
  std::sort(V.begin(), V.end());
  int N;
  std::cin >> N;
  for (int i = 0; i < N; ++i) {
    std::string a;
    std::cin >> a;
    remove(a);
    std::vector<std::string> W = V;
    bool ok = false;
    do {
      std::string x;
      for (int j = 0; j < 3; ++j) {
        x += W[j];
      }
      if (x == a) {
        ok = true;
        break;
      }
    } while (std::next_permutation(W.begin(), W.end()));
    if (ok) {
      std::cout << "ACC";
    } else {
      std::cout << "WA";
    }
    std::cout << std::endl;
  }
}
