#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e9+5,M=1e5+5,mod=1e9+7;
long long pow1(int a,int b){
	int sum=1,k=a;
	while(b){
		if(b&1) sum=sum*k%mod;
		k=k*k%mod;
		b>>=1;
	}
	return sum;
}
struct P{
	int i,v;
	bool operator <(const P &x) const{
		return i<x.i;
	}
}op[M];
int t,n,m,v,ans;
signed main()
{
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	scanf("%lld",&t);
	while(t--){
		scanf("%lld%lld%lld",&n,&m,&v);
		for(int i=1;i<=m;i++) scanf("%lld%lld",&op[i].i,&op[i].v);
		sort(op+1,op+1+m);
		bool flag=1;
		ans=pow1(v*v%mod,(op[1].i-1))%mod;
		for(int i=1;i<m;i++){
			if(op[i+1].i==op[i].i && op[i+1].v==op[i].v) continue;
			if(op[i+1].i==op[i].i){
				flag=0;
				break;
			}
			ans=ans*(pow1(v*v%mod,op[i+1].i-op[i].i)-pow1(v,op[i+1].i-op[i].i)+pow1(v,op[i+1].i-op[i].i-1)+mod)%mod;
		}
		ans=ans*pow1(v*v%mod,n-op[m].i)%mod;
		if(!flag) printf("0\n");
		else printf("%lld\n",ans);
	}
	return 0;
}

