#include <bits/stdc++.h>
using namespace std;
int isSubstring(string &s1, string s2) {
  for (int i = 0; i <= s1.length() - s2.length(); i++) {
    int j;
    for (j = 0; j < s2.length(); j++) {
      if (s1[i + j] != s2[j]) {
        break;
      }
    }
    if (j == s2.length()) {
      int endd = i + j - 1;
      int start = i;
      while (start <= endd) {
        s1[start] = '*';
        start++;
      }
      return 1;
    }
  }
  return 0;
}
int compare(string str1, string str2) {
  if (str1.length() > str2.length()) return 1;
  return 0;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  string s1, s2, s3, t1, t2, t3;
  string str[1000], tmp[1000], s[3];
  cin >> t1;
  cin >> t2;
  cin >> t3;
  for (int i = 0; i < t1.length(); i++) {
    if (t1[i] != '_' && t1[i] != '-' && t1[i] != ';') {
      s1 += tolower(t1[i]);
    }
  }
  for (int i = 0; i < t2.length(); i++) {
    if (t2[i] != '_' && t2[i] != '-' && t2[i] != ';') {
      s2 += tolower(t2[i]);
    }
  }
  for (int i = 0; i < t3.length(); i++) {
    if (t3[i] != '_' && t3[i] != '-' && t3[i] != ';') {
      s3 += tolower(t3[i]);
    }
  }
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> tmp[i];
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < tmp[i].length(); j++) {
      if (tmp[i][j] != '_' && tmp[i][j] != '-' && tmp[i][j] != ';') {
        str[i] += tolower(tmp[i][j]);
      }
    }
  }
  s[0] = s1;
  s[1] = s2;
  s[2] = s3;
  sort(s, s + 3, compare);
  int len = s1.length() + s2.length() + s3.length();
  for (int i = 0; i < n; i++) {
    if (len == str[i].length() && isSubstring(str[i], s[0]) &&
        isSubstring(str[i], s[1]) && isSubstring(str[i], s[2])) {
      cout << "ACC\n";
    } else {
      cout << "WA\n";
    }
  }
  return 0;
}
