#include <bits/stdc++.h>
using namespace std;
set<string> myset;
string source[3];
int dfs(string in) {
  int flag;
  for (int i = 0; i < 3; i++) {
    if (in == source[i]) return true;
    string s = in;
    flag = 0;
    for (int j = 0; j < source[i].size(); j++) {
      if (s[j] != source[i][j]) {
        flag = 1;
        break;
      }
    }
    if (!flag) {
      s.erase(0, source[i].size());
      if (dfs(s)) return true;
    }
  }
  return 0;
}
int main() {
  int n, flag;
  string input;
  for (int i = 0; i < 3; i++) {
    getline(cin, source[i]);
    while (source[i].find('-') != -1) {
      source[i].erase(source[i].find('-'), 1);
    }
    while (source[i].find(';') != -1) {
      source[i].erase(source[i].find(';'), 1);
    }
    while (source[i].find('_') != -1) {
      source[i].erase(source[i].find('_'), 1);
    }
    for (int j = 0; j < source[i].size(); j++)
      if (isupper(source[i][j])) source[i][j] = tolower(source[i][j]);
  }
  cin >> n;
  cin.ignore();
  for (int i = 0; i < n; i++) {
    getline(cin, input);
    while (input.find('-') != -1) {
      input.erase(input.find('-'), 1);
    }
    while (input.find(';') != -1) {
      input.erase(input.find(';'), 1);
    }
    while (input.find('_') != -1) {
      input.erase(input.find('_'), 1);
    }
    for (int j = 0; j < input.size(); j++)
      if (isupper(input[j])) input[j] = tolower(input[j]);
    if (!dfs(input))
      cout << "WA" << endl;
    else
      cout << "ACC" << endl;
  }
  return 0;
}
