#include<bits/stdc++.h> 
using namespace std;
const int inf=1e5+5;
int c[inf],a;
int main(){
	freopen("assign.in","r" ,stdin);
	freopen("assign.out","w",stdout);
	int t;
	cin >> t;
	while(t--){
		cin >> n >> m >> v;
		memset(c,0,sizeof(c));
		for(int i=1;i<=m;i++){
			cin >> a;
			cin >> c[a];
			if(c[a]!=0){
				cout << "0" << endl;
				ct=0;
				break; 
			}
		}
		if(ct==0){
			break;
		}
		for(int i=1;i<=n;i++){
			for(int j=1;j<=m;j++){
				for(int k=)
			}
		}
	}
	
	
	
	return 0;
} 
