#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=1e5+5,p=1e9+7;
int t;
ll n,m,v;
struct node{
	ll c,d;
}b[N],a[N];
ll powr(ll x,ll y){
	ll s=1;
	while(y>0){
		if(y%2==1) s*=x,s%=p;
		x*=x;x%=p;y/=2;
	}
	return s;
}
ll tr[N],fl[N];
bool cmp(node x,node y){
	if(x.c==y.c) return x.d<y.d;
	return x.c<y.c;
}
int main(){
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	cin>>t;
	while(t--){
		cin>>n>>m>>v;
		for(int i=1;i<=m;i++)
			cin>>b[i].c>>b[i].d;
		sort(b+1,b+m+1,cmp);
		ll s=1,mm=0;
		for(int i=1;i<=m;i++){
			if(b[i].c==b[i-1].c) {
				if(b[i].d!=b[i-1].d) s=0;
				continue;
			}
			a[++mm]=b[i];
		}
		//cout<<a[1].c<<" "<<a[1].d<<" "<<b[1].c<<" "<<b[1].d<<"?\n";
		s*=(powr(v,2*(a[1].c-1))*powr(v,2*(n-a[mm].c)))%p;
		s%=p;
		for(int i=1;i<mm;i++){
			fl[i]=powr(v,a[i+1].c-a[i].c-1)*(v-1)%p;
			tr[i]=((powr(v,2*(a[i+1].c-a[i].c))-fl[i])%p+p)%p;
			//cout<<tr[cnt]<<"?";
			s*=tr[i];s%=p;
		}
		cout<<s<<"\n";
	}
	return 0;
} 
/*
2 2 2
5 1 1
6 2 2
*/
