#include<iostream>
#include<cstdio>
#include<algorithm>
#define ll long long
using namespace std;
const int mod=1e9+7;
ll qui(ll di,ll mi){
	ll res=1;
	while(mi){
		if(mi&1){
			(res*=di)%=mod;
		}
		(di*=di)%=mod;
		mi>>=1;
	}	
	return res;
}
const int MAXN=1e6+5;
int n,m;ll v;
pair<int,int>a[MAXN];
int main(){
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	int T;
	scanf("%d",&T);
	while(T--){
		scanf("%d%d%lld",&n,&m,&v);
		for(int i=1;i<=m;i++){
			scanf("%d%d",&a[i].first,&a[i].second);
		}
		sort(a+1,a+1+m);
		ll res=qui(v*v%mod,a[1].first-1);
		for(int i=2;i<=m;i++){
			if(a[i].first==a[i-1].first&&a[i].second!=a[i-1].second){
				res=0;
				break;
			}
			if(a[i].first==a[i-1].first)continue;
			(res*=qui(v*v%mod,a[i].first-a[i-1].first)-qui(v,a[i].first-a[i-1].first-1)*(v-1)%mod+mod)%=mod;
		}
		(res*=qui(v*v%mod,n-a[m].first))%=mod;
		printf("%lld\n",res);
	}
}
