#include <bits/stdc++.h>
using namespace std;
ifstream inf("meow.in"), ouf("meow.out");
int n, m, k;
vector <int> sta[610];
void rmain() {
    inf >> n >> m >> k;
    int cnt;
    ouf >> cnt;
    while (cnt--) {
        int type;
        ouf >> type;
        if (type == 1) {
            int x, p;
            inf >> x;
            ouf >> p;
            if (p < 1 || p > n) puts("WA1"), exit(1);
            if (sta[p].size() && sta[p].back() == x) sta[p].pop_back();
            else sta[p].push_back(x);
            m--;
        }
        else {
            int x, y;
            ouf >> x >> y;
            if (sta[x].empty() || sta[y].empty() || sta[x].front() != sta[y].front())
                puts("WA2"), exit(1);
            sta[x].erase(sta[x].begin());
            sta[y].erase(sta[y].begin());
        }
    }
    for (int i = 1; i <= n; i++) if (sta[i].size()) puts("WA3"), exit(1);
    if (m) puts("WA4"), exit(-1);
}
int main() {
    int T;
    inf >> T;
    while (T--) rmain();
    puts("AC");
}