#include <bits/stdc++.h>
using namespace std;
char a[103], b[103], c[103];
char aa[103], bb[103], cc[103];
char temp[103];
int temp2;
char ss[602];
char s[602];
int n;
int main() {
  scanf("%s%s%s", aa, bb, cc);
  scanf("%d", &n);
  int i, j, jj;
  int coun1 = 0, coun2 = 0, coun3 = 0;
  for (i = 0; aa[i]; i++)
    if (aa[i] != '_' && aa[i] != ';' && aa[i] != '-') a[coun1++] = aa[i];
  for (i = 0; bb[i]; i++)
    if (bb[i] != '_' && bb[i] != ';' && bb[i] != '-') b[coun2++] = bb[i];
  for (i = 0; cc[i]; i++)
    if (cc[i] != '_' && cc[i] != ';' && cc[i] != '-') c[coun3++] = cc[i];
  for (i = 0; a[i]; i++)
    if (a[i] > 96) a[i] -= 32;
  for (i = 0; b[i]; i++)
    if (b[i] > 96) b[i] -= 32;
  for (i = 0; c[i]; i++)
    if (c[i] > 96) c[i] -= 32;
  if (coun1 < coun3) {
    for (i = 0; i < coun1; i++) temp[i] = a[i];
    for (i = 0; i < coun3; i++) a[i] = c[i];
    for (i = 0; i < coun1; i++) c[i] = temp[i];
    temp2 = coun1;
    coun1 = coun3;
    coun3 = temp2;
  }
  if (coun1 < coun2) {
    for (i = 0; i < coun1; i++) temp[i] = a[i];
    for (i = 0; i < coun2; i++) a[i] = b[i];
    for (i = 0; i < coun1; i++) b[i] = temp[i];
    temp2 = coun1;
    coun1 = coun2;
    coun2 = temp2;
  }
  if (coun2 < coun3) {
    for (i = 0; i < coun2; i++) temp[i] = b[i];
    for (i = 0; i < coun3; i++) b[i] = c[i];
    for (i = 0; i < coun2; i++) c[i] = temp[i];
    temp2 = coun2;
    coun2 = coun3;
    coun3 = temp2;
  }
  a[coun1] = '\0';
  b[coun2] = '\0';
  c[coun3] = '\0';
  int coun;
  bool flag;
  bool flag2;
  bool flagi[5];
  for (i = 0; i < n; i++) {
    coun = 0;
    scanf("%s", ss);
    for (j = 0; j < 5; j++) flagi[j] = false;
    for (j = 0; ss[j]; j++)
      if (ss[j] != ';' && ss[j] != '_' && ss[j] != '-') s[coun++] = ss[j];
    for (j = 0; j < coun; j++)
      if (s[j] > 96) s[j] -= 32;
    for (j = 0; j < coun; j++) {
      flag = false;
      flag2 = true;
      for (jj = 0; a[jj]; jj++)
        if (a[jj] != s[j + jj] || j + jj == coun) flag2 = false;
      if (flag2 && !flagi[0]) {
        flag = true;
        flagi[0] = true;
        j = j + jj - 1;
        continue;
      }
      flag2 = true;
      for (jj = 0; b[jj]; jj++)
        if (b[jj] != s[j + jj] || j + jj == coun) flag2 = false;
      if (flag2 && !flagi[1]) {
        flag = true;
        flagi[1] = true;
        j = j + jj - 1;
        continue;
      }
      flag2 = true;
      for (jj = 0; c[jj]; jj++)
        if (c[jj] != s[j + jj] || j + jj == coun) flag2 = false;
      if (flag2 && !flagi[2]) {
        flag = true;
        flagi[2] = true;
        j = j + jj - 1;
        continue;
      }
      if (!flag) break;
      if (j == coun - 1) break;
    }
    if (flag) {
      for (j = 0; j < 3; j++)
        if (!flagi[j]) flag = false;
    }
    if (flag)
      printf("ACC\n");
    else
      printf("WA\n");
  }
  return 0;
}
