#include<bits/stdc++.h>
#define pii pair<int,int>
#define int long long
const int N=1e5+3,modd=1e9+7;
using namespace std;
int n,m,v;
vector<pii>vec;
vector<int>a;
map<int,int>mp;
int qpow(int bs,int num){
	int res=1; for(;num;num>>=1){
		if(num&1)res=res*bs%modd;
		bs=bs*bs%modd;
	} return res;
}
int calc(int x){
	// maybe you need to modify it a number of times
	int res=v*v%modd*qpow(v*v%modd,x)%modd;
	int res2=(v-1)*qpow(v,x)%modd;
	return (res-res2+modd)%modd;
}
void Solve(){
	cin>>n>>m>>v;
	mp.clear();
	vec.clear();
	a.clear();
	for(int i=1;i<=m;++i){
		int c,d; cin>>c>>d;
		vec.push_back({c,d});
	} sort(vec.begin(),vec.end());
	for(auto i:vec){
		int c=i.first;
		int d=i.second;
		if(mp.find(c)==mp.end()){
			mp[c]=d;
		} else if(mp[c]!=d){
			cout<<"0\n";
			return;
		}
	}
	for(auto i:mp)
		a.push_back(i.first);
	m=a.size(); int ans=1;
	for(int i=0;i<m-1;++i){
		int gap=a[i+1]-a[i]-1;
		if(gap)ans=ans*calc(gap)%modd;
		else ans=ans*(((v*v%modd+1)%modd-v+modd)%modd)%modd;
	} if(a[0]!=1){
		int gap=a[0]-1;
		ans=ans*qpow(v*v%modd,gap)%modd;
	} if(a[m-1]!=n){
		int gap=n-a[m-1];
		ans=ans*qpow(v*v%modd,gap)%modd;
	} cout<<ans<<'\n';
}
signed main(){
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(nullptr); int Ks;
	cin>>Ks; while(Ks--)Solve();
	return 0;
}
