#include <bits/stdc++.h>
std::ifstream fin("meow.in");
std::ifstream sol("meow.out");
int n, m, k, a[200001];
std::deque<int> q[301];
int main() {
  int T;
  fin >> T;
  while (T--) {
    fin >> n >> m >> k;
    for (int i = 1; i <= m; i++) fin >> a[i];
    for (int i = 1; i <= n; i++) q[i].clear();
    int op, c = 1;
    sol >> op;
    while (op--) {
      int o, x, y;
      sol >> o >> x;
      if (o == 2) sol >> y;
      if (o == 1) {
        if (q[x].empty() || a[c] != q[x].back())
          q[x].emplace_back(a[c]);
        else
          q[x].pop_back();
        c++;
      } else {
        if (q[x].empty() || q[y].empty() || q[x].front() != q[y].front())
          assert(false);
        q[x].pop_front();
        q[y].pop_front();
      }
    }
    for (int i = 1; i <= n; i++)
      if (!q[i].empty()) assert(false);
  }
  std::cout << "AC!\n";
  return 0;
}