#include<iostream>
#include<cstdio>
#include<algorithm>
#define int long long
using namespace std;

const int N = 1e5+5;
const int mod = 1e9+7;

struct node{
	int c,w;
}q[N];
int n,m,v,T,f[2][2],flg,top,tag[2];

bool cmp(node a,node b){
	if(a.c==b.c)return a.w<b.w;
	return a.c<b.c;
}

signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	cin>>T;
	while(T--){
		flg=0;
		top=1;
		cin>>n>>m>>v;
		for(int i=1;i<=m;i++){
			cin>>q[i].c>>q[i].w;
		}
		sort(q+1,q+m+1,cmp);
		for(int i=1;i<m;i++){
			if(q[i].c==q[i+1].c&&q[i].w!=q[i+1].w){
				cout<<"0\n";
				flg=1;
				break;
			}
		}
		if(flg){
			continue;
		}
		if(n==1){
			cout<<"1\n";
			continue;
		}
		f[1][0]=1;
		f[1][1]=0;
		tag[1]=v;
		while(top<=m&&q[top].c==1){
			top++;
			tag[1]=1;
			f[1][0]=0;
			f[1][1]=1;
		}
//		cerr<<"kk:"<<T<<' '<<f[1]<<"\n";
		int i,p;
		for(int j=2;j<=n;j++){
			i=j&1;
			tag[i]=v;
			while(top<=m&&q[top].c==j){
//				cerr<<j<<'\n';
				top++;
				tag[i]=1;
			}
			p=f[i^1][0]+f[i^1][1];
			p%=mod;
			f[i][0]=((p*v%mod)*v)%mod;
			f[i][1]=0;
			if(tag[i]==1)f[i][0]=0;
			if(tag[i]==1)f[i][1]=(((f[i^1][1])*(v-1)%mod)*v+((f[i^1][0])*v%mod)*v+f[i^1][1])%mod;
		}
//		cerr<<(n&1)<<' '<<f[n&1]<<' '<<tag[n&1]<<"\n";
		cout<<(f[n&1][1]+f[n&1][0])%mod<<'\n';
	}
	return 0;
}
