/**
 * @file meow-checker.cpp
 * @author Macesuted Moe (i@macesuted.moe)
 * @date 2022-11-26
 *
 * @copyright Copyright (c) 2022
 */

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

#define maxn 305
#define maxm 2000005

deque<int> que[maxn];
map<int, int> rec;
int a[maxm];

int main() {
    ifstream in("meow.in"), out("meow.out");
    int T;
    in >> T;
    while (T--) {
        rec.clear();
        int n, m, k, cnt = 0;
        in >> n >> m >> k;
        for (int i = 1; i <= m; i++) in >> a[i];
        int l;
        out >> l;
        rec[0] = n;
        for (int i = 1, j = 0; i <= l; i++) {
            int op, x, y;
            out >> op;
            if (op == 1) {
                out >> x, j++;
                rec[que[x].size()]--;
                if (!que[x].empty() && que[x].front() == a[j]) {
                    que[x].pop_front(), cnt += 2;
                }
                else {
                    que[x].push_front(a[j]);
                }
                rec[que[x].size()]++;
            } else {
                out >> x >> y;
                rec[que[x].size()]--, rec[que[y].size()]--;
                if (x == y || que[x].empty() || que[y].empty() || que[x].back() != que[y].back()) {
                    cout << "WA 1 on line " << i << ' ' << j << endl;
                    return 1;
                }
                que[x].pop_back(), que[y].pop_back(), cnt += 2;
                rec[que[x].size()]++, rec[que[y].size()]++;
            }
            if (rec[3] == 2) {
                cout << "WA 3 on line " << i << ' ' << cnt << endl;
                return 1;
            }
            if (rec[4] == 1) {
                cout << "WA 4 on line " << i << ' ' << cnt << endl;
                return 1;
            }
        }
        if (cnt != m) {
            cout << "WA 2" << endl;
            return 1;
        }
        cout << "AC" << endl;
    }
    return 0;
}
