#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=1e5+5,mod=1e9+7;
struct node{
	int c,d;
}s[N];
bool cmp(node a,node b){return a.c==b.c?a.d<b.d:a.c<b.c;}
int fpow(int a,int x){
	int res=1;
	while(x){
		if(x&1)res=res*a%mod;
		a=a*a%mod;
		x>>=1;
	}
	return res;
}
int js[N];
signed main(){
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	int T;cin>>T;
	while(T--){
		int n,m,v;
		scanf("%lld%lld%lld",&n,&m,&v);
		int v2=v*v%mod,inv=fpow(v,mod-2);
		for(int i=1; i<=m; i++)scanf("%lld%lld",&s[i].c,&s[i].d);
		sort(s+1,s+1+m,cmp);
		int ans=fpow(v2,n-1),ans2=0,d2=1;
		for(int i=2; i<=m; i++){
			if(s[i].c==s[i-1].c){
				if(s[i].d!=s[i-1].d){ans=0;break;}
				continue;
			}
			int d=s[i].c-s[i-1].c-1;
			if(s[i].c==n)d2=fpow(v2,s[i-1].c-1)*fpow(v,n-s[i-1].c)%mod*inv%mod;
			else d2=fpow(v2,n-d-1)*fpow(v,d+1)%mod*(v2-v+1);
			ans2=(ans2+d2)%mod;
//			cout<<d2<<"\n";
		}
		printf("%lld\n",(ans-ans2+mod)%mod);
	}
	return 0;
}
/*
10 11 2
10 2
7 2
7 2
2 2
3 2
4 2
10 2
7 2
10 2
3 2
3 2
*/
