#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod=(ll)1e9+7;
ll n,m,k,z,x,s,v,ls,ans,sum;
int tz;
bool bz;
struct node{
	ll c,d;
	node(){
		c=0,d=0;
	}
}a[100005];
bool cmp(node aa,node bb){
	return (aa.c<bb.c);
}
long long read(){
	char ch=getchar();
	long long ip=1,xx=0;
	while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
	if(ch=='-'){
		ip=-1,ch=getchar();
		while(ch<'0'||ch>'9') ch=getchar();
	}
	while(ch>='0'&&ch<='9')
		xx=xx*10+ch-'0',ch=getchar();
	return xx*ip;
}
ll mi(ll xx,ll ci){
	if(ci==0) return 1;
	if(ci==1) return xx;
	ll po=mi(xx,ci/2);
	po=po*po%mod;
	if(ci%2==1) po=po*xx%mod;
	return po;
}
int main(){
	//assign
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	tz=read();
	while(tz--){
		bz=0,ans=0;
		n=read(),m=read(),v=read();
		for(int i=1;i<=m;i++){
			a[i].c=read(),a[i].d=read();
		}
		sort(a+1,a+m+1,cmp);
		ls=1;
		for(int i=2;i<=m;i++){
			if(a[i].c!=a[ls].c)
				ls++,a[ls]=a[i];
			else if(a[i].d!=a[ls].d){
				printf("0\n");
				bz=1;
				break;
			}	
		}
		m=ls,ls=mi(v,2*a[1].c-2),n--;
		if(bz==1) continue;
		for(int i=1;i<m;i++){
			sum=mi(v,a[i+1].c-a[i].c-1)*(v-1)%mod;
			ans=(ans+ls*sum%mod*mi(v,2*(n-a[i+1].c+1))%mod)%mod;
			ls=ls*(mi(v,2*(a[i+1].c-a[i].c))-sum+mod)%mod;
		}
		ans=(mi(v,2*n)-ans+mod)%mod;
		printf("%lld\n",ans);
	}
	return 0;
}
