#include <iostream>
#include <string>
using namespace std;

int main()
{
    string str[3], ans[6], stu;

    cin >> str[0] >> str[1] >> str[2];
    for(int i = 0; i < 3; i++)
    {
        string::iterator it = str[i].begin();
        for(; it != str[i].end(); it++)
        {
            if(*it == '-' || *it == ';' || *it == '_')
                str[i].erase(it--);
            else
                *it = tolower(*it);
        }
    }
    ans[0] = str[0] + str[1] + str[2];
    ans[1] = str[0] + str[2] + str[1];
    ans[2] = str[1] + str[0] + str[2];
    ans[3] = str[1] + str[2] + str[0];
    ans[4] = str[2] + str[0] + str[1];
    ans[5] = str[2] + str[1] + str[0];

    int n;
    cin >> n;
    while(n--)
    {
        cin >> stu;
        string::iterator it = stu.begin();
        for(; it != stu.end(); it++)
        {
            if(*it == '-' || *it == ';' || *it == '_')
                stu.erase(it--);
            else
                *it = tolower(*it);
        }

        int i;
        for(i = 0; i < 6; i++)
            if(stu == ans[i])
                break;
        if(i < 6) cout << "ACC" << endl;
        else  cout << "WA" << endl;
    }

    return 0;
}


#include <iostream>
#include <string>
using namespace std;

int main()
{
    string str[3], ans[6], stu;

    cin >> str[0] >> str[1] >> str[2];
    for(int i = 0; i < 3; i++)
    {
        string::iterator it = str[i].begin();
        for(; it != str[i].end(); it++)
        {
            if(*it == '-' || *it == ';' || *it == '_')
                str[i].erase(it--);
            else if(*it < 'a')
                *it += 32;
        }
    }
    ans[0] = str[0] + str[1] + str[2];
    ans[1] = str[0] + str[2] + str[1];
    ans[2] = str[1] + str[0] + str[2];
    ans[3] = str[1] + str[2] + str[0];
    ans[4] = str[2] + str[0] + str[1];
    ans[5] = str[2] + str[1] + str[0];

    int n;
    cin >> n;
    while(n--)
    {
        cin >> stu;
        string::iterator it = stu.begin();
        for(; it != stu.end(); it++)
        {
            if(*it == '-' || *it == ';' || *it == '_')
                stu.erase(it--);
            else if(*it < 'a')
                *it += 32;
        }

        int i;
        for(i = 0; i < 6; i++)
            if(stu == ans[i])
                break;
        if(i < 6) cout << "ACC" << endl;
        else  cout << "WA" << endl;
    }

    return 0;
}


#include <iostream>
#include <string>
using namespace std;

int main()
{
    string str[3], ans[6], stu;

    cin >> str[0] >> str[1] >> str[2];
    for(int i = 0; i < 3; i++)
    {
        string::iterator it = str[i].begin();
        for(; it != str[i].end(); it++)
        {
            if(*it == '-' || *it == ';' || *it == '_')
                str[i].erase(it--);
            else
                tolower(*it);
        }
    }
    ans[0] = str[0] + str[1] + str[2];
    ans[1] = str[0] + str[2] + str[1];
    ans[2] = str[1] + str[0] + str[2];
    ans[3] = str[1] + str[2] + str[0];
    ans[4] = str[2] + str[0] + str[1];
    ans[5] = str[2] + str[1] + str[0];

    int n;
    cin >> n;
    while(n--)
    {
        cin >> stu;
        string::iterator it = stu.begin();
        for(; it != stu.end(); it++)
        {
            if(*it == '-' || *it == ';' || *it == '_')
                stu.erase(it--);
            else
                *it = tolower(*it);
        }

        int i;
        for(i = 0; i < 6; i++)
            if(stu == ans[i])
                break;
        if(i < 6) cout << "ACC" << endl;
        else  cout << "WA" << endl;
    }

    return 0;
}


#include<stdio.h>
#include<string.h>
char first[666],second[666],third[666],waste[666],checking[666];
int T1[666],T2[666],T3[666];
int c1=0,c2=0,c3=0;
//Table Building
void kmp_table (char *word,int *table)
{
    int l = strlen(word);
    int pos = 2;
    int cnd = 0;
    table[0]=-1;
    table[1]=0;
    while(pos<l)
    {
        if(word[pos-1] == word[cnd])
        {
            cnd++;
            table[pos]=cnd;
            pos++;
        }
        else if (cnd>0)
        {
            cnd = table[cnd];
        }
        else
        {
            table[pos] = 0;
            pos++;
        }
    }
    /*for(int i=0;i<strlen(word);i++)
        printf("%d ",table[i]);
    printf("\n");*/
}

int kmp_search(char *S,char *W,int *T)
{
    int i=0,m=0;
    //printf("Ls = %d, Lw = %d\n",strlen(S),strlen(W));
    while(m+i < strlen(S)-1)
    {
        if(W[i]==S[m+i])//Match
        {
            //printf("Matched(m=%d,i=%d)\n",m,i);
            if(i == strlen(W)-1)
            {
                //printf("Yes\n");
                return m;
            }

            else i++;
        }
        else
        {
            //printf("MisMatched(m=%d,i=%d)\n",m,i);
            if(T[i]>-1)
            {
                m = m+i-T[i];
                i = T[i];
            }
            else
            {
                i=0;
                m++;
            }
        }
    }
    return -1;
}

int main()
{
    scanf("%s",waste);
    //printf("Check: %s\n\n",waste);
    for(int i=0;i<strlen(waste);i++)
    {
        if(waste[i]>='a'&&waste[i]<='z')
        {
            waste[i]-=32;
        }
        if(waste[i]>='A'&&waste[i]<='Z')
        {
            first[c1]=waste[i];
            c1++;
        }
    }
    scanf("%s",waste);
    //printf("Check: %s\n\n",waste);
    for(int i=0;i<strlen(waste);i++)
    {
        if(waste[i]>='a'&&waste[i]<='z')
        {
            waste[i]-=32;
        }
        if(waste[i]>='A'&&waste[i]<='Z')
        {
            second[c2]=waste[i];
            c2++;
        }
    }
    scanf("%s",waste);
    //printf("Check: %s\n\n",waste);
    for(int i=0;i<strlen(waste);i++)
    {
        if(waste[i]>='a'&&waste[i]<='z')
        {
            waste[i]-=32;
        }
        if(waste[i]>='A'&&waste[i]<='Z')
        {
            third[c3]=waste[i];
            c3++;
        }
    }
    kmp_table(first,T1);
    kmp_table(second,T2);
    kmp_table(third,T3);
    //printf("First: %s\nSecond: %s\nThird: %s\n",first,second,third);
    //Judge
    int judge;
    scanf("%d",&judge);
    for(int i=1;i<=judge;i++)
    {
        scanf("%s",waste);
        //printf("Pre: %s\n",waste);
        int cnt=0;
        char assignment [666];
        for(int k=0;k<666;k++)
            assignment[k]='\0';
        for(int j=0;j<strlen(waste);j++)
        {
            if(waste[j]>='a'&&waste[j]<='z')
                waste[j]-=32;
            if(waste[j]>='A'&&waste[j]<='Z')
            {
                assignment[cnt]=waste[j];
                cnt++;
            }
        }
        //printf("Assignment%d: %s\n",i,assignment);
        if(cnt != c1+c2+c3)
        {
            printf("WA\n");
            continue;
        }
        assignment[cnt]='0';
        if(kmp_search(assignment,first,T1)==-1)
        {
            printf("WA\n");
            continue;
        }
        if(kmp_search(assignment,second,T2)==-1)
        {
            printf("WA\n");
            continue;
        }
        if(kmp_search(assignment,third,T3)==-1)
        {
            printf("WA\n");
            continue;
        }
        printf("ACC\n");
    }

    return 0;
}


#include<stdio.h>
#include<string.h>
char first[666],second[666],third[666],waste[666],checking[666];
int T1[666],T2[666],T3[666];
int c1=0,c2=0,c3=0;
//Table Building
void kmp_table (char *word,int *table)
{
    int l = strlen(word);
    int pos = 2;
    int cnd = 0;
    table[0]=-1;
    table[1]=0;
    while(pos<l)
    {
        if(word[pos-1] == word[cnd])
        {
            cnd++;
            table[pos]=cnd;
            pos++;
        }
        else if (cnd>0)
        {
            cnd = table[cnd];
        }
        else
        {
            table[pos] = 0;
            pos++;
        }
    }
    /*for(int i=0;i<strlen(word);i++)
        printf("%d ",table[i]);
    printf("\n");*/
}

int kmp_search(char *S,char *W,int *T)
{
    int i=0,m=0;
    //printf("Ls = %d, Lw = %d\n",strlen(S),strlen(W));
    while(m+i < strlen(S)-1)
    {
        if(W[i]==S[m+i])//Match
        {
            //printf("Matched(m=%d,i=%d)\n",m,i);
            if(i == strlen(W)-1)
            {
                //printf("Yes\n");
                return m;
            }

            else i++;
        }
        else
        {
            //printf("MisMatched(m=%d,i=%d)\n",m,i);
            if(T[i]>-1)
            {
                m = m+i-T[i];
                i = T[i];
            }
            else
            {
                i=0;
                m++;
            }
        }
    }
    return -1;
}

int main()
{
    scanf("%s",waste);
    //printf("Check: %s\n\n",waste);
    for(int i=0;i<strlen(waste);i++)
    {
        if(waste[i]>='a'&&waste[i]<='z')
        {
            waste[i]-=32;
        }
        if(waste[i]>='A'&&waste[i]<='Z')
        {
            first[c1]=waste[i];
            c1++;
        }
    }
    scanf("%s",waste);
    //printf("Check: %s\n\n",waste);
    for(int i=0;i<strlen(waste);i++)
    {
        if(waste[i]>='a'&&waste[i]<='z')
        {
            waste[i]-=32;
        }
        if(waste[i]>='A'&&waste[i]<='Z')
        {
            second[c2]=waste[i];
            c2++;
        }
    }
    scanf("%s",waste);
    //printf("Check: %s\n\n",waste);
    for(int i=0;i<strlen(waste);i++)
    {
        if(waste[i]>='a'&&waste[i]<='z')
        {
            waste[i]-=32;
        }
        if(waste[i]>='A'&&waste[i]<='Z')
        {
            third[c3]=waste[i];
            c3++;
        }
    }
    kmp_table(first,T1);
    kmp_table(second,T2);
    kmp_table(third,T3);
    //printf("First: %s\nSecond: %s\nThird: %s\n",first,second,third);
    //Judge
    int judge;
    scanf("%d",&judge);
    for(int i=1;i<=judge;i++)
    {
        scanf("%s",waste);
        //printf("Pre: %s\n",waste);
        int cnt=0;
        char assignment [666];
        for(int k=0;k<666;k++)
            assignment[k]='\0';
        for(int j=0;j<strlen(waste);j++)
        {
            if(waste[j]>='a'&&waste[j]<='z')
                waste[j]-=32;
            if(waste[j]>='A'&&waste[j]<='Z')
            {
                assignment[cnt]=waste[j];
                cnt++;
            }
        }
        //printf("Assignment%d: %s\n",i,assignment);
        if(cnt != c1+c2+c3)
        {
            printf("WA\n");
            continue;
        }
        assignment[cnt]='0';
        int r1=kmp_search(assignment,first,T1);
        if(r1==-1)
        {
            printf("WA\n");
            continue;
        }
        int r2=kmp_search(assignment,second,T2);
        if(r2==-1)
        {
            printf("WA\n");
            continue;
        }
        int r3=kmp_search(assignment,third,T3);
        if(r3==-1)
        {
            printf("WA\n");
            continue;
        }
        bool ok =false;
        if(r1==0)
        {
            if(r2==c1)
            {
                if(r3==c1+c2)   ok=true;
            }
            else if(r3==c1)
            {
                if(r2==c1+c3)   ok=true;
            }
        }
        else if (r2==0)
        {
            if(r1==c2)
            {
                if(r3==c1+c2) ok=true;
            }

            else if(r3==c2)
            {
                if(r1==c2+c3) ok=true;
            }
        }
        else if(r3==0)
        {
            if(r1==c3)//31
            {
                if(r2==c1+c3) ok=true;
            }
            else if(r2==c3)//32
            {
                if(r1==c2+c3) ok=true;
            }
        }
        if(ok)
            printf("ACC\n");
        else
        printf("WA\n");
    }

    return 0;
}


#include<string.h>
#include<string>
#include<stdio.h>
char waste[666];
char a[666],b[666],c[666];

void changestring(char *ori,char *dis)
{
    int cnt=0;
    for(int i=0;i<666;i++)
        dis[i]='\0';
    for(int i=0;i<strlen(ori);i++)
    {
        if(ori[i]>='a'&&ori[i]<='z')
            ori[i]-=32;
        if(ori[i]>='A'&&ori[i]<='Z')
            {dis[cnt]=ori[i];cnt++;}
    }
}

int main()
{
    scanf("%s",waste);
    changestring(waste,a);
    scanf("%s",waste);
    changestring(waste,b);
    scanf("%s",waste);
    changestring(waste,c);
    int q;
    scanf("%d",&q);
    for(int i=1;i<=q;i++)
    {
        char ass[666];
        scanf("%s",waste);
        changestring(waste,ass);
        char t1[666];
        strcpy(t1,a);
        strcat(t1,b);
        strcat(t1,c);
        char t2[666];
        strcpy(t2,a);
        strcat(t2,c);
        strcat(t2,b);
        char t3[666];
        strcpy(t3,b);
        strcat(t3,a);
        strcat(t3,c);
        char t4[666];
        strcpy(t4,b);
        strcat(t4,c);
        strcat(t4,a);
        char t5[666];
        strcpy(t5,c);
        strcat(t5,a);
        strcat(t5,b);
        char t6[666];
        strcpy(t6,c);
        strcat(t6,b);
        strcat(t6,a);
        //printf("%s****%s\n",ass,t6);
             if(strcmp(ass,t1)==0) printf("ACC\n");
        else if(strcmp(ass,t2)==0) printf("ACC\n");
        else if(strcmp(ass,t3)==0) printf("ACC\n");
        else if(strcmp(ass,t4)==0) printf("ACC\n");
        else if(strcmp(ass,t5)==0) printf("ACC\n");
        else if(strcmp(ass,t6)==0) printf("ACC\n");
        else printf("WA\n");
    }

}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>

using namespace std;

#define sz(v) (int)v.size()

