#include<bits/stdc++.h>
using namespace std;

const int M = 1e5+5, mod = 1e9+7;
int t, n, m, v;
long long ans, q, x;
bool f;
struct xz{
	int c, d;
}z[M];
bool cmp(xz a, xz b){
	return a.c<b.c;
}
long long qpow(long long x, int d){
	long long m=x, ans=1;
	while(d){
		if(d&1)ans=ans*m%mod;
		m=m*m%mod;
		d>>=1;
	}
	return 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", &z[i].c, &z[i].d);
		sort(z+1, z+m+1, cmp);
		ans=1;
		f=true;
		q=0;
		for(int i=1; i<=m; i++){
			ans=ans*qpow((long long)v*v%mod, z[i].c-z[i-1].c-1)%mod;
			if(v==2){
				q=q*qpow(2, z[i].c-z[i-1].c-1)%mod;
				ans=(ans+mod-q)%mod;
			}
			while(z[i].c==z[i+1].c){
				if(z[i].d!=z[i+1].d){
					f=false;
					break;
				}
				i++;
			}
			if(!f)break;
			q=ans;
			x=(long long)v*v%mod;
			if(v!=2 && z[i+1].c==z[i].c+1)x=(x+mod-v+1)%mod;
			if(z[i].c!=n)ans=ans*x%mod;
		}
		if(z[m].c!=n)ans=ans*qpow((long long)v*v%mod, n-1-z[m].c)%mod;
		if(f)printf("%lld\n", ans);
		else puts("0");
	}
	
	return 0;
}
