#include<bits/stdc++.h>
using namespace std;
int t;
int n,m,v;
const int N=1e5+10;
int c[N],d[N],x[N];
int f[N];
const int mod=1e9+7;
template <class T>
inline void read(T& x){
	x=0;
	T f=1;
	char ch=getchar();
	while(!isdigit(ch)){
		if(ch=='-'){
			f=-1;
		}
		ch=getchar();
	}
	while(isdigit(ch)){
		x=(x<<3)+(x<<1)+ch-'0';
		ch=getchar();
	}
	x*=f;
}
struct ayin{
	int fr,to,w;
}a[N];
int main(){
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	srand(time(0));
	read(t);
	while(t--){
		read(n),read(m),read(v);
		memset(x,0,sizeof(x));
		for(int i=1;i<=m;i++){
			cin>>c[i]>>d[i];	
			x[c[i]]=d[i];
			f[c[i]]=1;
		}
		cout<<rand()%mod+1<<"\n";
	}
	return 0;
}
/*
3
2 1 2
1 1
2 2 2
1 1
2 2 
2 2 2
1 1
1 2
*/
