#include<bits/stdc++.h>
#define ri register int
#define ll long long
#define rll register ll
#define ull unsigned ll
#define fo(i,x,y) for(ri i=(x);i<=(y);++i)
#define fu(i,x,y) for(ri i=(x);i<(y);++i)
#define fd(i,x,y) for(ri i=(x);i>=(y);--i)
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
using namespace std;
const int N=1e5+5,p=1e9+7;
int T,n,m,v,f[N][2];
struct nd{
	int w,v;
	inline int operator==(const nd &x){
		return w==x.w&&v==x.v;
	}
}a[N];
inline int ksm(ri x,ri y){
	ri sm=1;
	if(y<0)return 1;
	for(;y;y>>=1,x=1ll*x*x%p)
	if(y&1)sm=1ll*sm*x%p;
	return sm;
}
inline int calc(ri x){
	if(x<0)return 0;
	if(x==0)return 1;
	ri s=(ksm(v,x+1)-1+p)%p;
	s=1ll*s*ksm(v-1,p-2)%p;
	return s;
}
inline int get(ri x){
	ri s=(calc(2*x-1)-calc(x-1)+p)%p;
	s=1ll*s*(v-1)%p;
	(s+=ksm(v,x-1))%=p;
	return s;
}
int main(){
	freopen("assign.in","r",stdin);
//	freopen("assign3.in","r",stdin);
	freopen("assign.out","w",stdout);
	scanf("%d",&T);
	while(T--){
		scanf("%d%d%d",&n,&m,&v);
		fo(i,1,m)scanf("%d%d",&a[i].w,&a[i].v);
		sort(a+1,a+1+m,[&](nd x,nd y){return x.w<y.w;});
		ri pd=0;
		fu(i,1,m)if(a[i].w==a[i+1].w&&a[i].v!=a[i+1].v)pd=1;
		if(pd){puts("0");continue;}
		m=unique(a+1,a+1+m)-a-1;
		ri o=ksm(v,2*(a[1].w-1));
		if(a[1].w==n){
			printf("%d\n",o);
			continue;
		}
		f[1][0]=1ll*v*(v-1)%p*o%p;
		f[1][1]=1ll*o*(a[2].w==a[1].w+1?1:v)%p;
		fo(i,2,m){
			ri x=a[i].w-a[i-1].w-1;
			ri y=get(x);if(!x)y=1;
			o=(1ll*f[i-1][0]*ksm(v,2*x)%p+1ll*f[i-1][1]*y%p)%p;
			if(a[i].w==n){
				f[i][0]=o;
				f[i][1]=0;
				break;
			}
			f[i][0]=1ll*v*(v-1)%p*o%p;
			f[i][1]=1ll*(a[i+1].w==a[i].w+1?1:v)*o%p;
		}
		ri x=n-a[m].w-1;
		ri s1=ksm(v,2*x),s2=((get(x)-ksm(v,x-1)+p)%p+ksm(v,x))%p;
		ri ans=(1ll*s1*f[m][0]%p+1ll*s2*f[m][1]%p)%p;
		printf("%d\n",ans);
	}
}
