#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod=1e9+7;
const int M=100005;
int T,n,m,v;
struct node{
	int c,d;
}nd[M];
bool exi;
bool cmp(node x,node y){
	return x.c<y.c;
}
ll qpow(ll x,ll y){
	ll res=1;
	while(y){
		if(y&1) res=res*x%mod;
		x=x*x%mod;y>>=1;
	}
	return res;
}
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",&nd[i].c,&nd[i].d);
		sort(nd+1,nd+m+1,cmp);
		exi=1;
		for(int i=1;i<=m;i++)
			if(nd[i].c==nd[i-1].c&&nd[i].d!=nd[i-1].d)
				exi=0;
		if(!exi){
			printf("0\n");
			continue;
		}
		ans=qpow(v,2*(nd[1].c-1));
		for(int i=2;i<=m;i++){
			if(nd[i].c==nd[i-1].c) continue;
			ans=ans*(qpow(v,2*(nd[i].c-nd[i-1].c))-qpow(v,nd[i].c-nd[i-1].c-1)*(v-1)%mod+mod)%mod;
		}
		ans=ans*qpow(v,2*(n-nd[m].c))%mod;
		printf("%lld\n",ans);
	}
	fclose(stdin);
	fclose(stdout);
	return 0;
} 
