#include<cstdio>
#include<iostream>
#include<algorithm>
#define K 1000000007
#define N 100005
#define ll long long
using namespace std;
int t,n,m,ok,a,b;
long long v,ans;
pair <int,int> lim[N];
ll ksm(ll b,ll p){
	ll ans2=1;
	while(p){
		if(p&1) ans2=ans2*b%K;
		b=b*b%K,p>>=1;
	}
	return ans2;
}
int main(){
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	scanf("%d",&t);
	while(t--){
		scanf("%d%d%lld",&n,&m,&v);
		for(int i=1;i<=m;i++) scanf("%d%d",&lim[i].first,&lim[i].second);
		sort(lim+1,lim+m+1);
		ok=1;
		for(int i=2;i<=m;i++){
			if(lim[i].first == lim[i-1].first && lim[i].second != lim[i-1].second){
				ok=0;
				break;
			}
		}
		if(!ok){
			printf("0\n");
			continue;
		}
		if(lim[1].first != 1) ans=ksm((ll)v*v%K,(lim[1].first-1));
		else ans=1;
		for(int i=2;i<=m;i++){
			if(lim[i].first != lim[i-1].first){
				a=lim[i-1].first,b=lim[i].first;
				ans=ans*(ksm((ll)v*v%K,(b-a))-(ll)ksm(v,b-a-1)*(v-1)%K+K)%K;
			}
		}
		if(lim[m].first != n) ans=ans*ksm((ll)v*v%K,n-lim[m].first)%K;
		printf("%lld\n",ans);
	}
	return 0;
}
