#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define N 100005 
#define F first
#define S second
typedef pair<ll,ll> pll;
ll n,T,m,v,ans,a[N],dp[N]; 
map<ll,ll> mp;
const ll mod=1000000007;
inline ll qpow(ll a,ll b,ll res=1){
	if(b<=0) return 1ll;
	b%=mod;
	while(b){
		if(b&1) res=res*a%mod;
		a=a*a%mod,b>>=1;
	} return res;
}
int main(){
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	scanf("%lld",&T);
	while(T--){
		mp.clear();
		bool f=1;
		scanf("%lld%lld%lld",&n,&m,&v);
		for(ll i=1,x;i<=m;i++){
			scanf("%lld%lld",&a[i],&x);
			if(mp[a[i]]!=0&&mp[a[i]]!=x) f=0;
			mp[a[i]]=x;
		}
		if(!f){printf("0\n");continue;}
		sort(a+1,a+m+1);
		m=unique(a+1,a+m+1)-a-1;
		for(ll i=0;i<=m;i++) dp[i]=0;
		dp[1]=qpow(v*v%mod,a[1]-1);
		for(ll i=2;i<=m;i++){
			dp[i]=dp[i-1]*((qpow(v,2*(a[i]-a[i-1]))-qpow(v,a[i]-a[i-1]-1)*(v-1)%mod+mod)%mod)%mod;
		}
		printf("%lld\n",(dp[m])*qpow(v*v%mod,n-a[m])%mod);
	}
	return 0;
}
