#include<bits/stdc++.h>
#define rep(i,a,n) for(int i=(a);i<=(n);++i)
#define per(i,a,n) for(int i=(n);i>=(a);--i)
#define SZ(x) ((int)(x.size()))

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

const int maxn=1e5+10,mod=1e9+7;

template<typename T>
inline void rd(T &x){
	x=0;
	bool w=false;
	char ch=getchar();
	while(!isdigit(ch)){
		w|=ch=='-';
		ch=getchar();
	} 
	while(isdigit(ch)){
		x=x*10+ch-'0';
		ch=getchar();
	}
	if(w) x=-x;
}

int n,m,v;
pii a[maxn];
ll res,f[maxn][2];

inline ll qpow(ll a,ll b){
	ll t=1;
	while(b){
		if(b&1) t=t*a%mod;
		a=a*a%mod;
		b>>=1; 
	}
	return t;
}

inline void solve(){
	rd(n); rd(m); rd(v);
	rep(i,1,m){
		rd(a[i].first);
		rd(a[i].second);
	}
	sort(a+1,a+1+m);
	rep(i,1,m){
		if(a[i].first==a[i-1].first && a[i].second!=a[i-1].second){
			printf("0\n");
			return;
		}
	}
	m=unique(a+1,a+1+m)-a-1;
	f[0][0]=1;
	rep(i,1,m){
		f[i][0]=f[i-1][0]*(v-1)%mod*v%mod;
		f[i][1]=(f[i-1][0]+f[i-1][1])%mod;
	}
	int cnt=0;
	res=1;
	rep(i,1,m){
		int j=i;
		while(j+1<=m && a[j].first+1==a[j+1].first) j++;
		int len=j-i+1;
		if(a[j].first==n){
			res=res*((f[len-1][0]+f[len-1][1])%mod)%mod;
			cnt--;
		}
		else{
			if(a[j].first+1==n){
				res=res*((f[len][0]+f[len][1]*v%mod)%mod)%mod;
			}
			else{
				ll t=0;
//				printf("%d %lld %lld\n",len,f[len][0],f[len][1]);
				t+=f[len][0]*v%mod*v%mod; t%=mod;
				t+=f[len][1]*v%mod*v%mod*v%mod; t%=mod;
				res=res*t%mod;
				
			}
		}
		cnt++;
		i=j;
	}
	if(!(a[m].first==n || a[m].first==n-1)){
		cnt++;
	}
	printf("%lld\n",res*qpow(1ll*v*v%mod,n-m-cnt)%mod);
}

signed main(){
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	int _=1;
	rd(_);
	while(_--) solve();
}

