long int kruskal(int m, vector<triple> &arestas){

	DisjointSet<int> *ds = new DisjointSet<int>(m);
	// vector<ii> result;
	long int t = 0;

	for(int i=0; i<m; i++)
		ds->make(i, 0);

	sort(arestas.begin(), arestas.end());

	int e = 0, i = 0;
	while(e < m-1){

		int u = ds->find(arestas[i].first);
		int v = ds->find(arestas[i].second);

		if(ds->find(u) != ds->find(v)){
			t += arestas[i].third;
			// result.push_back(ii(u, v));
			ds->join(u, v);
			e++;
		}

		i++;
	}

	return t;
}
int main(){

    DisjointSet graph;
    int t,a,b,n,k;
    char opc;

    scanf("%d",&t);

    for(int u=1;u<=t;u++){

        scanf("%d %d",&n,&k);

        graph.init(n);
        fill( pareja , pareja + n , -1 );

        for(int i=0;i<n;i++){
            scanf("%d",&a);
            if(a==0 || a-1==i) continue;
            a--;
            pareja[i] = a;
        }

        vector<pii> query;
        vector<pii> otro;

        while(k--){
            scanf("\n%c",&opc);

            if(opc=='C'){
                scanf("%d",&a);
                //printf("%c %d\n",opc,a);
                a--;
                b = pareja[a];
                if(b==-1) continue;
                pareja[a] = -1;
                query.push_back( pii( a , -1 ) );
                otro.push_back( pii( a , b ) );
            }
            else{
                scanf("%d %d",&a,&b);
                //printf("%c %d %d\n",opc,a,b);
                a--,b--;
                query.push_back( pii( a , b ) );
            }
        }

        for(int i=0;i<n;i++)
            if(pareja[i]!=-1)
                graph.join( i , pareja[i] );

        vector<string> res;
        int j = otro.size() - 1;

        for(int i=query.size()-1;i>=0;i--){
            if(query[i].second!=-1){
                if( graph.joined( query[i].second , query[i].first ) )
                    res.push_back("YES\n");
                else res.push_back("NO\n");
            }
            else{
                graph.join( otro[j].first , otro[j].second );
                j--;
            }
        }

        printf("Case #%d:\n",u);
        for(int i=res.size()-1;i>=0;i--)
            printf("%s",res[i].c_str());
    }
    return 0;
}