#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define M 100005
#define mod 1000000007

ll qpow(ll a,ll b,ll p=mod){
	ll e=1;
	while(b){
		if(b&1) e=e*a%p;
		a=a*a%p;
		b>>=1;
	}
	return e;
}

int T;
int m;
ll n,v;
struct node{
	ll c,d;
	
	bool operator == (const node &z) const {return c==z.c && d==z.d;}
}p[M];

bool cmp(node a,node b){
	return a.c==b.c?a.d<b.d:a.c<b.c;
}

//int tot;

void work(){
//	printf("################# %d ################\n",++tot);
	scanf("%lld %d %lld",&n,&m,&v);
	for(int i=1;i<=m;++i){
		ll c,d;
		scanf("%lld %lld",&c,&d);
		p[i]=(node){c,d};
	}
	stable_sort(p+1,p+1+m,cmp);
	m=unique(p+1,p+1+m)-p-1;
//	for(int i=1;i<=m;++i) printf("%d %d\n",p[i].c,p[i].d);
	for(int i=1;i<m;++i) if(p[i].c==p[i+1].c) return printf("0\n"),void();
	ll res=qpow(v*v%mod,p[1].c-1);
//	printf("%lld ",res);
	for(int i=2;i<=m;++i){
		if(p[i].c==p[i-1].c+1) res=res*(1+v*(v-1)%mod)%mod;
		else res=res*(qpow(v*v%mod,p[i].c-p[i-1].c)-qpow(v,p[i].c-p[i-1].c-1)*(v-1)%mod+mod)%mod;
//		printf("%lld ",res);
	}
	res=res*qpow(v*v%mod,n-p[m].c)%mod;
	printf("%lld\n",res);
}

int main(){
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	scanf("%d",&T);
	while(T--) work();
	return 0;
}
