#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1e5+10,mod = 1e9+7;
int c[N],d[N];
int x[N],t[N];
int n,m,v,T,ans;
signed main(){
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	scanf("%lld",&T);
	while(T--){
		bool flag=0;
		scanf("%lld%lld%lld",&n,&m,&v);
		for(int i=0;i<=v;i++) x[i]=-1,t[i]=-1;
		for(int i=1;i<=m;i++){
			scanf("%lld%lld",&c[i],&d[i]);
			if(t[c[i]]!=-1&&t[c[i]]!=d[i]){
				printf("0\n");
				flag=1;
			}
			x[c[i]]=d[i];
			t[c[i]]=d[i];
		}
		if(flag) continue;
		ans=0;
		printf("%lld\n",ans%mod);
	}
	return 0;
}
