#include<bits/stdc++.h>
#define LL long long
#define mod 1000000007
#define N 100005
using namespace std;
LL fpow(LL a,LL b){
	if(!b) return 1;
	LL t(fpow(a,b>>1));
	if(b&1) return t*t%mod*a%mod;
	return t*t%mod;
}
int T,n,m,v;
struct R{
	int c,d;
} r[N];
LL ans;
int main(){
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	scanf("%d",&T);
	while(T--){
		scanf("%d%d%d",&n,&m,&v);
		for(int i(1);i<=m;++i)
			scanf("%d%d",&r[i].c,&r[i].d);
		sort(r+1,r+1+m,[](const R&a,const R&b){
			return a.c<b.c;
		});
		bool flg(0);
		for(int i(2);i<=m&&!flg;++i)
			if(r[i].c==r[i-1].c&&r[i].d!=r[i-1].d)
				puts("0"),flg=1;
		if(flg) continue;
		ans=fpow(v,r[1].c-1+n-r[m].c<<1);
		for(int i(1);i<m;++i)
			if(r[i+1].c^r[i].c){
				LL t(fpow(v,r[i+1].c-r[i].c-1));
				ans=ans*(t*v%mod*(t*v%mod-1)%mod+t)%mod;
			}
		printf("%lld\n",ans);
	}
	return 0;
}
