#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>

#define LL long long
#define upfor(i,a,b) for(LL i=(a);i<=(b);i++)
#define dnfor(i,a,b) for(LL i=(a);i>=(b);i--)

using namespace std;

void FileIO(string file) {
	freopen((file+".in").c_str(),"r",stdin);
	freopen((file+".out").c_str(),"w",stdout);
}

LL read() {
	LL n=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9') {
		if(ch=='-') f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9') {
		n=n*10+ch-'0';
		ch=getchar();
	}
	return n*f;
}

const LL N=1e5+5;

LL c,T;
LL n,k;
bool flagA;
bool flagB;
struct Edge {
	LL u,v;
}e[N];
LL keyedge[N];

void workA() {
	printf ("1\n");
}
void workB() {
	
}

void solve() {
//	if(flagA) {
//		workA();
//		return ;
//	}
//	if(flagB) {
//		workB();
//		return ;
//	}
	printf ("1\n");
}

// ¶à²âÒªÇå¿Õ£¡£¡£¡
int main() {
	FileIO("traverse");
	c=read(),T=read();
	while(T--) {
		flagA=true;
		flagB=true;
		n=read(),k=read();
//		if(n!=m) flagA=false;
		upfor(i,1,n-1) {
			LL u=read(),v=read();
			if(u!=i||v!=u+1) {
				flagA=false;
			}
			if(u!=1||v!=i+1) {
				flagB=false;
			}
		}
		upfor(i,1,k) {
			keyedge[i]=read();
		}
		if(k==0) {
			printf ("0\n");
			continue;
		}
		solve();
	}
	return 0;
}
