#include<bits/stdc++.h> 
using namespace std;
int T;
int n,m,v,flag;
int c[MAXN],d[MAXN];
int main()
{
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	cin>>T;
	while(T--)
	{
		cin>>n>>m>>v;
		flag=0;
		for(int i=1;i<=n;i++) 
		{
			cin>>c[i]>>d[i];
			if(b[c[i]])
			{
				cout<<'0'<<endl;
				flag=1;
				break;
			}
			b[c[i]]=d[i];
		}
		if(flag) continue;
		if(v<=2&&n<=12)
	}
	return 0;
}
