#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll mod=1000000007;
int m;
ll n,ans,v;
struct node{
	ll x,y;
}e[100005];
bool cmp(node a,node b){
	return a.x<b.x;
}
ll ksm(ll a,ll b){
	ll ret=1;
	while(b){
		if(b&1) ret=ret*a%mod;
		a=a*a%mod;
		b=(b>>1);
	}
	return ret;
}
int main(){
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	int T;
	scanf("%d",&T);
	while(T--){
		scanf("%d%d%d",&n,&m,&v);
		for(int i=1,x,y;i<=m;i++) scanf("%d%d",&e[i].x,&e[i].y);
		sort(e+1,e+m+1,cmp);
		bool flag=true;
		for(int i=1;i<m;i++){
			if(e[i].x==e[i+1].x&&e[i].y!=e[i+1].y){
				flag=false;
				break;
			}
		}
		if(!flag){
			printf("0\n");
			continue;
		}
		ans=ksm(v,2*e[1].x-2);
		for(int i=2;i<=m;i++){
			if(e[i].x==e[i-1].x) continue;
			ll t1=(ksm(v,2*(e[i].x-e[i-1].x))-ksm(v,e[i].x-e[i-1].x-1)*(v-1)%mod+mod)%mod;
			ans=ans*t1%mod;
		}
		ans=ans*ksm(v,2*(n-e[m].x))%mod;
		printf("%lld\n",ans);
	}
}
