#include<bits/stdc++.h>
using namespace std;
#define int long long
const int mod=1e9+7;
int t,x[1000004],dp[105][105][105]; 
void deal(){
	int n,m,v;
	cin>>n>>m>>v;
	memset(x,-1,sizeof x);
	memset(dp,0,sizeof dp); 
	for(int i=1;i<=m;i++){
		int c,d;
		cin>>c>>d;
		if(x[c]!=-1&&x[c]!=d){
			cout<<0<<"\n";
			return ;
		}
		else x[c]=d;
	} 
	
}
signed main(){
	//freopen("assign.in","r",stdin);
	//freopen("assign.out","w",stdout);
	int cnt=1;
	for(int i=1;i<=100;i++)cnt=(cnt*2)%mod,cout<<cnt<<"\n";
	cin>>t;
	while(t--){
		deal();
	}
	return 0;
}
