#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll N=1e5+5,P=1e9+7;
ll T,n,m,v;
struct xs{
	ll x,y;
	bool operator<(xs& op)const{
		return x<op.x;
	}
}c[N];
ll ksm(ll x,ll k){
	ll sum=1;
	while(k){
		if(k&1)sum=sum*x%P;
		x=x*x%P,k>>=1;
	}
	return sum;
}
ll sol(){
	cin>>n>>m>>v;
	for(int i=1;i<=m;i++){
		cin>>c[i].x>>c[i].y;
	}
	sort(c+1,c+m+1);
	ll ans=1;
	for(int i=2;i<=m;i++){
		if(c[i].x==c[i-1].x){
			if(c[i].y!=c[i-1].y)return 0;
			else continue;
		}
		if(c[i].x==c[i-1].x+1){
			(ans*=(1+(v-1)*v%P))%=P;
		}else{
			(ans*=(ksm(v*v%P,c[i].x-c[i-1].x)-ksm(v,c[i].x-c[i-1].x-1)*(v-1)%P+P)%P)%=P;
		}
	}
	(ans*=ksm(v*v%P,n-c[m].x))%=P;
	(ans*=ksm(v*v%P,c[1].x-1))%=P;
	return ans;
}
int main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	freopen("assign.in","r",stdin),freopen("assign.out","w",stdout);
	cin>>T;
	while(T--)cout<<sol()<<'\n';
}
