#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18 + 10, mod = 2147493647;
string a[5];
char str[5][100010];
map<string, int> ans;
int main() {
  for (int i = 0; i < 3; i++) scanf("%s", &str[i]);
  for (int i = 0; i < 3; i++) {
    int len = strlen(str[i]);
    for (int j = 0; j < len; j++) {
      if (str[i][j] >= 'a' && str[i][j] <= 'z') a[i] += str[i][j];
      if (str[i][j] >= 'A' && str[i][j] <= 'Z') a[i] += str[i][j] - 'A' + 'a';
    }
  }
  ans[a[0]] = 1;
  ans[a[1]] = 1;
  ans[a[2]] = 1;
  ans[a[0] + a[1]] = 1;
  ans[a[1] + a[0]] = 1;
  ans[a[0] + a[2]] = 1;
  ans[a[2] + a[0]] = 1;
  ans[a[1] + a[2]] = 1;
  ans[a[2] + a[1]] = 1;
  ans[a[0] + a[1] + a[2]] = 1;
  ans[a[0] + a[2] + a[1]] = 1;
  ans[a[1] + a[0] + a[2]] = 1;
  ans[a[1] + a[2] + a[0]] = 1;
  ans[a[2] + a[0] + a[1]] = 1;
  ans[a[2] + a[1] + a[0]] = 1;
  int q;
  scanf("%d", &q);
  while (q--) {
    string k = "";
    scanf("%s", str[4]);
    int len = strlen(str[4]);
    for (int i = 0; i < len; i++) {
      if (str[4][i] >= 'a' && str[4][i] <= 'z') k += str[4][i];
      if (str[4][i] >= 'A' && str[4][i] <= 'Z') k += str[4][i] - 'A' + 'a';
    }
    if (ans[k])
      printf("ACC\n");
    else
      printf("WA\n");
  }
  return 0;
}