string s(string str) {
	string res;
	for (int i = 0; i < sz(str); ++i) {
		if (str[i] == '_' || str[i] == ';' || str[i] == '-')
			continue;

		 res += str[i];
	}

	for(int i = 0 ; i < sz(res); i++){
		res[i] = tolower(res[i]);
	}

	return res;
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("in.txt", "rt", stdin);
	//freopen("out.txt", "wt", stdout);
#endif
	string _a, _b, _c;
	while (cin >> _a >> _b >> _c) {
		string abc[3];
		abc[0] = s(_a);
		abc[1] = s(_b);
		abc[2] = s(_c);

		set<string> abcPerm;

		do{
			string str;
			for (int i = 0; i < 3; ++i) {
				str += abc[i];
			}
			abcPerm.insert(str);
		}while (next_permutation(abc, abc + 3));

		int x;
		cin >> x;
		while(x--){
			string in;
			cin >> in;

			in = s(in);
			string res = (abcPerm.find(in) != abcPerm.end()) ? "ACC" : "WA";
			cout << res << endl;
		}
	}

	return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>

using namespace std;

#define sz(v) (int)v.size()

string s(string str) {
    string res;
    for (int i = 0; i < sz(str); ++i) {
        if (str[i] == '_' || str[i] == ';' || str[i] == '-')
            continue;

        res += str[i];
    }

    for (int i = 0; i < sz(res); i++) {
        res[i] = tolower(res[i]);
    }

    return res;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("in.txt", "rt", stdin);
    //freopen("out.txt", "wt", stdout);
#endif
    string _a, _b, _c;
    while (cin >> _a >> _b >> _c) {
        string abc[3];
        abc[0] = s(_a);
        abc[1] = s(_b);
        abc[2] = s(_c);

        set<string> abcPerm;

        for (int i = 0; i < 3; ++i) {
            for (int j = 0; j < 3; ++j) {
                if (j != i)
                    for (int k = 0; k < 3; ++k) {
                        if (k != j) {
                            string str = abc[i] + abc[j] + abc[k];
                            abcPerm.insert(str);
                        }
                    }
            }
        }

//      do {
//          string str;
//          for (int i = 0; i < 3; ++i) {
//              str += abc[i];
//          }
//          cout << str << endl;
//          abcPerm.insert(str);
//      } while (next_permutation(abc, abc + 3));

        int x;
        cin >> x;
        while (x--) {
            string in;
            cin >> in;

            in = s(in);
//          cout << in << endl;
            string res = (abcPerm.find(in) != abcPerm.end()) ? "ACC" : "WA";
            cout << res << endl;
        }
    }

    return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>

using namespace std;

#define sz(v) (int)v.size()

string s(string str) {
    string res;
    for (int i = 0; i < sz(str); ++i) {
        if (str[i] == '_' || str[i] == ';' || str[i] == '-')
            continue;

        res += str[i];
    }

    for (int i = 0; i < sz(res); i++) {
        res[i] = tolower(res[i]);
    }

    return res;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("in.txt", "rt", stdin);
    //freopen("out.txt", "wt", stdout);
#endif
    string _a, _b, _c;
    while (cin >> _a >> _b >> _c) {
        string abc[3];
        abc[0] = s(_a);
        abc[1] = s(_b);
        abc[2] = s(_c);

        set<string> abcPerm;

        sort(abc,abc+3);
        do {
            string str;
            for (int i = 0; i < 3; ++i) {
                str += abc[i];
            }
            abcPerm.insert(str);
        } while (next_permutation(abc, abc + 3));

        int x;
        cin >> x;
        while (x--) {
            string in;
            cin >> in;

            in = s(in);
            string res = (abcPerm.find(in) != abcPerm.end()) ? "ACC" : "WA";
            cout << res << endl;
        }
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long num;

string fix(char s[]){
    char ss[105];
    string st;
    int j = 0;
    for(int k = 0; k < strlen(s); k++)
        if(isalpha(s[k]))
            ss[j++] = tolower(s[k]);
        ss[j] = '\0';
        st = ss;
        return st;
}

int main(){
    vector<string> vs, gab;
    char s[105], ss[105];
    string st;
    int n;

    for(int i = 0; i < 3; i++){
        scanf(" %s", s);
        st = fix(s);
        vs.push_back(st);
    }

    sort(vs.begin(), vs.begin()+3);

    do{
        st.clear();
        for(int i = 0; i < vs.size(); i++)
            st += vs[i];
        gab.push_back(st);
    }while(next_permutation(vs.begin(), vs.begin()+3));

    scanf("%d", &n);
    for(int i = 0; i < n; i++){
        scanf(" %s", s);
        st = fix(s);
        if(find(gab.begin(), gab.end(), st) != gab.end())
            puts("ACC");
        else puts("WA");
    }
}


#include <bits/stdc++.h>
using namespace std;
typedef long long num;

string fix(char s[]){
    char ss[105];
    string st;
    int j = 0;
    for(int k = 0; k < strlen(s); k++)
        if(isalpha(s[k]))
            ss[j++] = tolower(s[k]);
        ss[j] = '\0';
        st = ss;
        return st;
}

int main(){
    vector<string> vs, gab;
    char s[800], ss[800];
    string st;
    int n;

    for(int i = 0; i < 3; i++){
        scanf(" %s", s);
        st = fix(s);
        vs.push_back(st);
    }

    sort(vs.begin(), vs.begin()+3);

    do{
        st.clear();
        for(int i = 0; i < vs.size(); i++)
            st += vs[i];
        gab.push_back(st);
    }while(next_permutation(vs.begin(), vs.begin()+3));

    scanf("%d", &n);
    for(int i = 0; i < n; i++){
        scanf(" %s", s);
        st = fix(s);
        if(find(gab.begin(), gab.end(), st) != gab.end())
            puts("ACC");
        else puts("WA");
    }
}


#include <bits/stdc++.h>
using namespace std;
typedef long long num;

string fix(char s[]){
    char ss[800];
    string st;
    int j = 0;
    for(int k = 0; k < strlen(s); k++)
        if(isalpha(s[k]))
            ss[j++] = tolower(s[k]);
        ss[j] = '\0';
        st = ss;
        return st;
}

int main(){
    vector<string> vs, gab;
    char s[800], ss[800];
    string st;
    int n;

    for(int i = 0; i < 3; i++){
        scanf(" %s", s);
        st = fix(s);
        vs.push_back(st);
    }

    sort(vs.begin(), vs.begin()+3);

    do{
        st.clear();
        for(int i = 0; i < vs.size(); i++)
            st += vs[i];
        gab.push_back(st);
    }while(next_permutation(vs.begin(), vs.begin()+3));

    scanf("%d", &n);
    for(int i = 0; i < n; i++){
        scanf(" %s", s);
        st = fix(s);
        if(find(gab.begin(), gab.end(), st) != gab.end())
            puts("ACC");
        else puts("WA");
    }
}


//
//  main.cpp
//
//  Created by Prateek Sachdev
//  Copyright (c) 2013 Prateek Sachdev. All rights reserved.
//
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <iterator>
#include <utility>

using namespace std;

typedef vector<int > vd;
typedef vector<long long int > vl;

#define sd(n) scanf("%d",&n)
#define sc(n) scanf("%c",&n)
#define sf(n) scanf("%f",&n)
#define ss(n) scanf("%s",n)
#define pd(n) printf("%d\n",n)
#define pb push_back

#define LL long long

#define ALL(c) c.begin(), c.end()
#define UB(s, e, x) upper_bound(s, e, x)
#define LB(s, e, x) lower_bound(s, e, x)

#define REV(s, e) reverse(s, e);
#define SZ(c) c.size()
#define SET(p) memset(p, -1, sizeof(p))
#define CLR(p) memset(p, 0, sizeof(p))
#define MEM(p, v) memset(p, v, sizeof(p))

#define SIEVE(a) ({int b=ceil(sqrt(a));vd d(a,0);vd e;int f=2;e.pb(2);e.pb(3);for(int x=1;x<b+1;x++){for(int y=1;y<b+1;y++){int n=(4*x*x)+(y*y);if(n<=a&&(n%12==1||n%12==5)){d[n]^=1;}n=(3*x*x)+(y*y);if(n<=a&&n%12==7){d[n]^=1;}n=(3*x*x)-(y*y);if(x>y&&n<=a&&n%12==11){d[n]^=1;}}}for(int r=5;r<b+1;r++){if(d[r]){for(int i=r*r;i<a;i+=(r*r)){d[i]=0;}}}for(int c=5;c<a;c++){if(d[c]){e.pb(c);}}e;})
template<class T> inline vector<pair<T,int> > FACTORISE(T n){vector<pair<T,int> >R;for (T i=2;n>1;){if (n%i==0){int C=0;for (;n%i==0;C++,n/=i);R.push_back(make_pair(i,C));}i++;if (i>n/i) i=n;}if (n>1) R.push_back(make_pair(n,1));return R;}
template<class T> inline T TOTIENT(T n) {vector<pair<T,int> > R=FACTORISE(n);T r=n;for (int i=0;i<R.size();i++)r=r/R[i].first*(R[i].first-1);return r;}

// vd v=SIEVE(2100);
// int n=TOTIENT(num);
struct state
{
	int row, col, val;
	state(int _r, int _c, int _v) :
		row(_r), col(_c), val(_v) {}
	bool operator < (const state &s) const {
		return val>s.val;
	}
};
string filter(string a)
{
	string s="";
	transform(a.begin(), a.end(), a.begin(), ::tolower);
	for(int i=0;i<a.length();i++)
	{
		if(a[i]!=';' && a[i]!='-' && a[i]!='_')
			s+=a[i];
	}
	return s;
}
int main()
{

	string s1,s2,s3;
	cin >> s1>>s2>>s3;
	s1=filter(s1);
	s2=filter(s2);
	s3=filter(s3);
	int len1=s1.length();
	int len2=s2.length();
	int len3=s3.length();
	int n;
	sd(n);
	string test;
	std::size_t found;
	int flag1,flag2,flag3;
	for(int i=0;i<n;i++)
	{
		cin >> test;
		flag1=flag2=flag3=0;
		test=filter(test);

		if(test.length()==len1+len2+len3)
		{
			found = test.find(s1);
			if(found!=string::npos)
				flag1=1;
			found = test.find(s2);
			if(found!=string::npos)
				flag2=1;
			found = test.find(s3);
			if(found!=string::npos)
				flag3=1;
			if(flag1&&flag2&&flag3)
				printf("ACC\n");
			else
				printf("WA\n");

		}
		else
			printf("WA\n");
	}
	return 0;
}


//
//  main.cpp
//
//  Created by Prateek Sachdev
//  Copyright (c) 2013 Prateek Sachdev. All rights reserved.
//
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <iterator>
#include <utility>

using namespace std;

typedef vector<int > vd;
typedef vector<long long int > vl;

#define sd(n) scanf("%d",&n)
#define sc(n) scanf("%c",&n)
#define sf(n) scanf("%f",&n)
#define ss(n) scanf("%s",n)
#define pd(n) printf("%d\n",n)
#define pb push_back

#define LL long long

#define ALL(c) c.begin(), c.end()
#define UB(s, e, x) upper_bound(s, e, x)
#define LB(s, e, x) lower_bound(s, e, x)

#define REV(s, e) reverse(s, e);
#define SZ(c) c.size()
#define SET(p) memset(p, -1, sizeof(p))
#define CLR(p) memset(p, 0, sizeof(p))
#define MEM(p, v) memset(p, v, sizeof(p))

#define SIEVE(a) ({int b=ceil(sqrt(a));vd d(a,0);vd e;int f=2;e.pb(2);e.pb(3);for(int x=1;x<b+1;x++){for(int y=1;y<b+1;y++){int n=(4*x*x)+(y*y);if(n<=a&&(n%12==1||n%12==5)){d[n]^=1;}n=(3*x*x)+(y*y);if(n<=a&&n%12==7){d[n]^=1;}n=(3*x*x)-(y*y);if(x>y&&n<=a&&n%12==11){d[n]^=1;}}}for(int r=5;r<b+1;r++){if(d[r]){for(int i=r*r;i<a;i+=(r*r)){d[i]=0;}}}for(int c=5;c<a;c++){if(d[c]){e.pb(c);}}e;})
template<class T> inline vector<pair<T,int> > FACTORISE(T n){vector<pair<T,int> >R;for (T i=2;n>1;){if (n%i==0){int C=0;for (;n%i==0;C++,n/=i);R.push_back(make_pair(i,C));}i++;if (i>n/i) i=n;}if (n>1) R.push_back(make_pair(n,1));return R;}
template<class T> inline T TOTIENT(T n) {vector<pair<T,int> > R=FACTORISE(n);T r=n;for (int i=0;i<R.size();i++)r=r/R[i].first*(R[i].first-1);return r;}

// vd v=SIEVE(2100);
// int n=TOTIENT(num);
struct state
{
	int row, col, val;
	state(int _r, int _c, int _v) :
	row(_r), col(_c), val(_v) {}
	bool operator < (const state &s) const {
		return val>s.val;
	}
};
string filter(string a)
{
	string s="";
	transform(a.begin(), a.end(), a.begin(), ::tolower);
	for(int i=0;i<a.length();i++)
	{
		if(a[i]!=';' && a[i]!='-' && a[i]!='_')
		s+=a[i];
	}
	return s;
}
int main()
{

	string s1,s2,s3;
	cin >> s1>>s2>>s3;
	string ss[3];
	s1=filter(s1);
	s2=filter(s2);
	s3=filter(s3);
	ss[0]=s1;
	ss[1]=s2;
	ss[2]=s3;
	int len1=s1.length();
	int len2=s2.length();
	int len3=s3.length();
	int n;
	sd(n);
	string test;
	std::size_t found;
	int flag1,flag2,flag3;
	string tempstr="";
	for(int i=0;i<n;i++)
	{
		cin >> test;
		flag1=0;
		tempstr="";
		test=filter(test);
		for(int i=0;i<3;i++)
		{
			if(!flag1){
				for(int j=0;j<3;j++)
				{
					if(!flag1)
					{
						for(int k=0;k<3;k++)
						{
							tempstr="";
							if(j!=i && j!=k && k!=i)
								tempstr+=ss[i]+ss[j]+ss[k];
							if(tempstr==test)
							{
								printf("ACC\n");
								flag1=1;
								break;
							}
						}
					}

				}
			}
		}

		if(!flag1)
			printf("WA\n");
	}
	return 0;
}


//
//  main.cpp
//
//  Created by Prateek Sachdev
//  Copyright (c) 2013 Prateek Sachdev. All rights reserved.
//
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <iterator>
#include <utility>

using namespace std;

typedef vector<int > vd;
typedef vector<long long int > vl;

#define sd(n) scanf("%d",&n)
#define sc(n) scanf("%c",&n)
#define sf(n) scanf("%f",&n)
#define ss(n) scanf("%s",n)
#define pd(n) printf("%d\n",n)
#define pb push_back

#define LL long long

#define ALL(c) c.begin(), c.end()
#define UB(s, e, x) upper_bound(s, e, x)
#define LB(s, e, x) lower_bound(s, e, x)

#define REV(s, e) reverse(s, e);
#define SZ(c) c.size()
#define SET(p) memset(p, -1, sizeof(p))
#define CLR(p) memset(p, 0, sizeof(p))
#define MEM(p, v) memset(p, v, sizeof(p))

#define SIEVE(a) ({int b=ceil(sqrt(a));vd d(a,0);vd e;int f=2;e.pb(2);e.pb(3);for(int x=1;x<b+1;x++){for(int y=1;y<b+1;y++){int n=(4*x*x)+(y*y);if(n<=a&&(n%12==1||n%12==5)){d[n]^=1;}n=(3*x*x)+(y*y);if(n<=a&&n%12==7){d[n]^=1;}n=(3*x*x)-(y*y);if(x>y&&n<=a&&n%12==11){d[n]^=1;}}}for(int r=5;r<b+1;r++){if(d[r]){for(int i=r*r;i<a;i+=(r*r)){d[i]=0;}}}for(int c=5;c<a;c++){if(d[c]){e.pb(c);}}e;})
template<class T> inline vector<pair<T,int> > FACTORISE(T n){vector<pair<T,int> >R;for (T i=2;n>1;){if (n%i==0){int C=0;for (;n%i==0;C++,n/=i);R.push_back(make_pair(i,C));}i++;if (i>n/i) i=n;}if (n>1) R.push_back(make_pair(n,1));return R;}
template<class T> inline T TOTIENT(T n) {vector<pair<T,int> > R=FACTORISE(n);T r=n;for (int i=0;i<R.size();i++)r=r/R[i].first*(R[i].first-1);return r;}

// vd v=SIEVE(2100);
// int n=TOTIENT(num);
struct state
{
	int row, col, val;
	state(int _r, int _c, int _v) :
	row(_r), col(_c), val(_v) {}
	bool operator < (const state &s) const {
		return val>s.val;
	}
};
string filter(string a)
{
	string s="";
	transform(a.begin(), a.end(), a.begin(), ::tolower);
	for(int i=0;i<a.length();i++)
	{
		if(a[i]!=';' && a[i]!='-' && a[i]!='_')
		s+=a[i];
	}
	return s;
}
int main()
{

	string s1,s2,s3;
	cin >>s1>>s2>>s3;
	string x,y,z;
	string ss[3];
	x=s1=filter(s1);
	y=s2=filter(s2);
	z=s3=filter(s3);

	int len1=s1.length();
	int len2=s2.length();
	int len3=s3.length();
	int n;
	sd(n);
	string test;
	std::size_t found;
	int flag1,flag2,flag3;
	string tempstr="";
	for(int i=0;i<n;i++)
	{
		cin >> test;
		flag1=0;
		tempstr="";
		test=filter(test);
		if(test==x+y+z || test==x+z+y || test==y+x+z || test==y+z+x || test==z+y+x || test==z+x+y) cout<<"ACC"<<endl;

		else
			printf("WA\n");
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
	string str[3],ss[6];
	int student;
	string stud[1001];
	for (int i=0;i<3;i++)
	{
		cin>>str[i];
		for (int j=0;str[i][j];j++)
		{
			if (str[i][j]=='-'||str[i][j]=='_'||str[i][j]==';')
			{
				str[i].erase(j,1);
				j--;
				continue;
			}
			str[i][j]=tolower(str[i][j]);
		}
	}
	ss[0]=str[0]+str[1]+str[2];
	ss[1]=str[0]+str[2]+str[1];
	ss[2]=str[1]+str[0]+str[2];
	ss[3]=str[1]+str[2]+str[0];
	ss[4]=str[2]+str[0]+str[1];
	ss[5]=str[2]+str[1]+str[0];
	cin>>student;
	for (int I=0;I<student;I++)
	{
		cin>>stud[I];
		for (int j=0;stud[I][j];j++)
		{
			if (stud[I][j]=='-'||stud[I][j]=='_'||stud[I][j]==';')
			{
				stud[I].erase(j,1);
				j--;
			}
			else
				stud[I][j]=tolower(stud[I][j]);
		}
		int j;
		for (j=0;j<6;j++)
		{
			if (stud[I]==ss[j])
			{
				cout<<"ACC"<<endl;
				break;
			}
		}
		if (j==6)
			cout<<"WA"<<endl;
	}
	end:
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

stringstream ss;

void filter(string s)
{
	for(int i=0;i<s.length();i++)
	{
		if(s[i]!='-'&&s[i]!='_'&&s[i]!=';')
		{
			ss<<char(tolower(s[i]));
		}
	}
	ss<<'\n';
}

int main()
{
	string s,input[3],all[6];
	int stud;
	for(int i=0;i<3;i++)
	{
		cin>>s;
		filter(s);
	}
	cin>>stud;
	ss<<stud<<"\n";
	while(stud--)
	{
		cin>>s;
		filter(s);
	}

	ss>>input[0]>>input[1]>>input[2];

	sort(input,input+3);
	int cnt=0;
	do
	{
		all[cnt++]=input[0]+input[1]+input[2];
	}
	while(next_permutation(input,input+3));

	ss>>stud;
	while(stud--)
	{
		ss>>s;
		for(int i=0;i<6;i++)
		{
			if(s==all[i])
			{
				cout<<"ACC\n";
				goto end;
			}
		}
		cout<<"WA\n";
		end:;
	}

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    string str[3],ss[6];
    int student;
    string stud[1001];
    for (int i=0;i<3;i++)
    {
        cin>>str[i];
        for (int j=0;str[i][j];j++)
        {
            if (str[i][j]=='-'||str[i][j]=='_'||str[i][j]==';')
            {
                str[i].erase(j,1);
                j--;
                continue;
            }
            str[i][j]=tolower(str[i][j]);
        }
    }
    ss[0]=str[0]+str[1]+str[2];
    ss[1]=str[0]+str[2]+str[1];
    ss[2]=str[1]+str[0]+str[2];
    ss[3]=str[1]+str[2]+str[0];
    ss[4]=str[2]+str[0]+str[1];
    ss[5]=str[2]+str[1]+str[0];
    cin>>student;
    for (int I=0;I<student;I++)
    {
        cin>>stud[I];
        for (int j=0;stud[I][j];j++)
        {
            if (stud[I][j]=='-'||stud[I][j]=='_'||stud[I][j]==';')
            {
                stud[I].erase(j,1);
                j--;
            }
            else
                stud[I][j]=tolower(stud[I][j]);
        }
        int j;
        for (j=0;j<6;j++)
        {
            if (stud[I]==ss[j])
            {
                cout<<"AAC"<<endl;
                break;
            }
        }
        if (j==6)
            cout<<"WA"<<endl;
    }
    end:
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

string filter(string s)
{
	string st="";
	for(int i=0;i<s.length();i++)
	{
		if(s[i]!='-'&&s[i]!='_'&&s[i]!=';')
		{
			st+=char(tolower(s[i]));
		}
	}
	return st;
}

int main()
{
	string s,input[3],all[6];
	int stud;
	for(int i=0;i<3;i++)
	{
		cin>>s;
		input[i]=filter(s);
	}
	sort(input,input+3);
	int cnt=0;
	do
	{
		all[cnt++]=input[0]+input[1]+input[2];
	}
	while(next_permutation(input,input+3));
	cin>>stud;
	while(stud--)
	{
		cin>>s;
		s=filter(s);
		for(int i=0;i<6;i++)
		{
			if(s==all[i])
			{
				cout<<"ACC\n";
				goto end;
			}
		}
		cout<<"WA\n";
		end:;
	}

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    string str[3];
    int student;
    string stud[1001];
    int len,len2=0;
    for (int i=0;i<3;i++)
    {
        cin>>str[i];
        for (int j=0;str[i][j];j++)
        {
            if (str[i][j]=='-'||str[i][j]=='_'||str[i][j]==';')
            {
                str[i].erase(j,1);
                j--;
                continue;
            }
            str[i][j]=tolower(str[i][j]);
        }
    }
     len=str[0].length() + str[1].length() + str[2].length();
    cin>>student;
    for (int I=0;I<student;I++)
    {
        cin>>stud[I];
        for (int j=0;stud[I][j];j++)
        {
            if (stud[I][j]=='-'||stud[I][j]=='_'||stud[I][j]==';')
            {
                stud[I].erase(j,1);
                j--;
            }
            else
                stud[I][j]=tolower(stud[I][j]);
            len2=stud[I].length();
        }
        if (stud[I].find(str[0])!=-1 && stud[I].find(str[1])!=-1 && stud[I].find(str[2])!=-1 && len==len2)
            cout << "ACC"<<endl;
        else
            cout<<"WA"<<endl;
    }
    end:
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

stringstream ss;

void filter(string s)
{
	for(int i=0;i<s.length();i++)
	{
		if(s[i]!='-'&&s[i]!='_'&&s[i]!=';')
		{
			ss<<tolower(s[i]);
		}
	}
	ss<<'\n';
}

int main()
{
	string s,input[3],all[6];
	int stud;
	for(int i=0;i<3;i++)
	{
		cin>>s;
		filter(s);
	}
	cin>>stud;
	ss<<stud<<"\n";
	while(stud--)
	{
		cin>>s;
		filter(s);
	}

	ss>>input[0]>>input[1]>>input[2];

	sort(input,input+3);
	int cnt=0;
	do
	{
		all[cnt++]=input[0]+input[1]+input[2];
	}
	while(next_permutation(input,input+3));

	ss>>stud;
	while(stud--)
	{
		ss>>s;
		for(int i=0;i<6;i++)
		{
			if(s==all[i])
			{
				cout<<"ACC\n";
				goto end;
			}
		}
		cout<<"WA\n";
		end:;
	}

    return 0;
}


#include<iostream>
#include<string>
using namespace std;

string pp(string s)
{
	string t;
	for (short i = 0;i < s.size();i++)
	{
		if ((s[i] >= 'a'&&s[i] <= 'z')||(s[i] >= 'A'&&s[i] <= 'Z'))
			t += s[i];
	}
	for (short i = 0;i < t.size();i++)
	{
		t[i] = tolower(t[i]);
	}

	return t;
}
int main()
{
	string s[1000],s1,s2,s3;
	short n;
	cin >> s1 >> s2 >> s3 >> n;
	for (short i = 0;i < n;i++)
	{
		cin >> s[i];
		s[i] = pp(s[i]);
	}
	s1 = pp(s1);
	s2 = pp(s2);
	s3 = pp(s3);
	for (short i = 0;i < n;i++)
		if (s[i] == s1 + s2 + s3 || s[i] == s1 + s3 + s2 || s[i] == s3 + s2 + s1 || s[i] == s3 + s1 + s2 || s[i] == s2 + s1 + s3 || s[i] == s2 + s3 + s1)
			cout << "ACC"<<endl;
		else
			cout << "WA"<<endl;
	return 0;
}


#include<iostream>
#include<string>
using namespace std;

string pp(string s)
{
	string t;
	for (short i = 0;i < s.size();i++)
	{
		s[i] = tolower(s[i]);
		if (s[i] >= 'a'&&s[i] <= 'z')
			t += s[i];
	}
	return t;
}
int main()
{
	string s[1000],s1,s2,s3;
	short n;
	cin >> s1 >> s2 >> s3 >> n;
	for (short i = 0;i < n;i++)
	{
		cin >> s[i];
		s[i] = pp(s[i]);
	}
	s1 = pp(s1);
	s2 = pp(s2);
	s3 = pp(s3);
	for (short i = 0;i < n;i++)
		if (s[i] == s1 + s2 + s3 || s[i] == s1 + s3 + s2 || s[i] == s3 + s2 + s1 || s[i] == s3 + s1 + s2 || s[i] == s2 + s1 + s3 || s[i] == s2 + s3 + s1)
			cout << "ACC"<<endl;
		else
			cout << "WA"<<endl;
	return 0;
}


#include<iostream>
#include<string>
using namespace std;

string pp(string s)
{
	string t;
	for (short i = s.size() - 1;i >= 0;i--)
	{
		s[i] = tolower(s[i]);
		if (s[i] > 'a'&&s[i] <= 'z')
			t += s[i];
	}
	return t;
}
int main()
{
	string s[1000],s1,s2,s3;
	short n;
	cin >> s1 >> s2 >> s3 >> n;
	for (short i = 0;i < n;i++)
	{
		cin >> s[i];
		s[i] = pp(s[i]);
	}
	s1 = pp(s1);
	s2 = pp(s2);
	s3 = pp(s3);
	for (short i = 0;i < n;i++)
		if (s[i] == s1 + s2 + s3 || s[i] == s1 + s3 + s2 || s[i] == s3 + s2 + s1 || s[i] == s3 + s1 + s2 || s[i] == s2 + s1 + s3 || s[i] == s2 + s3 + s1)
			cout << "ACC"<<endl;
		else
			cout << "WA"<<endl;
	return 0;
}


#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#include <cctype>
#include <ios>
#include <iomanip>
#include <fstream>
using namespace std;

int main()
{

 char words[3][101];
 int test,lsum=0;
 int esum =0;
 string s;
 string ex(700,' ');
 int k,j,i;
 vector<string> v;
 getline(cin,s);
 v.push_back(s);
 getline(cin,s);
 v.push_back(s);
 getline(cin,s);
 v.push_back(s);
 getline(cin,s);
 test = atoi(s.c_str());
 for(i= 0; i<3;i++)
 { k =0;
   for(int j =0;j<v[i].length();j++)
    {
       if(isalpha(v[i][j]))
        {  words[i][k] = tolower(v[i][j]);k++;}
    }
    words[i][k] = '\0';
    lsum +=k;
 }

 while(test--)
 {
    getline(cin,s);
    k = s.length();

    j =0;
    esum = 0;
    for(i =0 ;i < k ; i++)
    {
       if(isalpha(s[i]))
       { ex[j] = tolower(s[i]);j++;}

    }
   ex[j] = '\0';
   esum = j;
  // cout<<ex<<endl;
   const char *p = (const char*)(&words[0]);
   const char *q = (const char*)(&words[1]);
   const char *r = (const char*)(&words[2]);
   i = ex.find(p);

   j = ex.find(q);

   k = ex.find(r);

   int il = strlen(words[0]);
   int jl = strlen(words[1]);
   int kl = strlen(words[2]);

  // printf("%s\n",p);
  // printf("%s\n",q);
  // printf("%s\n",r);
   if(il >= jl)
   {
     char *pij = (char*)strstr(p,q);
     if(pij != NULL)
     { //cout<<"pij"<<endl;
       j = ex.rfind(q);
     }
   }
    if(jl >= il)
   { //cout<<"jl>il";
     char *pji = (char*)strstr(q,p);
    if(pji != NULL)
     { //cout<<"pji"<<endl;
       i = ex.rfind(p);
     }
   }
    if(il >= kl)
   {
      char *pik = (char*)strstr(p,r);
      if(pik != NULL)
     {// cout<<"pik"<<endl;
       k = ex.rfind(r);
     }
   }
   if(kl >= il)
  { //cout<<"pki";
   char *pki = (char*)strstr(r,p);
   if(pki != NULL)
     {// cout<<"pki";
       i = ex.rfind(p);
      cout<<i<<endl;
     }
  }
   if(jl >= kl)
  {  //cout<<"jl>kl";
     char *pjk = (char*)strstr(q,r);
     if(pjk != NULL)
     {
       k = ex.rfind(r);
     }
  }
   if(kl >= jl)
  {
   char *pkj = (char*)strstr(r,q);
   if(pkj != NULL)
     {
       j = ex.rfind(q);
     }
  }
  //i = ex.find(p);
   int ipos = i + strlen(words[0]) -1;
   //j = ex.find(q);
   int jpos = j + strlen(words[1]) -1;
  // k = ex.find(r);
   int kpos = k + strlen(words[2]) -1;
  bool flag = (ipos != j && jpos != i && kpos != i && kpos != j && ipos != k && jpos != k && i != j && i != k && j != k);
  // cout<<i<<j<<k<<ipos<<jpos<<kpos<<endl;
   if( (lsum == esum) && flag && (i >= 0 && i < ex.length()) && (j >= 0 && j < ex.length()) && (k >= 0 && k < ex.length()))
   { cout<<"ACC"<<endl;}
   else
   { cout<<"WA"<<endl;}
  i=j=k=0;
 }

return 0;

}


#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#include <cctype>
#include <ios>
#include <iomanip>
#include <fstream>
using namespace std;

int main()
{

 char words[3][101];
 int test,lsum=0;
 int esum =0;
 string s;
 string ex(700,' ');
 int k,j,i;
 vector<string> v;
 getline(cin,s);
 v.push_back(s);
 getline(cin,s);
 v.push_back(s);
 getline(cin,s);
 v.push_back(s);
 getline(cin,s);
 test = atoi(s.c_str());
 for(i= 0; i<3;i++)
 { k =0;
   for(int j =0;j<v[i].length();j++)
    {
       if(isalpha(v[i][j]))
        {  words[i][k] = tolower(v[i][j]);k++;}
    }
    words[i][k] = '\0';
    lsum +=k;
 }

 while(test--)
 {
    getline(cin,s);
    k = s.length();

    j =0;
    esum = 0;
    for(i =0 ;i < k ; i++)
    {
       if(isalpha(s[i]))
       { ex[j] = tolower(s[i]);j++;}

    }
   ex[j] = '\0';
   esum = j;
   i = ex.find((const char*)(&words[0]));
   j = ex.find((const char*)(&words[1]));
   k = ex.find((const char*)(&words[2]));

   if( (lsum == esum) && (i >= 0 && i < ex.length()) && (j >= 0 && j < ex.length()) && (k >= 0 && k < ex.length()))
   { cout<<"ACC"<<endl;}
   else
   { cout<<"WA"<<endl;}
  i=j=k=0;
 }

return 0;

}


#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#include <cctype>
#include <ios>
#include <iomanip>
#include <fstream>
using namespace std;

int main()
{

 char words[3][200];
 int test,lsum=0;
 int esum =0;
 string s;
 string ex(1000,' ');
 int k,j,i;
 vector<string> v;
 getline(cin,s);
 v.push_back(s);
 getline(cin,s);
 v.push_back(s);
 getline(cin,s);
 v.push_back(s);
 getline(cin,s);
 test = atoi(s.c_str());
 for(i= 0; i<3;i++)
 { k =0;
   for(int j =0;j<v[i].length();j++)
    {
       if(isalpha(v[i][j]))
        {  words[i][k] = tolower(v[i][j]);k++;}
    }
    words[i][k] = '\0';
    lsum +=k;
 }

 while(test--)
 {
    getline(cin,s);
    k = s.length();

    j =0;
    esum = 0;
    for(i =0 ;i < k ; i++)
    {
       if(isalpha(s[i]))
       { ex[j] = tolower(s[i]);j++;}

    }
   ex[j] = '\0';
   esum = j;

   const char *p = (const char*)(&words[0]);
   const char *q = (const char*)(&words[1]);
   const char *r = (const char*)(&words[2]);
   i = ex.find(p);

   j = ex.find(q);

   k = ex.find(r);

   int il = strlen(words[0]);
   int jl = strlen(words[1]);
   int kl = strlen(words[2]);

   if(il >= jl)
   {
     char *pij = (char*)strstr(p,q);
     if(pij != NULL)
     { //cout<<"pij"<<endl;
       j = ex.rfind(q);
     }
   }
    if(jl >= il)
   { //cout<<"jl>il";
     char *pji = (char*)strstr(q,p);
    if(pji != NULL)
     {// cout<<"pji"<<endl;
       i = ex.rfind(p);
     }
   }
    if(il >= kl)
   {
      char *pik = (char*)strstr(p,r);
      if(pik != NULL)
     { //cout<<"pik"<<endl;
       k = ex.rfind(r);
     }
   }
   if(kl >= il)
  {// cout<<"pki";
   char *pki = (char*)strstr(r,p);
   if(pki != NULL)
     {// cout<<"pki";
       i = ex.rfind(p);

     }
  }
   if(jl >= kl)
  { // cout<<"jl>kl";
     char *pjk = (char*)strstr(q,r);
     if(pjk != NULL)
     {
       k = ex.rfind(r);
     }
  }
   if(kl >= jl)
  {
   char *pkj = (char*)strstr(r,q);
   if(pkj != NULL)
     {
       j = ex.rfind(q);
     }
  }
  //i = ex.find(p);
   int ipos = i + strlen(words[0]) -1;
   //j = ex.find(q);
   int jpos = j + strlen(words[1]) -1;
  // k = ex.find(r);
   int kpos = k + strlen(words[2]) -1;
  bool flag = (ipos != j && jpos != i && kpos != i && kpos != j && ipos != k && jpos != k && i != j && i != k && j != k);

   if( (lsum == esum) && flag && (i >= 0 && i < ex.length()) && (j >= 0 && j < ex.length()) && (k >= 0 && k < ex.length()))
   { cout<<"ACC"<<endl;}
   else
   { cout<<"WA"<<endl;}
  i=j=k=0;
 }

return 0;

}


#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#include <cctype>
#include <ios>
#include <iomanip>
#include <fstream>
using namespace std;

int main()
{
  int jk,kh;
 string pri;
 char words[3][200];
 int test,lsum=0;
 int esum =0;
 string s;
 string ex(1000,' ');
 int k,j,i;
 vector<string> v;
 getline(cin,s);
 v.push_back(s);
 getline(cin,s);
 v.push_back(s);
 getline(cin,s);
 v.push_back(s);
 getline(cin,s);
 test = atoi(s.c_str());
 for(i= 0; i<3;i++)
 { k =0;
   for(int j =0;j<v[i].length();j++)
    {
       if(isalpha(v[i][j]))
        {  words[i][k] = tolower(v[i][j]);k++;}
    }
    words[i][k] = '\0';
    lsum +=k;
 }

 while(test--)
 {
    getline(cin,s);
    k = s.length();

    j =0;
    esum = 0;
    for(i =0 ;i < k ; i++)
    {
       if(isalpha(s[i]))
       { ex[j] = tolower(s[i]);j++;}

    }
   ex[j] = '\0';
   esum = j;
  // cout<<ex<<endl;
   const char *p = (const char*)(&words[0]);
   const char *q = (const char*)(&words[1]);
   const char *r = (const char*)(&words[2]);
   i = ex.find(p);

   j = ex.find(q);

   k = ex.find(r);

   int il = strlen(words[0]);
   int jl = strlen(words[1]);
   int kl = strlen(words[2]);

  // printf("%s\n",p);
  // printf("%s\n",q);
  // printf("%s\n",r);
   if(il >= jl)
   {
     char *pij = (char*)strstr(p,q);
     if(pij != NULL)
     { //cout<<"pij"<<endl;
       j = ex.rfind(q);
     }
   }
    if(jl >= il)
   { //cout<<"jl>il";
     char *pji = (char*)strstr(q,p);
    if(pji != NULL)
     { //cout<<"pji"<<endl;
       i = ex.rfind(p);
     }
   }
    if(il >= kl)
   {
      char *pik = (char*)strstr(p,r);
      if(pik != NULL)
     {// cout<<"pik"<<endl;
       k = ex.rfind(r);
     }
   }
   if(kl >= il)
  { //cout<<"pki";
   char *pki = (char*)strstr(r,p);
   if(pki != NULL)
     {// cout<<"pki";
       i = ex.rfind(p);
      cout<<i<<endl;
     }
  }
   if(jl >= kl)
  {  //cout<<"jl>kl";
     char *pjk = (char*)strstr(q,r);
     if(pjk != NULL)
     {
       k = ex.rfind(r);
     }
  }
   if(kl >= jl)
  {
   char *pkj = (char*)strstr(r,q);
   if(pkj != NULL)
     {
       j = ex.rfind(q);
     }
  }
  //i = ex.find(p);
   int ipos = i + strlen(words[0]) -1;
   //j = ex.find(q);
   int jpos = j + strlen(words[1]) -1;
  // k = ex.find(r);
   int kpos = k + strlen(words[2]) -1;
  bool flag = (ipos != j && jpos != i && kpos != i && kpos != j && ipos != k && jpos != k && i != j && i != k && j != k);
  // cout<<i<<j<<k<<ipos<<jpos<<kpos<<endl;
   if( (lsum == esum) && flag && (i >= 0 && i < ex.length()) && (j >= 0 && j < ex.length()) && (k >= 0 && k < ex.length()))
   { cout<<"ACC"<<endl;}
   else
   { cout<<"WA"<<endl;}
  i=j=k=0;
 }

return 0;

}


#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#include <cctype>
#include <ios>
#include <iomanip>
#include <fstream>
using namespace std;

int main()
{

 char words[3][101];
 int test,lsum=0;
 int esum =0;
 string s;
 string ex(700,' ');
 int k,j,i;
 vector<string> v;
 getline(cin,s);
 v.push_back(s);
 getline(cin,s);
 v.push_back(s);
 getline(cin,s);
 v.push_back(s);
 getline(cin,s);
 test = atoi(s.c_str());
 for(i= 0; i<3;i++)
 { k =0;
   for(int j =0;j<v[i].length();j++)
    {
       if(isalpha(v[i][j]))
        {  words[i][k] = tolower(v[i][j]);k++;}
    }
    words[i][k] = '\0';
    lsum +=k;
 }

 while(test--)
 {
    getline(cin,s);
    k = s.length();

    j =0;
    esum = 0;
    for(i =0 ;i < k ; i++)
    {
       if(isalpha(s[i]))
       { ex[j] = tolower(s[i]);j++;}

    }
   ex[j] = '\0';
   esum = j;
   i = ex.find((const char*)(&words[0]));
   int ipos = i + strlen(words[0]) -1;
   j = ex.find((const char*)(&words[1]));
   int jpos = j + strlen(words[1]) -1;
   k = ex.find((const char*)(&words[2]));
   int kpos = k + strlen(words[2]) -1;
   bool flag = (ipos != j && jpos != i && kpos != i && kpos != j && ipos != k && jpos != k);

   if( (lsum == esum) && flag && (i >= 0 && i < ex.length()) && (j >= 0 && j < ex.length()) && (k >= 0 && k < ex.length()))
   { cout<<"ACC"<<endl;}
   else
   { cout<<"WA"<<endl;}
  i=j=k=0;
 }

return 0;

}


#include<iostream>
#include<cstdio>
#include<cstdlib>
using namespace std;
#define MAX 601

int main(){
 string s1, s2, s3;
 cin>>s1>>s2>>s3;
 string t1, t2, t3;
 for(int k=0; k<s1.length(); k++)
  if(isalnum(s1[k]))
   t1+=tolower(s1[k]);
 for(int k=0; k<s2.length(); k++)
  if(isalnum(s2[k]))
   t2+=tolower(s2[k]);
 for(int k=0; k<s3.length(); k++)
  if(isalnum(s3[k]))
   t3+=tolower(s3[k]);
 int n;
 cin>>n;
 while(n--){
  char p[MAX];
  string re;
  cin>>p;
  for(int k=0; p[k]!='\0'; k++){
   if(isalnum(p[k]))
    re+=tolower(p[k]);
  }
  string r1, r2, r3, r4, r5, r6;
  r1=t1+t2+t3;
  r2=t1+t3+t2;
  r3=t2+t1+t3;
  r4=t2+t3+t1;
  r5=t3+t1+t2;
  r6=t3+t2+t1;
  if(re==r1||re==r2||re==r3||re==r4||re==r5||re==r6)
   cout<<"ACC"<<endl;
  else
   cout<<"WA"<<endl;
 }
 return 0;
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define MAX 601

inline bool isOk(char c){
 return c!='-'&&c!='_'&&c!=';';
}

int main(){
 string s1, s2, s3;
 cin>>s1>>s2>>s3;
 string t1, t2, t3;
 for(int k=0; k<s1.length(); k++)
  if(isOk(s1[k]))
   t1+=tolower(s1[k]);
 for(int k=0; k<s2.length(); k++)
  if(isOk(s2[k]))
   t2+=tolower(s2[k]);
 for(int k=0; k<s3.length(); k++)
  if(isOk(s3[k]))
   t3+=tolower(s3[k]);
 int n;
 cin>>n;
 while(n--){
  char p[MAX];
  string re;
  cin>>p;
  for(int k=0; k<strlen(p); k++){
   if(isOk(p[k]))
    re+=tolower(p[k]);
  }
  string r1, r2, r3, r4, r5, r6;
  r1=t1+t2+t3;
  r2=t1+t3+t2;
  r3=t2+t1+t3;
  r4=t2+t3+t1;
  r5=t3+t1+t2;
  r6=t3+t2+t1;
  if(re==r1||re==r2||re==r3||re==r4||re==r5||re==r6)
   cout<<"AC"<<endl;
  else
   cout<<"WA"<<endl;
 }
 return 0;
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
using namespace std;
#define MAX 601

int main(){
 string s1, s2, s3;
 cin>>s1>>s2>>s3;
 string t1, t2, t3;
 for(int k=0; k<s1.length(); k++)
  if(isalnum(s1[k]))
   t1+=tolower(s1[k]);
 for(int k=0; k<s2.length(); k++)
  if(isalnum(s2[k]))
   t2+=tolower(s2[k]);
 for(int k=0; k<s3.length(); k++)
  if(isalnum(s3[k]))
   t3+=tolower(s3[k]);
 int n;
 cin>>n;
 while(n--){
  char p[MAX];
  string re;
  cin>>p;
  for(int k=0; p[k]!='\0'; k++){
   if(isalnum(p[k]))
    re+=tolower(p[k]);
  }
  string r1, r2, r3, r4, r5, r6;
  r1=t1+t2+t3;
  r2=t1+t3+t2;
  r3=t2+t1+t3;
  r4=t2+t3+t1;
  r5=t3+t1+t2;
  r6=t3+t2+t1;
  if(re==r1||re==r2||re==r3||re==r4||re==r5||re==r6)
   cout<<"AC"<<endl;
  else
   cout<<"WA"<<endl;
 }
 return 0;
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define MAX 601

inline bool isOk(char c){
 return c!='-'&&c!='_'&&c!=';';
}

int main(){
 string s1, s2, s3;
 cin>>s1>>s2>>s3;
 string t1, t2, t3;
 for(int k=0; k<s1.length(); k++)
  if(isOk(s1[k]))
   t1+=tolower(s1[k]);
 for(int k=0; k<s2.length(); k++)
  if(isOk(s2[k]))
   t2+=tolower(s2[k]);
 for(int k=0; k<s3.length(); k++)
  if(isOk(s3[k]))
   t3+=tolower(s3[k]);
 int n;
 cin>>n;
 while(n--){
  char p[MAX];
  string re;
  cin>>p;
  int q=-1;
  bool f=true;
  for(int k=0; k<strlen(p); k++){
   q++;
   if(q>250){
     f=false;
     continue;
   }
   if(isOk(p[k]))
    re+=tolower(p[k]);
  }
  string r1, r2, r3, r4, r5, r6;
  r1=t1+t2+t3;
  r2=t1+t3+t2;
  r3=t2+t1+t3;
  r4=t2+t3+t1;
  r5=t3+t1+t2;
  r6=t3+t2+t1;
  if(re==r1||re==r2||re==r3||re==r4||re==r5||re==r6&&f==true)
   cout<<"AC"<<endl;
  else
   cout<<"WA"<<endl;
 }
 return 0;
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define MAX 601

inline bool isOk(char c){
 return c!='-'&&c!='_'&&c!=';';
}

int main(){
 string s1, s2, s3;
 cin>>s1>>s2>>s3;
 string t1, t2, t3;
 for(int k=0; k<s1.length(); k++)
  if(isOk(s1[k]))
   t1+=tolower(s1[k]);
 for(int k=0; k<s2.length(); k++)
  if(isOk(s2[k]))
   t2+=tolower(s2[k]);
 for(int k=0; k<s3.length(); k++)
  if(isOk(s3[k]))
   t3+=tolower(s3[k]);
 int n;
 cin>>n;
 while(n--){
  char p[MAX];
  string re;
  cin>>p;
  int q=-1;
  for(int k=0; k<strlen(p); k++){
   q++;
   if(q>250)
     break;
   if(isOk(p[k]))
    re+=tolower(p[k]);
  }
  string r1, r2, r3, r4, r5, r6;
  r1=t1+t2+t3;
  r2=t1+t3+t2;
  r3=t2+t1+t3;
  r4=t2+t3+t1;
  r5=t3+t1+t2;
  r6=t3+t2+t1;
  if(re==r1||re==r2||re==r3||re==r4||re==r5||re==r6)
   cout<<"AC"<<endl;
  else
   cout<<"WA"<<endl;
 }
 return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <ctime>
#include <cmath>
#include <conio.h>

#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <list>
#include <vector>
#include <iostream>
#include <utility>

#define MP make_pair
#define FF fflush(stdin)
#define PB push_back
#define ST first
#define ND second
#define LL long long
#define SZ(y) (int)(y).size()
#define ALL(x) (x).begin(),(x).end()
#define FOR(i,x,n) for(int(i)=x;(i)<(n);++(i))
#define FORN(i,x,n) for(int(i)=x;(i)<=(n);++(i))
#define RFOR(i,x,n) for(int(i)=x;(i)>=(n);--(i))
#define TR(c,i) for(typeof((c).begin()) i=(c).begin(); (i)!=(c).end(); ++(i))
#define TRR(c,i) for(typeof((c).rbegin()) i=(c).rbegin(); (i)!=(c).rend(); ++(i))

using namespace std;

int main() {
    ios::sync_with_stdio(0);
    string ss[3];
    int pp = 0;
    FOR(i,0,3) {
       string tt;
       cin >> tt;
       int len = SZ(tt); ss[i].clear();
       FOR(j,0,len) {
          if (isalpha(tt[j]))
             ss[i] += tolower(tt[j]);
       }
       pp += SZ(ss[i]);
    }

    string ans[6];
    ans[0] = ss[0]+ss[1]+ss[2]; ans[1] = ss[0]+ss[2]+ss[1];
    ans[2] = ss[1]+ss[0]+ss[2]; ans[3] = ss[1]+ss[2]+ss[0];
    ans[4] = ss[2]+ss[0]+ss[1]; ans[5] = ss[2]+ss[1]+ss[0];

    int n;
    cin >> n;
    string tt;
    FOR(i,0,n) {
       string a = "";
       cin >> tt;
       int len = SZ(tt);
       FOR(j,0,len) {
          if (isalpha(tt[j]))
             a += tolower(tt[j]);
       }
       FOR(j,0,6) {
          if (a==ans[j]) {
             cout << "ACC" << endl;
             goto next;
          }
       }
       cout << "WA" << endl;
       next: continue;
    }

//    system("pause");
    return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <ctime>
#include <cmath>
#include <conio.h>

#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <list>
#include <vector>
#include <iostream>
#include <utility>

#define MP make_pair
#define FF fflush(stdin)
#define PB push_back
#define ST first
#define ND second
#define LL long long
#define SZ(y) (int)(y).size()
#define ALL(x) (x).begin(),(x).end()
#define FOR(i,x,n) for(int(i)=x;(i)<(n);++(i))
#define FORN(i,x,n) for(int(i)=x;(i)<=(n);++(i))
#define RFOR(i,x,n) for(int(i)=x;(i)>=(n);--(i))
#define TR(c,i) for(typeof((c).begin()) i=(c).begin(); (i)!=(c).end(); ++(i))
#define TRR(c,i) for(typeof((c).rbegin()) i=(c).rbegin(); (i)!=(c).rend(); ++(i))

using namespace std;

int main() {
    ios::sync_with_stdio(0);
    string ss[3];

    FOR(i,0,3) {
       string tt;
       cin >> tt;
       int len = SZ(tt); ss[i].clear();
       FOR(j,0,len) {
          if (isalpha(tt[j]))
             ss[i] += tolower(tt[j]);
       }
    }

    int n;
    cin >> n;
    string tt;
    FOR(i,0,n) {
       string a = "";
       cin >> tt;
       int len = SZ(tt);
       FOR(j,0,len) {
          if (isalpha(tt[j]))
             a += tolower(tt[j]);
       }
       size_t x;
       FOR(j,0,3) {
          if ((x=a.find(ss[j]))==string::npos) {
             cout << "WA" << endl;
             goto next;
          }
          else {
             a.erase(x,SZ(ss[j]));
          }
       }
       if (a.empty())
          cout << "ACC" << endl;
       else {
          cout << "WA" << endl;
       }
       next: continue;
    }

//    system("pause");
    return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <ctime>
#include <cmath>
#include <conio.h>

#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <list>
#include <vector>
#include <iostream>
#include <utility>

#define MP make_pair
#define FF fflush(stdin)
#define PB push_back
#define ST first
#define ND second
#define LL long long
#define SZ(y) (int)(y).size()
#define ALL(x) (x).begin(),(x).end()
#define FOR(i,x,n) for(int(i)=x;(i)<(n);++(i))
#define FORN(i,x,n) for(int(i)=x;(i)<=(n);++(i))
#define RFOR(i,x,n) for(int(i)=x;(i)>=(n);--(i))
#define TR(c,i) for(typeof((c).begin()) i=(c).begin(); (i)!=(c).end(); ++(i))
#define TRR(c,i) for(typeof((c).rbegin()) i=(c).rbegin(); (i)!=(c).rend(); ++(i))

using namespace std;

int main() {
    ios::sync_with_stdio(0);
    string ss[3];
    int pp = 0;
    FOR(i,0,3) {
       string tt;
       cin >> tt;
       int len = SZ(tt); ss[i].clear();
       FOR(j,0,len) {
          if (isalpha(tt[j]))
             ss[i] += tolower(tt[j]);
       }
       pp += SZ(ss[i]);
    }

    int n;
    cin >> n;
    string tt;
    FOR(i,0,n) {
       string a = "";
       cin >> tt;
       int len = SZ(tt);
       FOR(j,0,len) {
          if (isalpha(tt[j]))
             a += tolower(tt[j]);
       }
       size_t x;
       FOR(j,0,3) {
          if ((x=a.find(ss[j]))==string::npos) {
             cout << "WA" << endl;
             goto next;
          }
       }
       if (SZ(a)==pp)
          cout << "ACC" << endl;
       else
          cout << "WA" << endl;
       next: continue;
    }

//    system("pause");
    return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <ctime>
#include <cmath>
#include <conio.h>

#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <list>
#include <vector>
#include <iostream>
#include <utility>

#define MP make_pair
#define FF fflush(stdin)
#define PB push_back
#define ST first
#define ND second
#define LL long long
#define SZ(y) (int)(y).size()
#define ALL(x) (x).begin(),(x).end()
#define FOR(i,x,n) for(int(i)=x;(i)<(n);++(i))
#define FORN(i,x,n) for(int(i)=x;(i)<=(n);++(i))
#define RFOR(i,x,n) for(int(i)=x;(i)>=(n);--(i))
#define TR(c,i) for(typeof((c).begin()) i=(c).begin(); (i)!=(c).end(); ++(i))
#define TRR(c,i) for(typeof((c).rbegin()) i=(c).rbegin(); (i)!=(c).rend(); ++(i))

using namespace std;

int main() {
    ios::sync_with_stdio(0);
    string ss[3];
    int pp = 0;
    FOR(i,0,3) {
       string tt;
       cin >> tt;
       int len = SZ(tt); ss[i].clear();
       FOR(j,0,len) {
          if (isalpha(tt[j]))
             ss[i] += tolower(tt[j]);
       }
       pp += SZ(ss[i]);
    }

    int n;
    cin >> n;
    string tt;
    FOR(i,0,n) {
       string a = "";
       cin >> tt;
       int len = SZ(tt);
       FOR(j,0,len) {
          if (isalpha(tt[j]))
             a += tolower(tt[j]);
       }
       size_t x; tt = a;
       FOR(j,0,3) {
          if ((x=a.find(ss[j]))==string::npos) {
             cout << "WA" << endl;
             goto next;
          }
          else
             a.erase(x,SZ(ss[j]));
       }
       if (!a.empty())
          cout << "WA" << endl;
       else {
          FOR(j,0,3) {
             if ((x=tt.find(ss[j]))==string::npos) {
                cout << "WA" << endl;
                goto next;
             }
          }
          if (SZ(tt)==pp)
             cout << "ACC" << endl;
          else
             cout << "WA" << endl;
       }
       next: continue;
    }

//    system("pause");
    return 0;
}


#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
#include <cmath>

using namespace std;

string pp(string);

int main(){
	freopen("a.in","r",stdin);

	int n;
    string s[3];
    string SS[6] = {""};

    for (int i = 0; i < 3; ++ i) {
    	getline(cin,s[i]);
    	s[i] = pp(s[i]);
    }

    int uk = 0;
    do {
    	SS[uk++] = s[0]+s[1]+s[2];
    } while(next_permutation(s,s+3));

    string s1;
    cin >> n;
    getline(cin,s1);

    for (int i = 0; i < n; ++ i) {
    	bool ok = false;
    	getline(cin,s1);
    	s1 = pp(s1);
//    	cout << s1 << ' ';
    	for (int j = 0; j < uk; ++ j) {
    		if (s1 == SS[j]) {
    			cout << "ACC\n";
    			ok = true;
				break;
    		}
    	}

    	if (!ok) {
    		cout << "WA\n";
    	}
    }

    return 0;
}

string pp(string s){
    for (int i = 0; i < s.length(); ++ i) {
    	if (s[i] == '-' || s[i] == ';' || s[i] == '_') {
    		s.erase(i,1);
    		i--;
    	}
    }
    for (int i = 0; i < s.length(); ++ i) {
    	s[i] = tolower(s[i]);
    }

	return s;
}


#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
#include <cmath>

using namespace std;

string pp(string);

int main(){
	freopen("a.in","r",stdin);

	int n;
	int a[3] = {0,1,2};
    string s[3];
    string SS[100] = {""};

    for (int i = 0; i < 3; ++ i) {
    	getline(cin,s[i]);
    	s[i] = pp(s[i]);
    }

    int uk = 0;
    do {
    	SS[uk++] = s[a[0]]+s[a[1]]+s[a[2]];
    } while(next_permutation(a,a+3));

    string s1;
    cin >> n;
    getline(cin,s1);

    for (int i = 0; i < n; ++ i) {
    	bool ok = false;
    	getline(cin,s1);
    	s1 = pp(s1);
//    	cout << s1 << ' ';
    	for (int j = 0; j < uk; ++ j) {
    		if (s1 == SS[j]) {
    			cout << "ACC\n";
    			ok = true;
				break;
    		}
    	}

    	if (!ok) {
    		cout << "WA\n";
    	}
    }

//*/
    return 0;
}

string pp(string s){
    for (int i = 0; i < s.length(); ++ i) {
    	if (s[i] == '-' || s[i] == ';' || s[i] == '_') {
    		s.erase(i,1);
    		i--;
    	}
    }
    for (int i = 0; i < s.length(); ++ i) {
    	s[i] = tolower(s[i]);
    }

	return s;
}


#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
#include <cmath>

using namespace std;

string pp(string);

int main(){
//	freopen("a.in","r",stdin);

	int n;
	int a[3] = {0,1,2};
    string s[3];
    string SS[100] = {""};

    for (int i = 0; i < 3; ++ i) {
    	getline(cin,s[i]);
    	s[i] = pp(s[i]);
    }

    int uk = 0;
    do {
    	SS[uk++] = s[a[0]]+s[a[1]]+s[a[2]];
    } while(next_permutation(a,a+3));

    string s1;
    cin >> n;
    getline(cin,s1);

    for (int i = 0; i < n; ++ i) {
    	bool ok = false;
    	getline(cin,s1);
    	s1 = pp(s1);
//    	cout << s1 << ' ';
    	for (int j = 0; j < uk; ++ j) {
    		if (s1 == SS[j]) {
    			cout << "ACC\n";
    			ok = true;
				break;
    		}
    	}

    	if (!ok) {
    		cout << "WA\n";
    	}
    }

//*/
    return 0;
}

string pp(string s){
    for (int i = 0; i < s.length(); ++ i) {
    	if (s[i] == '-' || s[i] == ';' || s[i] == '_') {
    		s.erase(i,1);
    		i--;
    	}
    }
    for (int i = 0; i < s.length(); ++ i) {
    	s[i] = tolower(s[i]);
    }

	return s;
}


#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
#include <cmath>

using namespace std;

string pp(string);

int main(){
//	freopen("a.in","r",stdin);

	int n;
    string s[3];
    string SS[6] = {""};

    for (int i = 0; i < 3; ++ i) {
    	getline(cin,s[i]);
    	s[i] = pp(s[i]);
    }

    int uk = 0;
    do {
    	SS[uk++] = s[0]+s[1]+s[2];
    } while(next_permutation(s,s+3));

    string s1;
    cin >> n;
    getline(cin,s1);

    for (int i = 0; i < n; ++ i) {
    	bool ok = false;
    	getline(cin,s1);
    	s1 = pp(s1);
//    	cout << s1 << ' ';
    	for (int j = 0; j < uk; ++ j) {
    		if (s1 == SS[j]) {
    			cout << "ACC\n";
    			ok = true;
				break;
    		}
    	}

    	if (!ok) {
    		cout << "WA\n";
    	}
    }

    return 0;
}

string pp(string s){
    for (int i = 0; i < s.length(); ++ i) {
    	if (s[i] == '-' || s[i] == ';' || s[i] == '_') {
    		s.erase(i,1);
    		i--;
    	}
    }
    for (int i = 0; i < s.length(); ++ i) {
    	s[i] = tolower(s[i]);
    }

	return s;
}


#include<string>
#include<iostream>
using namespace std;
void cr(string &t);
void cr(string &t){
	string z="";
	for(int i=0;i<t.size();++i){
		if((t[i]>='a'&&t[i]<='z')||(t[i]>='A'&&t[i]<='Z')) z+=(t[i]<'a'?t[i]+32:t[i]);
	}
	t=z;
}
int main() {
	string a,b,c,t,ck[6];
	cin>>a>>b>>c;
	cr(a); cr(b); cr(c);
	ck[0]=a+b+c;
	ck[1]=a+c+b;
	ck[2]=b+a+c;
	ck[3]=b+c+a;
	ck[4]=c+a+b;
	ck[5]=c+b+a;
	int n;
	bool acc;
	cin>>n;
	while(n--){
		cin>>t;
		cr(t);
		acc=0;
		for(int i=0;i<6;++i){
			if(t==ck[i]) {acc=1;break;}
		}
		cout<<(acc?"ACC":"WA")<<endl;
	}
	return 0;
}


#include<stdio.h>
#include<iostream>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<ctype.h>
#include<vector>
#include<algorithm>
#define pb push_back
#define er erase
#define be begin
#define si size
#define N 310
#define INF 100000000
#define sc scanf
#define pr printf
#define fori(x,y) for(int i=(x);i<(y);i++)
#define forj(x,y) for(int j=(x);j<(y);j++)
using namespace std;
char a[N],b[N],c[N],d[N],e[N],f[N],x[N*2],y[N],z[N];
void to(char *p,int ln,char *q)
{
    int lq=0;
    fori(0,ln)
        if(isalpha(p[i])){
            if(isupper(p[i])){q[lq]=p[i]+32;lq++;}
            else {q[lq]=p[i];lq++;}
        }
        q[lq]=NULL;
}
main()
{
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);*/
int ln,n,l,lx,k;
bool u[6];
sc("%s\n%s\n%s",a,b,c);
to(a,strlen(a),x);
to(b,strlen(b),y);
to(c,strlen(c),z);
l=strlen(x)+strlen(y)+strlen(z);
strcpy(a,x); strcat(a,y); strcat(a,z);
strcpy(b,x); strcat(b,z); strcat(b,y);
strcpy(c,y); strcat(c,x); strcat(c,z);
strcpy(d,y); strcat(d,z); strcat(d,x);
strcpy(e,z); strcat(e,x); strcat(e,y);
strcpy(f,z); strcat(f,y); strcat(f,x);
a[l]=NULL;
b[l]=NULL;
c[l]=NULL;
d[l]=NULL;
e[l]=NULL;
f[l]=NULL;
sc("%d\n",&n);
fori(0,n)
{
    sc("%s\n",x);
    forj(0,6)u[j]=false;
    l=0;
    k=0;
    lx=strlen(x);
    forj(0,lx)
    {
        while(x[j]=='-'||x[j]=='_'||x[j]==';')j++;
        if(j==lx){pr("ACC\n");k=1;break;}
        if(!u[0]&&x[j]!=a[l]&&x[j]!=a[l]-32)u[0]=1;
        if(!u[1]&&x[j]!=b[l]&&x[j]!=b[l]-32)u[1]=1;
        if(!u[2]&&x[j]!=c[l]&&x[j]!=c[l]-32)u[2]=1;
        if(!u[3]&&x[j]!=d[l]&&x[j]!=d[l]-32)u[3]=1;
        if(!u[4]&&x[j]!=e[l]&&x[j]!=e[l]-32)u[4]=1;
        if(!u[5]&&x[j]!=f[l]&&x[j]!=f[l]-32)u[5]=1;
        if(u[0]&&u[1]&&u[2]&&u[3]&&u[4]&&u[5]){pr("WA\n");k=1;break;}
        l++;
    }
    if(!k)pr("ACC\n");
}
return 0;
}


#include<stdio.h>
#include<string.h>
#include<ctype.h>
#include<stdlib.h>
#include<math.h>
struct my
{
    char b[605];
    int lb;
}q[10000];
main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
int i,j,n,ls,lc,la,l1=0,l2=0,l3=0,k;
char s[300],c[300],a[300];
scanf("%s %s %s",&s,&c,&a);
ls=strlen(s);
lc=strlen(c);
la=strlen(a);
scanf("%d",&n);
for(i=0;i<n;i++)
{
    scanf("%s",&q[i].b);
    q[i].lb=strlen(q[i].b);
    for(j=0;j<q[i].lb;j++)
    {
        if(!isalpha(q[i].b[j]))
        {
            for(k=j;k<q[i].lb;k++)
            {
                q[i].b[k]=q[i].b[k+1];
            }
        q[i].lb--;
        j--;
        }
        if(isalpha(q[i].b[j])&&isupper(q[i].b[j]))
        {
            q[i].b[j]=tolower(q[i].b[j]);
        }
    }
}
for(i=0;i<ls;i++)
{
    if(!isalpha(s[i]))
    {
        for(j=i;j<ls;j++)
        {
            s[j]=s[j+1];
        }
    ls--;
    i--;
    }
    if(isalpha(s[i])&&isupper(s[i]))
    {
        s[i]=tolower(s[i]);
    }
}
for(i=0;i<lc;i++)
{
    if(!isalpha(c[i]))
    {
        for(j=i;j<lc;j++)
        {
            c[j]=c[j+1];
        }
    lc--;
    i--;
    }
    if(isalpha(c[i])&&isupper(c[i]))
    {
        c[i]=tolower(c[i]);
    }
}
for(i=0;i<la;i++)
{
    if(!isalpha(a[i]))
    {
        for(j=i;j<la;j++)
        {
            a[j]=a[j+1];
        }
    la--;
    i--;
    }
    if(isalpha(a[i])&&isupper(a[i]))
    {
        a[i]=tolower(a[i]);
    }
}
for(i=0;i<n;i++)
{
    if(strstr(q[i].b,s)&&strstr(q[i].b,c)&&strstr(q[i].b,a))
    {
        if(q[i].lb!=ls+lc+la)
        {
            printf("WA\n");
        }
        else
        {
            printf("ACC\n");
        }
        l1=1;
    }
    if(l1==0)
    {
        printf("WA\n");
    }
    l1=0;
}
if(strstr(a,s))
getchar();
getchar();
return 0;
}


#include<stdio.h>
#include<iostream>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<ctype.h>
#include<vector>
#include<algorithm>
#define pb push_back
#define er erase
#define be begin
#define si size
#define N 310
#define INF 100000000
#define sc scanf
#define pr printf
#define fori(x,y) for(int i=(x);i<(y);i++)
#define forj(x,y) for(int j=(x);j<(y);j++)
using namespace std;
char a[N],b[N],c[N],d[N],e[N],f[N],x[N*2],y[N],z[N];
void to(char *p,int ln,char *q)
{
    int lq=0;
    fori(0,ln)
        if(isalpha(p[i])){
            if(isupper(p[i])){q[lq]=p[i]+32;lq++;}
            else {q[lq]=p[i];lq++;}
        }
}
main()
{
/*freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);*/
int ln,n,l,lx,k;
bool u[6];
sc("%s\n%s\n%s",a,b,c);
to(a,strlen(a),x);
to(b,strlen(b),y);
to(c,strlen(c),z);
strcpy(a,x); strcat(a,y); strcat(a,z);
strcpy(b,x); strcat(b,z); strcat(b,y);
strcpy(c,y); strcat(c,x); strcat(c,z);
strcpy(d,y); strcat(d,z); strcat(d,x);
strcpy(e,z); strcat(e,x); strcat(e,y);
strcpy(f,z); strcat(f,y); strcat(f,x);
sc("%d\n",&n);
fori(0,n)
{
    sc("%s\n",x);
    forj(0,6)u[j]=false;
    l=0;
    k=0;
    lx=strlen(x);
    forj(0,lx)
    {
        while(x[j]=='-'||x[j]=='_'||x[j]==';')j++;
        if(j==lx){pr("ACC\n");k=1;break;}
        if(!u[0]&&x[j]!=a[l]&&x[j]!=a[l]-32)u[0]=1;
        if(!u[1]&&x[j]!=b[l]&&x[j]!=b[l]-32)u[1]=1;
        if(!u[2]&&x[j]!=c[l]&&x[j]!=c[l]-32)u[2]=1;
        if(!u[3]&&x[j]!=d[l]&&x[j]!=d[l]-32)u[3]=1;
        if(!u[4]&&x[j]!=e[l]&&x[j]!=e[l]-32)u[4]=1;
        if(!u[5]&&x[j]!=f[l]&&x[j]!=f[l]-32)u[5]=1;
        if(u[0]&&u[1]&&u[2]&&u[3]&&u[4]&&u[5]){pr("WA\n");k=1;break;}
        l++;
    }
    if(!k)pr("ACC\n");
}
return 0;
}


#include<stdio.h>
#include<iostream>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<ctype.h>
#include<vector>
#include<algorithm>
# define si size
# define er erase
# define sc scanf
# define be begin
# define pr printf
# define pb push_back
# define INF 100000000.0
# define For(x,y) for(int o=(x);o<(y);o++)
# define prdata(A,x,y) For(x,y)pr(,A[o]);
using namespace std;
main()
{
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
string st[10];
int ln,i,j,k,ind[5],n;
char s[5][105],c[605];
for(k=0;k<3;k++)
{
    sc("%s",s[k]);
    ln=strlen(s[k]);
    for(i=0;i<ln;i++)
    {
        if(s[k][i]>64&&s[k][i]<91)s[k][i]+=32;
        if(s[k][i]==';'||s[k][i]=='_'||s[k][i]=='-')
        {
            for(j=i;j<ln-1;j++)
            {
                s[k][j]=s[k][j+1];
            }
            i--;
            ln--;
        }
    }
    s[k][ln]='\0';
}
For(0,3)ind[o]=o;
For(0,6)
{
    st[o]=s[ind[0]];
    st[o]+=s[ind[1]];
    st[o]+=s[ind[2]];
    next_permutation(ind,ind+3);
}
/*For(0,6)
{
    cout<<st[o]<<endl;
}
For(0,3)pr("%s\n",s[o]);*/
sc("%d",&n);
For(0,n)
{
    sc("%s",c);
    ln=strlen(c);
    for(i=0;i<ln;i++)
    {
        if(c[i]>64&&c[i]<91)c[i]+=32;
        if(c[i]==';'||c[i]=='_'||c[i]=='-')
        {
            for(j=i;j<ln-1;j++)
            {
                c[j]=c[j+1];
            }
            i--;
            ln--;
        }
    }
    c[ln]='\0';
    //pr("%s\n",c);
    for(i=0;i<6;i++)
    {
        if(st[i]==c)
        {
            puts("ACC");
            break;
        }
    }
    if(i==6)puts("WA");
}
return 0;
}


#include<stdio.h>
#include<string.h>
#include<ctype.h>
#include<stdlib.h>
#include<math.h>
struct my
{
    char b[605];
    int lb;
}q[10000];
main()
{
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
int i,j,n,ls,lc,la,l1=0,l2=0,l3=0,k;
char s[300],c[300],a[300];
scanf("%s %s %s",&s,&c,&a);
ls=strlen(s);
lc=strlen(c);
la=strlen(a);
scanf("%d",&n);
for(i=0;i<n;i++)
{
    scanf("%s",&q[i].b);
    q[i].lb=strlen(q[i].b);
    for(j=0;j<q[i].lb;j++)
    {
        if(!isalpha(q[i].b[j]))
        {
            for(k=j;k<q[i].lb;k++)
            {
                q[i].b[k]=q[i].b[k+1];
            }
        q[i].lb--;
        j--;
        }
        if(isalpha(q[i].b[j])&&isupper(q[i].b[j]))
        {
            q[i].b[j]=tolower(q[i].b[j]);
        }
    }
}
for(i=0;i<ls;i++)
{
    if(!isalpha(s[i]))
    {
        for(j=i;j<ls;j++)
        {
            s[j]=s[j+1];
        }
    ls--;
    i--;
    }
    if(isalpha(s[i])&&isupper(s[i]))
    {
        s[i]=tolower(s[i]);
    }
}
for(i=0;i<lc;i++)
{
    if(!isalpha(c[i]))
    {
        for(j=i;j<lc;j++)
        {
            c[j]=c[j+1];
        }
    lc--;
    i--;
    }
    if(isalpha(c[i])&&isupper(c[i]))
    {
        c[i]=tolower(c[i]);
    }
}
for(i=0;i<la;i++)
{
    if(!isalpha(a[i]))
    {
        for(j=i;j<la;j++)
        {
            a[j]=a[j+1];
        }
    la--;
    i--;
    }
    if(isalpha(a[i])&&isupper(a[i]))
    {
        a[i]=tolower(a[i]);
    }
}
for(i=0;i<n;i++)
{
    if(strstr(q[i].b,s)&&strstr(q[i].b,c)&&strstr(q[i].b,a))
    {
        if(q[i].lb!=ls+lc+la)
        {
            printf("WA\n");
        }
        else
        {
            printf("ACC\n");
        }
        l1=1;
    }
    if(l1==0)
    {
        printf("WA\n");
    }
    l1=0;
}
if(strstr(a,s))
getchar();
getchar();
return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define cnt(x , n) count(x.begin(),x.end(),n)
#define so(x) sort(x.begin(),x.end())
#define rso(x) sort(x.rbegin(),x.rend())
#define mx(x) *max_element(x.begin(),x.end())
#define mn(x) *min_element(x.begin(),x.end())
#define rev(x) reverse(x.begin(),x.end())
#define pb push_back
#define al(n) (n).begin(),(n).end()
#define ral(n) (n).rbegin(),(n).rend()
#define mp make_pair
#define sz size()
#define F first
#define S second
#define rFoR(i,x,n) for(int i=x;i>n;--i)
#define FoR(i,x,n) for(int i = x; i < n; i++)
#define bo bool
#define RE(s) freopen(s, "r", stdin)
#define WR(s) freopen(s, "w", stdout)

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<string> vs;
typedef pair<int, int> pi;
typedef vector<pi> vpi;
int main() {
#ifndef ONLINE_JUDGE
    RE("text.txt");
#endif
    vector<string> ori;
    int n , x = 0;
    string s;
    FoR(t,0,3)
    {
        cin >> s;
        string temp;
        for (unsigned int i = 0; i < s.sz; i++)
            if (isalpha(s[i]))
                temp += tolower(s[i]);

        ori.pb(temp);
    }
    FoR(i,0,ori.sz)
        x+=ori[i].sz;

    scanf("%d", &n);
    FoR(t,0,n)
    {
        cin >> s;
        string temp;
        for (unsigned int i = 0; i < s.sz; i++)
            if (isalpha(s[i]))
                temp += tolower(s[i]);
        bool z = 0;
        for(int i = 0 ; i < 3 ; i++){
            int q = temp.find(ori[i]);
            if(q > temp.sz || q < 0 ){
                z = 1;
                break;
            }
        }
        if(!z)
            (x != temp.sz)? puts("WA"):puts("ACC");
        if(z)
            puts("WA");
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define cnt(x , n) count(x.begin(),x.end(),n)
#define so(x) sort(x.begin(),x.end())
#define rso(x) sort(x.rbegin(),x.rend())
#define mx(x) *max_element(x.begin(),x.end())
#define mn(x) *min_element(x.begin(),x.end())
#define rev(x) reverse(x.begin(),x.end())
#define pb push_back
#define al(n) (n).begin(),(n).end()
#define ral(n) (n).rbegin(),(n).rend()
#define mp make_pair
#define sz size()
#define F first
#define S second
#define rFoR(i,x,n) for(int i=x;i>n;--i)
#define FoR(i,x,n) for(int i = x; i < n; i++)
#define bo bool
#define RE(s) freopen(s, "r", stdin)
#define WR(s) freopen(s, "w", stdout)

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<string> vs;
typedef pair<int, int> pi;
typedef vector<pi> vpi;
int main() {
#ifndef ONLINE_JUDGE
    RE("text.txt");
#endif
    vector<string> ori;
    int n , x = 0;
    string s;
    FoR(t,0,3)
    {
        cin >> s;
        string temp;
        for (unsigned int i = 0; i < s.sz; i++)
            if (isalpha(s[i]))
                temp += tolower(s[i]);

        ori.pb(temp);
    }
    FoR(i,0,ori.sz)
        x+=ori[i].sz;

    scanf("%d", &n);
    FoR(t,0,n)
    {
        cin >> s;
        string temp;
        for (unsigned int i = 0; i < s.sz; i++)
            if (isalpha(s[i]))
                temp += tolower(s[i]);
        bool z = 0;
        for(int i = 0 ; i < 3 ; i++){
            int q = temp.find(ori[i]);
            if(q > temp.sz || q < 0 ){
                z = 1;
                break;
            }
            for(unsigned int j = q ; j < ori[i].sz ; j++)
                temp[j] = '1';

        }

        if(!z)
            (x != temp.sz)? puts("WA"):puts("ACC");
        if(z)
            puts("WA");
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define cnt(x , n) count(x.begin(),x.end(),n)
#define so(x) sort(x.begin(),x.end())
#define rso(x) sort(x.rbegin(),x.rend())
#define mx(x) *max_element(x.begin(),x.end())
#define mn(x) *min_element(x.begin(),x.end())
#define rev(x) reverse(x.begin(),x.end())
#define pb push_back
#define al(n) (n).begin(),(n).end()
#define ral(n) (n).rbegin(),(n).rend()
#define mp make_pair
#define sz size()
#define F first
#define S second
#define rFoR(i,x,n) for(int i=x;i>n;--i)
#define FoR(i,x,n) for(int i = x; i < n; i++)
#define bo bool
#define RE(s) freopen(s, "r", stdin)
#define WR(s) freopen(s, "w", stdout)

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<string> vs;
typedef pair<int, int> pi;
typedef vector<pi> vpi;
int main() {
#ifndef ONLINE_JUDGE
    RE("text.txt");
#endif
    vector<string> ori;
    int n, x = 0;
    string s;
    FoR(t,0,3)
    {
        cin >> s;
        string temp;
        for (unsigned int i = 0; i < s.sz; i++)
            if (isalpha(s[i]))
                temp += tolower(s[i]);

        ori.pb(temp);
    }
    FoR(i,0,ori.sz)
        x += ori[i].sz;

    scanf("%d", &n);
    FoR(t,0,n)
    {
        cin >> s;
        string temp;
        for (unsigned int i = 0; i < s.sz; i++)
            if (isalpha(s[i]))
                temp += tolower(s[i]);
        bool z = 0;
        for (int i = 0; i < 3; i++) {
            int q = temp.find(ori[i]);
            if (q > temp.sz || q < 0) {
                z = 1;
                break;
            }
            for (unsigned int j = q; j < q + ori[i].sz; j++)
                temp[j] = '1';

        }
        if (!z)
            (x != temp.sz) ? puts("WA") : puts("ACC");
        if (z)
            puts("WA");
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define cnt(x , n) count(x.begin(),x.end(),n)
#define so(x) sort(x.begin(),x.end())
#define rso(x) sort(x.rbegin(),x.rend())
#define mx(x) *max_element(x.begin(),x.end())
#define mn(x) *min_element(x.begin(),x.end())
#define rev(x) reverse(x.begin(),x.end())
#define pb push_back
#define al(n) (n).begin(),(n).end()
#define ral(n) (n).rbegin(),(n).rend()
#define mp make_pair
#define sz size()
#define F first
#define S second
#define rFoR(i,x,n) for(int i=x;i>n;--i)
#define FoR(i,x,n) for(int i = x; i < n; i++)
#define bo bool
#define RE(s) freopen(s, "r", stdin)
#define WR(s) freopen(s, "w", stdout)

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<string> vs;
typedef pair<int, int> pi;
typedef vector<pi> vpi;
int main() {
#ifndef ONLINE_JUDGE
    RE("text.txt");
#endif
    vector<string> ori;
    int n, x = 0;
    string s;
    FoR(t,0,3)
    {
        cin >> s;
        string temp;
        for (unsigned int i = 0; i < s.sz; i++)
            if (isalpha(s[i]))
                temp += tolower(s[i]);

        ori.pb(temp);
    }
    FoR(i,0,ori.sz)
        x += ori[i].sz;
    for(int i = 0 ; i < ori.sz ; i++)
        for(int j = i+1 ; j < ori.sz ; j++)
            if(ori[i].sz < ori[j].sz)
                swap(ori[i],ori[j]);

    scanf("%d", &n);
    FoR(t,0,n)
    {
        cin >> s;
        string temp;
        for (unsigned int i = 0; i < s.sz; i++)
            if (isalpha(s[i]))
                temp += tolower(s[i]);
        bool z = 0;
        for (int i = 0; i < 3; i++) {
            int q = temp.find(ori[i]);
            if (q > temp.sz || q < 0) {
                z = 1;
                break;
            }
            for (unsigned int j = q; j < q + ori[i].sz; j++)
                temp[j] = '1';
        }
        if (!z)
            (x != temp.sz) ? puts("WA") : puts("ACC");
        if (z)
            puts("WA");
    }
    return 0;
}


#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <queue>
#include <vector>
#include <stack>
#include <set>
#include <map>
#include <string>
#include <cctype>
#include <cstring>

using namespace std;

int main()
{
	string ans[3];
	for(int i=0;i<3;i++)cin>>ans[i];
	for(int i=0;i<3;i++){
		for(int j=0;j<ans[i].size();j++){
			if(isupper(ans[i][j]))ans[i][j]=tolower(ans[i][j]);
			if(!isalpha(ans[i][j])){ans[i].erase(ans[i].begin()+j);j--;}
		}
	}
	int od[3]={
		0,1,2
	};
	int len=0;
	string tem[99];
	do{
		tem[len]="";
		for(int i=0;i<3;i++){
			tem[len]+=ans[od[i]];
		}
		len++;
	}while(next_permutation(od,od+3));
	//for(int i=0;i<6;i++)cout<<tem[i]<<endl;
	int n;
	cin>>n;
	string res[2]={
		"ACC","WA"
	};
	string s;
	for(int i=0;i<n;i++){
		cin>>s;
		bool OK=false;
		for(int j=0;j<s.size();j++){
			if(isupper(s[j]))s[j]=tolower(s[j]);
			if(!isalpha(s[j])){s.erase(s.begin()+j);j--;}
		}
		for(int j=0;j<len;j++){
			if(tem[j].size()<=s.size())
			for(int k=0;k<s.size()-tem[j].size()+1;k++){
				if(tem[j]==s.substr(k,tem[j].size())){
					OK=true;break;
				}
			}
			if(OK)break;
		}
		if(OK)cout<<res[0]<<endl;
		else cout<<res[1]<<endl;
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <queue>
#include <vector>
#include <stack>
#include <set>
#include <map>
#include <string>
#include <cctype>
#include <cstring>

using namespace std;

int main()
{
	string ans[3];
	for(int i=0;i<3;i++)cin>>ans[i];
	for(int i=0;i<3;i++){
		for(int j=0;j<ans[i].size();j++){
			if(!isalpha(ans[i][j])){ans[i].erase(ans[i].begin()+j);j--;}
			if(isupper(ans[i][j])){
				ans[i][j]=tolower(ans[i][j]);
			}
		}
	}
	int od[3]={
		0,1,2
	};
	int len=0;
	string tem[99];
	do{
		tem[len]="";
		for(int i=0;i<3;i++){
			tem[len]+=ans[od[i]];
		}
		len++;
	}while(next_permutation(od,od+3));
	//for(int i=0;i<6;i++)cout<<tem[i]<<endl;
	int n;
	cin>>n;
	string res[2]={
		"ACC","WA"
	};
	string s;
	for(int i=0;i<n;i++){
		cin>>s;
		bool OK=false;
		for(int j=0;j<s.size();j++){
			if(!isalpha(s[j])){s.erase(s.begin()+j);j--;}
			if(isupper(s[j]))s[j]=tolower(s[j]);
		}
		for(int j=0;j<len;j++){
			for(int k=0;k<s.size()-tem[j].size()+1;k++){
				if(tem[j]==s.substr(k,tem[j].size())){
					OK=true;break;
				}
			}
			if(OK)break;
		}
		if(OK)cout<<res[0]<<endl;
		else cout<<res[1]<<endl;
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <queue>
#include <vector>
#include <stack>
#include <set>
#include <map>
#include <string>
#include <cctype>
#include <cstring>

using namespace std;

int main()
{
	string ans[3];
	for(int i=0;i<3;i++)cin>>ans[i];
	for(int i=0;i<3;i++){
		for(int j=0;j<ans[i].size();j++){
			if(isupper(ans[i][j]))ans[i][j]=tolower(ans[i][j]);
			if(!isalpha(ans[i][j])){ans[i].erase(ans[i].begin()+j);j--;}
		}
	}
	int od[3]={
		0,1,2
	};
	int len=0;
	string tem[99];
	do{
		tem[len]="";
		for(int i=0;i<3;i++){
			tem[len]+=ans[od[i]];
		}
		len++;
	}while(next_permutation(od,od+3));
	for(int i=0;i<6;i++)cout<<tem[i]<<endl;
	int n;
	cin>>n;
	string res[2]={
		"ACC","WA"
	};
	string s;
	for(int i=0;i<n;i++){
		cin>>s;
		bool OK=false;
		for(int j=0;j<s.size();j++){
			if(isupper(s[j]))s[j]=tolower(s[j]);
			if(!isalpha(s[j])){s.erase(s.begin()+j);j--;}
		}
		for(int j=0;j<len;j++){
			if(tem[j].size()<=s.size())
			for(int k=0;k<s.size()-tem[j].size()+1;k++){
				if(tem[j]==s.substr(k,tem[j].size())){
					OK=true;break;
				}
			}
			if(OK)break;
		}
		if(OK)cout<<res[0]<<endl;
		else cout<<res[1]<<endl;
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <queue>
#include <vector>
#include <stack>
#include <set>
#include <map>
#include <string>
#include <cctype>
#include <cstring>

using namespace std;

int main()
{
	string ans[3];
	for(int i=0;i<3;i++)cin>>ans[i];
	for(int i=0;i<3;i++){
		for(int j=0;j<ans[i].size();j++){
			if(isupper(ans[i][j]))ans[i][j]=tolower(ans[i][j]);
			if(!isalpha(ans[i][j])){ans[i].erase(ans[i].begin()+j);j--;}
		}
	}
	int od[3]={
		0,1,2
	};
	int len=0;
	string tem[99];
	do{
		tem[len]="";
		for(int i=0;i<3;i++){
			tem[len]+=ans[od[i]];
		}
		len++;
	}while(next_permutation(od,od+3));
	//for(int i=0;i<6;i++)cout<<tem[i]<<endl;
	int n;
	cin>>n;
	string res[2]={
		"ACC","WA"
	};
	string s;
	for(int i=0;i<n;i++){
		cin>>s;
		bool OK=false;
		for(int j=0;j<s.size();j++){
			if(isupper(s[j]))s[j]=tolower(s[j]);
			if(!isalpha(s[j])){s.erase(s.begin()+j);j--;}
		}
		for(int j=0;j<len;j++){
			for(int k=0;k<s.size()-tem[j].size()+1;k++){
				if(tem[j]==s.substr(k,tem[j].size())){
					OK=true;break;
				}
			}
			if(OK)break;
		}
		if(OK)cout<<res[0]<<endl;
		else cout<<res[1]<<endl;
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <queue>
#include <vector>
#include <stack>
#include <set>
#include <map>
#include <string>
#include <cctype>
#include <cstring>

using namespace std;

int main()
{
	string ans[3];
	for(int i=0;i<3;i++)cin>>ans[i];
	for(int i=0;i<3;i++){
		for(int j=0;j<ans[i].size();j++){
			if(!isalpha(ans[i][j])){ans[i].erase(ans[i].begin()+j);j--;}
			if(isupper(ans[i][j])){
				ans[i][j]=tolower(ans[i][j]);
			}
		}
	}
	int od[3]={
		0,1,2
	};
	int len=0;
	string tem[6];
	do{
		tem[len]="";
		for(int i=0;i<3;i++){
			tem[len]+=ans[od[i]];
		}
		len++;
	}while(next_permutation(od,od+3));
	//for(int i=0;i<6;i++)cout<<tem[i]<<endl;
	int n;
	cin>>n;
	string res[2]={
		"ACC","WA"
	};
	string s;
	for(int i=0;i<n;i++){
		cin>>s;
		bool OK=false;
		for(int j=0;j<s.size();j++){
			if(!isalpha(s[j])){s.erase(s.begin()+j);j--;}
			if(isupper(s[j]))s[j]=tolower(s[j]);
		}
		//cout<<s<<endl;
		for(int j=0;j<6;j++){
			for(int k=0;k<s.size()-tem[j].size()+1;k++){
				if(tem[j]==s.substr(k,tem[j].size())){
					OK=true;break;
				}
			}
			if(OK)break;
		}
		if(OK)cout<<res[0]<<endl;
		else cout<<res[1]<<endl;
	}
	return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include<string>

using namespace std;
typedef long long int  LLD;

LLD gcd(LLD a, LLD b)
{
   if (b==0) return a;
   return gcd(b,a%b);
}

int main()
{
    LLD i,j,k,counts=0,len,n;
    map<string,LLD> abc;

    string a,temp="s",x;

    for(i=0;i<3;i++)
    {
        cin>>a;
        //cout<<a;
        len = a.size();
        for(j=0; j<len; j++)
        {
            if(a[j] >= 'a' && a[j] <= 'z')
            temp += a[j];

            if(a[j] >= 'A' && a[j] <= 'Z')
            temp += (a[j] + 32);
        }

        x.assign(temp,1,len-1);
        abc[x] = -1;
        //cout<<x<<endl;
        temp = "s";

    }
    //cout<<temp;
    cin>>n;

    for(i=0;i<n;i++)
    {
        cin>>a;

        len = a.size();

        for(j=0; j<len; j++)
        {
            if(a[j] >= 'a' && a[j] <= 'z')
            temp += a[j];

            if(a[j] >= 'A' && a[j] <= 'Z')
            temp += a[j] + 32;

            x.assign(temp,1,j+1);
            ///cout<<temp<<endl;;
            if(abc[x] == -1)
            {
                counts++;
                abc[temp] =1;
                temp = "s";
            }
        }

        if(counts == 3)
        cout<<"ACC"<<endl;
        else
        {
            cout<<"WA"<<endl;
            temp = "s";
        }
        counts=0;
    }
return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include<string>

using namespace std;
typedef long long int  LLD;

int main()
{
    LLD i,j,k,counts=0,len,n;
    map<string,LLD> abc;

    string a,temp="s",x,str[3];

    for(i=0;i<3;i++)
    {
        cin>>a;

        len = a.size();
        for(j=0; j<len; j++)
        {
            if(a[j] >= 'a' && a[j] <= 'z')
            temp += a[j];

            if(a[j] >= 'A' && a[j] <= 'Z')
            temp += (a[j] + 32);
        }

        x.assign(temp,1,len);
        abc[x] = -1;

        str[i] = x;
        temp = "s";
    }

    cin>>n;

    for(i=0;i<n;i++)
    {
        cin>>a;

        len = a.size();

        for(j=0; j<len; j++)
        {
            if(a[j] >= 'a' && a[j] <= 'z')
            temp += a[j];

            if(a[j] >= 'A' && a[j] <= 'Z')
            temp += a[j] + 32;

            x.assign(temp,1,j+1);

            if(abc[x] == -1)
            {
                counts++;
                abc[x] =1;
                temp = "s";

            }
        }

        if(counts == 3)
        cout<<"ACC"<<endl;
        else
        {
            cout<<"WA"<<endl;
            temp = "s";
        }
        counts=0;
        abc.clear();

        for(j=0;j<3;j++)
        abc[str[j]] = -1;
          }

return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include<string>

using namespace std;
typedef long long int  LLD;

int main()
{
    LLD i,j,k,counts=0,len,n;
    map<string,LLD> abc;

    string a,temp="s",x,str[3];

    for(i=0;i<3;i++)
    {
        cin>>a;
            cout<<a<<endl;
        len = a.size();
        for(j=0; j<len; j++)
        {
            if(a[j] >= 'a' && a[j] <= 'z')
            temp += a[j];

            if(a[j] >= 'A' && a[j] <= 'Z')
            temp += (a[j] + 32);
        }

        x.assign(temp,1,len);
        abc[x] = -1;
        cout<<x<<endl;
        str[i] = x;
        temp = "s";
    }

    cin>>n;

    for(i=0;i<n;i++)
    {
        cin>>a;

        len = a.size();
        cout<<len;
        for(j=0; j<len; j++)
        {
            if(a[j] >= 'a' && a[j] <= 'z')
            temp += a[j];

            if(a[j] >= 'A' && a[j] <= 'Z')
            temp += a[j] + 32;

            x.assign(temp,1,j+1);

            if(abc[x] == -1)
            {
                counts++;
                abc[x] =1;
                temp = "s";
                cout<<x<<endl;
            }
        }

        if(counts == 3)
        cout<<"ACC"<<endl;
        else
        {
            cout<<"WA"<<endl;
            temp = "s";
        }
        counts=0;
        abc.clear();

        for(j=0;j<3;j++)
        abc[str[j]] = -1;
          }

return 0;
}


#include <iostream>
using namespace std;
int main(){
    int n, x, i, j, c, t = 0, hash[100000] = { 0 }, r = 0;
    cin >> n >> x;
    for (int i = 1; i <= n; i++){
        cin >> j;
        ++hash[j];
        if (j>r)
            r = j;
    }

    for (i = 1; i <= r ; ++i){
        for (j = hash[i]; j > 0; --j){
            if (hash[i] != 0 && x > 0){
                t += i*x;
                --x;
                c = i;
                hash[i] -= 1;
            }
        }
    }
    for (i = c; i <= r ; ++i){
        if (hash[i] != 0){
            t += hash[i] * i;
        }
    }
    cout << t << endl;
}


#include <iostream>
using namespace std;
int main(){
    int n, x, i, j, c, t = 0, hash[10000] = { 0 }, r = 0;
    cin >> n >> x;
    for (int i = 1; i <= n; i++){
        cin >> j;
        ++hash[j];
        if (j>r)
            r = j;
    }

    for (i = 1; i <= r ; ++i){
        for (j = hash[i]; j > 0; --j){
            if (hash[i] != 0 && x > 0){
                t += i*x;
                --x;
                c = i;
                hash[i] -= 1;
            }
        }
    }
    for (i = c; i <= r ; ++i){
        if (hash[i] != 0){
            t += hash[i] * i;
        }
    }
    cout << t << endl;
}


#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
	int n, x, sum = 0;
	int c[100000];
	cin >> n >> x;
	for (int i = 0; i < n; i++)
		cin >> c[i];
	sort(c, c + n);
	for (int i = 0; i < n; i++) {
		if (x > 1) {
			sum += (x * c[i]);
			x--;
		}
		else
			sum += (x * c[i]);
	}
	cout << sum;
	return  0;
}


#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
	int n, x;
	long int sum = 0;
	long int c[100000];
	cin >> n >> x;
	for (int i = 0; i < n; i++)
		cin >> c[i];
	sort(c, c + n);
	for (int i = 0; i < n; i++) {
		if (x > 1) {
			sum += (x * c[i]);
			x--;
		}
		else
			sum += (x * c[i]);
	}
	cout << sum;

	return  0;
}


#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
	long int n, x, sum = 0;
	long int c[100005];
	cin >> n >> x;
	for (int i = 0; i < n; i++)
		cin >> c[i];
	sort(c, c + n);
	for (int i = 0; i < n; i++) {
		if (x > 1) {
			sum += (x * c[i]);
			x--;
		}
		else
			sum += (x * c[i]);
	}
	cout << sum;
	return  0;
}


#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
	int n, x;
	long int sum = 0;
	long int c[100000];
	cin >> n >> x;
	for (int i = 0; i < n; i++)
		cin >> c[i];
	sort(c, c + n);
	for (int i = 0; i < n; i++) {
		if (x > 1) {
			sum += (x * c[i]);
			x--;
		}
		else
			sum += (x * c[i]);
	}
	cout << sum;
	return  0;
}


#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
	long int n, x, sum = 0;
	vector<long int> c;
	cin >> n >> x;
	c.resize(n);
	for (int i = 0; i < n; i++)
		cin >> c[i];
	sort(c.begin(), c.end());
	for (int i = 0; i < n; i++) {
		if (x > 1) {
			sum += (x * c[i]);
			x--;
		}
		else
			sum += (x * c[i]);
	}
	cout << sum;
	return  0;
}


#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
	//439B
	long long int n, x, sum = 0;
	vector<long long int> c;
	cin >> n >> x;
	c.resize(n);
	for (int i = 0; i < n; i++)
		cin >> c[i];
	sort(c.begin(), c.end());
	for (int i = 0; i < n; i++) {
		if (x > 1) {
			sum += (x * c[i]);
			x--;
		}
		else
			sum += (x * c[i]);
	}
	cout << sum;
	return  0;
}


#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
	long int n, x, sum = 0;
	long int c[100000];
	cin >> n >> x;
	for (int i = 0; i < n; i++)
		cin >> c[i];
	sort(c, c + n);
	for (int i = 0; i < n; i++) {
		if (x > 1) {
			sum += (x * c[i]);
			x--;
		}
		else
			sum += (x * c[i]);
	}
	cout << sum;
	return  0;
}


#include <iostream>
#include <algorithm>
using namespace std;

int main(){
	int n, x;
	cin >> n >> x;
	int arr[100009];
	for (int i = 0; i < n; ++i){
		cin >> arr[i];
	}

	sort(arr, arr +n);
   /* for(int i = 0; i<n; i++){
        cout << arr[i]<< " ";
    }cout <<endl;*/
	float minTime = 0;
	int time = x;
	for (int i = 0; i < n; ++i)
	{
	    //cout << minTime<< " ";
		minTime += time*arr[i];
		if(time>1) time--;
		else time = 1;
	}
	cout << minTime;

}


#include <iostream>
#include <algorithm>
using namespace std;

int main(){
	int n, x;
	cin >> n >> x;
	int arr[100009];
	for (int i = 0; i < n; ++i){
		cin >> arr[i];
	}

	sort(arr, arr +n);
   /* for(int i = 0; i<n; i++){
        cout << arr[i]<< " ";
    }cout <<endl;*/
	int minTime = 0;
	int time = x;
	for (int i = 0; i < n; ++i)
	{
	    //cout << minTime<< " ";
		minTime += time*arr[i];
		if(time>1) time--;
		else time = 1;
	}
	cout << minTime;

}


#include <iostream>
#include <algorithm>
using namespace std;

int main(){
	int n;
	long long x;
	cin >> n >> x;
	long long arr[100009];
	for (int i = 0; i < n; ++i){
		cin >> arr[i];
	}

	sort(arr, arr +n);
   /* for(int i = 0; i<n; i++){
        cout << arr[i]<< " ";
    }cout <<endl;*/
	long long minTime = 0;
	long long time = x;
	for (int i = 0; i < n; ++i)
	{
	    //cout << minTime<< " ";
		minTime += time*arr[i];
		if(time>1) time--;
		else time = 1;
	}
	cout << minTime;
return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;

int main(){
	int n, x;
	cin >> n >> x;
	int arr[100009];
	for (int i = 0; i < n; ++i){
		cin >> arr[i];
	}

	sort(arr, arr +n);
    /*for(int i = 0; i<n; i++){
        cout << arr[i]<< " ";
    }*/
	int minTime = 0;
	int time = x;
	for (int i = 0; i < n; ++i)
	{
		minTime += time*arr[i];
		time--;
	}
	cout << minTime;

}


#include <iostream>
#include <algorithm>
using namespace std;

int main(){
	int n, x;
	cin >> n >> x;
	int arr[100009];
	for (int i = 0; i < n; ++i){
		cin >> arr[i];
	}

	sort(arr, arr +n);
   /* for(int i = 0; i<n; i++){
        cout << arr[i]<< " ";
    }cout <<endl;*/
	long long minTime = 0;
	int time = x;
	for (int i = 0; i < n; ++i)
	{
	    //cout << minTime<< " ";
		minTime += time*arr[i];
		if(time>1) time--;
		else time = 1;
	}
	cout << minTime;

}


#include <iostream>
#include <algorithm>
using namespace std;

int main(){
	int n, x;
	cin >> n >> x;
	int arr[100009];
	for (int i = 0; i < n; ++i){
		cin >> arr[i];
	}

	sort(arr, arr +n);
   /* for(int i = 0; i<n; i++){
        cout << arr[i]<< " ";
    }cout <<endl;*/
	long int minTime = 0;
	int time = x;
	for (int i = 0; i < n; ++i)
	{
	    //cout << minTime<< " ";
		minTime += time*arr[i];
		if(time>1) time--;
		else time = 1;
	}
	cout << minTime;

}


#include<iostream>
#include<algorithm>
using namespace std;
int arr[100001];
int main(){
    int n,x;
    cin>>n>>x;
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    sort(arr,arr+n);
    unsigned long long int sum=0;
    for(int i=0;i<n;i++){
        sum+=arr[i]*x;
        if(x>1) x--;
    }
    cout<<sum<<endl;
    //system("pause");
}


#include<iostream>
#include<algorithm>
using namespace std;
int arr[100000];
int main(){
    long long int n,x;
    cin>>n>>x;
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    sort(arr,arr+n);
    unsigned long long int sum=0;
    for(int i=0;i<n;i++){
        sum+=arr[i]*x;
        if(x>1) x--;
    }
    cout<<sum<<endl;
    //system("pause");
}


#include<iostream>
#include<algorithm>
using namespace std;
int arr[100000];
int main(){
    int n,x;
    cin>>n>>x;
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    sort(arr,arr+n);
    unsigned long long int sum=0;
    for(int i=0;i<n;i++){
        sum+=arr[i]*x(long long int);
        if(x>1) x--;
    }
    cout<<sum<<endl;
    //system("pause");
}


#include<iostream>
#include<algorithm>
using namespace std;
int arr[100000];
int main(){
    int n,x;
    cin>>n>>x;
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    sort(arr,arr+n);
    long long int sum=0;
    for(int i=0;i<n;i++){
        sum+=arr[i]*x;
        if(x>1) x--;
    }
    cout<<sum<<endl;
    //system("pause");
}


#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <algorithm>

using namespace std;

int main() {
	int n, x;
	cin >> n >> x;
	vector<int> a(n);
	for (int i = 0; i < n; i++)
		cin >> a[i];
	sort(a.begin(), a.end());
	int sum = 0;
	for (int i = 0; i < n; i++) {
		if (x < 1) x = 1;
		sum += a[i] * x--;
	}
	cout << sum;
//	system("pause");
	return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <algorithm>

using namespace std;

int main() {
	int n, x;
	cin >> n >> x;
	vector<int> a(n);
	for (int i = 0; i < n; i++)
		cin >> a[i];
	sort(a.begin(), a.end());
	long long sum = 0;
	for (int i = 0; i < n; i++) {
		sum += a[i] * x;
		if (x > 1) x--;
	}
	cout << sum;
//	system("pause");
	return 0;
}