#include<bits/stdc++.h>
#define il inline
#define pii pair<int,int>
#define fir first
#define sec second
using namespace std;
const int N=1e5+10,MOD=1e9+7;
int n,m,v,ln,ans,fg; pii p[N];
map<int,int> mp;
il int qpow(int a,int b) {
	int rs=1;
	for(;b;a=1ll*a*a%MOD,b>>=1) if(b&1) rs=1ll*rs*a%MOD;
	return rs;
}
void sol() {
	scanf("%d%d%d",&n,&m,&v),ln=0,mp.clear(),ans=fg=1;
	for(int t=m,x,y;t--;) {
		scanf("%d%d",&x,&y);
		if(mp[x]&&mp[x]!=y) fg=0; mp[x]=y;
	}
	if(!fg) return puts("0"),void();
	for(pii _p:mp) {
		if(!ln||_p.fir>p[ln].sec+1) p[++ln]={_p.fir,_p.fir};
		else p[ln].sec=_p.fir;
	}
	for(int i=1,ll,rl,lc,rc;i<=ln;i++) {
		ll=p[i-1].sec+1,rl=p[i].fir-1,lc=p[i].fir,rc=p[i].sec;
		if(i==1) ans=1ll*ans*qpow(v,(rl-ll+1)*2)%MOD;
		else ans=1ll*ans*(qpow(v,(rl-ll+2)*2)-1ll*qpow(v,rl-ll+1)*(v-1)%MOD+MOD)%MOD;
		ans=1ll*ans*qpow((1ll*v*(v-1)%MOD+1)%MOD,rc-lc)%MOD;
	}
	printf("%d\n",1ll*ans*qpow(v,(n-p[ln].sec)*2)%MOD);
}
int main() {
	freopen("assign.in","r",stdin),freopen("assign.out","w",stdout);
	int T; scanf("%d",&T); for(;T--;) sol();
}
/*
1
3 3 2
1 1
2 2
3 1


1
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

俗话说的好，大难不死，必有大难 
*/
