#include<bits/stdc++.h>
using namespace std;
const int M=1e9+7;
bool cmp(pair<int,int>a,pair<int,int>b){
	return a.first<b.first;
}
int POW(int a,int n){
	if(n<=0)return 1;
	int res=1;
	while(n){
		if(n&1){
			res*=a;
			res%=M;
		}
		a*=a;
		a%=M;
		n>>=1;
	}
	return res;
}
int main(){
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int V,T,n,m,v,ans,indx;
	pair<int,int>s[(int)1e5+10];
	bool flag=false;
	cin>>T;
	while(T--){
		ans=1;
		indx=1;
		cin>>n>>m>>v;
		V=v*v;
		V%=M;
		v=v*(v-1)+1;
		v%=M;
		for(int i=1;i<=m;i++){
			cin>>s[i].first>>s[i].second;
		}
		sort(s+1,s+m+1,cmp);
		for(int i=1;i<m;i++){
			if(s[i].first==s[i+1].first&&s[i].second!=s[i+1].second){
				cout<<"0\n";
				flag=true;
				break;
			}
		}
		if(flag){
			flag=false;
			continue;
		}
		for(int i=2;i<=m;i++){
			if(s[i].first==indx)continue;
			ans*=POW(V,s[i].first-indx-1);
			ans%=M;
			if(s[i].first-s[i-1].first==1){
				ans*=v;
			}
			else{
				ans*=V;
			}
			ans%=M;
			indx=s[i].first;
		}
		ans*=POW(V,n-indx);
		ans%=M;
		cout<<ans<<'\n';
	}
	return 0;
}
