#include<bits/stdc++.h>
using namespace std;
long long A[15],B[15],xxk[100005];
const int MOD=1e9+7;
pair<long long,long long> lmtt[100005];
long long poww(long long x,long long y){
	if (y==0) return 1;
	long long divv=poww(x,y/2)%MOD;
	if (y%2) {
		return ((divv%MOD)*(divv%MOD)%MOD*x)%MOD;
	}
	return (divv%MOD)*divv%MOD;
}
bool checck(int n,int m,int v){
	int i,j,k;
	for(i=1;i<n;i++)
	  if (xxk[i]==A[i]&&(xxk[i+1]!=B[i]&&xxk[i+1]!=-1)) return 0;
	return 1;
}
void solve(){
	memset(xxk,-1,sizeof xxk);
	long long n,m,i,j,k,v;
	long long tms1=0,tms2=0;
	scanf("%lld%lld%lld",&n,&m,&v);
	for(i=1;i<=m;i++) scanf("%lld%lld",&lmtt[i].first,&lmtt[i].second);
	sort(lmtt+1,lmtt+m+1);
	lmtt[0]={1,lmtt[1].second};
	for(i=1;i<=m;i++){
		if (lmtt[i].first==lmtt[i-1].first&&lmtt[i].second!=lmtt[i-1].second){
			printf("0\n");
			return;
		}
		if (lmtt[i].first==lmtt[i-1].first+1) {
			tms2++;
	//		printf("tms2+=1\n");
		}
		else{
	//		printf("tms1+=%lld\n",lmtt[i].first-lmtt[i-1].first);
			tms1+=(lmtt[i].first-lmtt[i-1].first);
		}
	}
//	printf("aft tms1=%lld\n",tms1);
	if (lmtt[m].first!=n) tms1+=(n-lmtt[m].first);
	int kun1=(v%MOD)*(v%MOD)%MOD,kun2=(v*v-v+1)%MOD;
//	printf("%lld^%lld * %lld^%lld = %lld\n",kun1,tms1,kun2,tms2,(poww(kun1,tms1)*poww(kun2,tms2))%MOD);
	printf("%lld\n",(poww(kun1,tms1)*poww(kun2,tms2))%MOD);
}
int main(){
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	long long t;
	scanf("%lld",&t);
	while(t--) solve();
	fclose(stdin);
	fclose(stdout);
	return 0;
}
