#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;

const int N = 2e5+10;
const int M = 1e9+7;
int n,m,v,a[N];
int po[N];
struct node{
	int c,d;
}no[N];
inline bool cmp(node x,node y){
	return x.c<y.c;
}

inline int qpow(int base,int x){
	int tmp = 1;
	while(x){
		if(x&1) tmp = (tmp*base)%M;
		base = (base*base)%M;
		x >>= 1ll;
	}
	return tmp;
}

inline void work(){
	cin>>n>>m>>v;
	for(int i=1;i<=m;i++){
		cin>>no[i].c>>no[i].d;
	} 
	sort(no+1,no+m+1,cmp);
	int ans = qpow(v*v%M,no[1].c-1);
	for(int i=2;i<=m;i++){
		if(no[i].c==no[i-1].c){
			if(no[i].d!=no[i-1].d){
				cout<<0<<endl;
				return;
			}
			continue;
		}
		ans = (ans*(qpow(v,2*(no[i].c-no[i-1].c))-qpow(v,no[i].c-no[i-1].c)+qpow(v,no[i].c-no[i-1].c-1)+M+M)%M);
	}	
	ans = (ans*qpow(v,2*(n-no[m].c))%M);
	cout<<ans<<endl;
}

signed main(){
	ios::sync_with_stdio(false);
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	int t;
	cin>>t;
	while(t--){
		work();
	}
	
	return 0;
}
