#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int M=1e5+1,mod=1e9+7;
int T;
ll n,m,v;
ll c[M],d[M];
bool fA=1,fB=1;
void getfla(){
	scanf("%lld%lld%lld",&n,&m,&v);
	if(n!=m)fA=0;
	for(int i=1;i<=m;++i){
		scanf("%d%d",&c[i],&d[i]);
		if(c[i]!=i)fA=0;
		if(d[i]!=1)fB=0;
	}
}
void taskA(){
	
}
void taskB(){
	
}
ll ans=0;
void baoli(){
	
}
int main(){
	srand(time(0));
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	scanf("%d",&T);
	while(T--){
		getfla();
//		if(fA){
//			taskA();
//		}else if(fB){
//			taskB();
//		}
		printf("%d\n",rand()%mod);
	}
	return 0;
}

