#include <bits/stdc++.h>
using namespace std;
void toLowerString(string& str) {
  for (int iCh = 0; iCh < str.length(); ++iCh) {
    str[iCh] = tolower(str[iCh]);
  }
}
string removeSigns(string& str) {
  string res = "";
  for (int iStr = 0; iStr < str.length(); ++iStr) {
    if (str[iStr] == '-' || str[iStr] == ';' || str[iStr] == '_') {
    } else {
      res += str[iStr];
    }
  }
  return res;
}
void resetIndice(queue<int>& indice) {
  while (!indice.empty()) indice.pop();
  indice.push(0);
  indice.push(1);
  indice.push(2);
}
bool compareWord(string w1, string w2) { return w1.length() > w2.length(); }
int main() {
  string words[3];
  queue<int> indice;
  for (int iWord = 0; iWord < 3; ++iWord) {
    cin >> words[iWord];
    words[iWord] = removeSigns(words[iWord]);
    toLowerString(words[iWord]);
  }
  sort(words, words + 3, compareWord);
  int nAnswers, iFrom, cnt, prevSize;
  string answer, word;
  cin >> nAnswers;
  for (int iAnswer = 0; iAnswer < nAnswers; ++iAnswer) {
    cin >> answer;
    answer = removeSigns(answer);
    toLowerString(answer);
    resetIndice(indice);
    iFrom = 0;
    cnt = 0;
    while (true) {
      prevSize = indice.size();
      for (int i = 0; !indice.empty() && i < 3; ++i) {
        word = words[indice.front()];
        if (answer.substr(iFrom, word.length()) == word) {
          iFrom += word.length();
          ++cnt;
        } else {
          indice.push(indice.front());
        }
        indice.pop();
      }
      if (cnt == 3) {
        cout << "ACC" << endl;
        break;
      } else if (prevSize == indice.size()) {
        cout << "WA" << endl;
        break;
      }
    }
  }
  return 0;
}
