#include<bits/stdc++.h>
const int N=1e5+10;
const int mod=1e9+7;
using namespace std;
typedef long long ll;
bool debug1;
int t,n,m,v,c,d,flag1,tot;
int a[N];
ll f1,f2;
bool debug2;
int main()
{
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
//	cout<<((&debug2-&debug1)/1024.0/1024.0)<<endl;
	scanf("%d",&t);
	for(int j=1;j<=t;j++){
		scanf("%d%d%d",&n,&m,&v);
		flag1=1;
		memset(a,0,sizeof(a));
		for(int i=1;i<=m;i++){
			scanf("%d%d",&c,&d);
			if(c>=1e5)
				continue;
			if(a[c])
				flag1=0;
			a[c]=d;
		}
		if(!flag1)
			continue;
		if(m==n){
			f1=1;
			for(int i=1;i<n;i++){
				f2=(1+1ll*(v-1)*v)%mod;
				f2=(1ll*f1*f2)%mod;
				f1=f2;
			}
			printf("%lld\n",f2);
		}
	}
	return 0;
}

