#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
inline int read(){
	int x=0; int flg=0; char ch=getchar();
	while(ch<'0' || ch>'9'){if(ch=='-') flg=1; ch=getchar();}
	while(ch>='0' && ch<='9') x=(x<<3)+(x<<1)+ch-48,ch=getchar();
	if(flg) return ~(x-1); return x;
}

inline void write(int x){
	int s[20]; int cnt=0;
	if(x<0) putchar('-'),x=~(x-1);
	while(x) s[++cnt]=x%10,x/=10;
	if(!cnt) cnt++;
	while(cnt) putchar(s[cnt--]+'0');
	putchar(' ');
}

const int N=1e5+5,mod=1e9+7;
struct node{
	int i,x;
	bool operator<(node a){return i<a.i;}
}a[N];
int t,n,m,v;
int flg;
ll ans;

void init(){
	flg=1;
	sort(a+1,a+n+1);
	int l=1,r=1;
	while(r<=n){
		if(a[r+1].i==a[r].i){
			if(a[r+1].x!=a[r].x){flg=0; return;}
			
		}
	}
}

int main(){
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	t=read();
	while(t--){
		n=read(),m=read(),v=read(),ans=0;
		for(int i=1; i<=m; i++) a[i].i=read(),a[i].x=read();
		init();
		puts("0");
		
	}
	return 0;
}
