#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const int N=1e5+5,mod=1e9+7;

int n,m;
PII a[N];

LL qp(LL x,LL y){
	LL res=1,i=x%mod;
	while(y){
		if(y&1) res=res*i%mod;
		i=i*i%mod;
		y>>=1;
	}
	return res;
}

int main(){
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	ios::sync_with_stdio(0);
	
	int ttt;
	LL v,res,x;
	cin>>ttt;
	while(ttt--){
		cin>>n>>m>>v;
		for(int i=1;i<=m;i++){
			cin>>a[i].first>>a[i].second;
		}
		sort(a+1,a+1+m);
		res=qp(v,2*(a[1].first-1));
		for(int i=2;i<=m;i++){
			if(a[i].first==a[i-1].first){
				if(a[i].second!=a[i-1].second) res=0;
			}else{
				x=a[i].first-a[i-1].first;
				res=res*((qp(v,2*x)+mod-qp(v,x-1)*(v-1)%mod)%mod)%mod;
			}
		}
		if(a[m].first<n) res=res*qp(v,2*(n-a[m].first))%mod;
		cout<<res<<endl;
	}
	return 0;
}
/*

*/
