#include<bits/stdc++.h>
#define Pc(x) putchar(x)
#define PB push_back
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
using namespace std;using ll=long long;using ull=unsigned ll;
const int N=1e3+5,M=2e6+5,eps=1e-5,INF=1e9+7,mod=998244353;
int n,m,op,x,y,k,H,A[M];deque<int> Q[N];
int main(){
	freopen("meow.in","r",stdin);
	int T,i;scanf("%d",&T);scanf("%d%d%d",&n,&m,&k);for(i=1;i<=m;i++) scanf("%d",&A[i]);
	freopen("meow.out","r",stdin);
	scanf("%d",&H);int R=1;while(H--){
		scanf("%d%d",&op,&x);if(op==1) {
			if(!Q[x].empty()&&Q[x].back()==A[R]) Q[x].pop_back();else Q[x].push_back(A[R]);R++; 
		}else{
			scanf("%d",&y);if(!Q[x].empty()&&!Q[y].empty()&&Q[x].front()==Q[y].front()) Q[x].pop_front(),Q[y].pop_front();
		}
	}
	for(i=1;i<=n;i++) if(!Q[i].empty()){printf("%d\n",i);puts("NO");return 0;}puts("AC");
}