#include<bits/stdc++.h>
#define int long long
#define fi first
#define se second
using namespace std;
const int mod=1e9+7;
int t;
int n,m,v,c,d;
vector<pair<int,int> >vc;
int ans,ct1,s1;
int fl;
int qp(int b,int e){
	int res=1;
	while(e){
		if(e&1)res=res*b%mod;
		b=b*b%mod;
		e>>=1;
	}
	return res;
}
signed main(){
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	cin>>t;
	while(t--){
		cin>>n>>m>>v;
		vc.clear();
		ans=1;
		s1=v*v%mod;
		for(int i=1;i<=m;i++){
			cin>>c>>d;
			vc.push_back({c,d});
		}
		fl=0;
		ct1=1;
		sort(vc.begin(),vc.end());
		for(int i=0;i<vc.size();i++){
			ct1=1;
			c=vc[i].fi;
			d=vc[i].se;
//			cout<<c<<" "<<d<<" ";
			if(i!=0){
				if(c==vc[i-1].fi){
					if(d!=vc[i-1].se){
						fl=1;
						break;
					}else{
						continue;
					}
				}
			}
			if(c==vc[vc.size()-1].fi){
				ans=ans*qp(s1,n-c)%mod;
			}
			if(i==0){
				if(c==1)continue;
				ans=ans*qp(s1,c-1)%mod;
			}
			if(i!=0){
				int c1=vc[i-1].fi;
				ct1=(qp(s1,c-c1)-qp(v,c-c1-1)*(v-1)%mod+mod)%mod;
				ans=ans*ct1%mod;
			}
//			cout<<ans<<" "<<s1<<" "<<s2;
		}
		if(fl){
			cout<<"0\n";
		}else{
			cout<<ans<<"\n";
		}
	}
}
//10:00 pass xingzhiA
//10:15 find zuofa wrong 
//10:19 many WAs
//10:26 find zuofa wrong again 
//10:33 WA on #5
//10:36 pass big sample O(mlogn)*t=O(tmlogn) (logn from quickpow)
//sto cyq,the maths master,rating higher than tourist,will solve it easily (if he is still awake) orz
