#include<iostream>
#include<algorithm>
#include<fstream>
using namespace std;
const int maxm=1e5+10;
const long long mod=1e9+7;
long long unk,acr;
long long ans;
int T,n,m,v;
struct node{
	int c,d;
}dat[maxm];
int read(){
	int res=0;char ch=getchar();
	while(ch<'0'||ch>'9')ch=getchar();
	while(ch>='0'&&ch<='9'){
		res=(res<<1)+(res<<3)+ch-'0';
		ch=getchar();
	}
	return res;
}
bool cmp(node p,node q){
	if(p.c==q.c)return p.d<q.d;
	return p.c<q.c;
}
long long qp(long long x,int p){
	long long res=1;
	while(p>0){
		if(p&1)res=(res*x)%mod;
		x=(x*x)%mod;
		p>>=1;
	}
	return res%mod;
}
long long qmul(long long x,long long p){
	long long res=0;
	while(p>0){
		if(p&1)res=(res+x)%mod;
		x=(x+x)%mod;
		p>>=1;
	}
	return res%mod;
}
int main(){
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	T=read();
	while(T--){
		n=read();m=read();v=read();
		unk=qmul(v,v);
		for(int i=1;i<=m;i++){
			dat[i].c=read();dat[i].d=read();
		}
		sort(dat+1,dat+m+1,cmp);
		if(dat[1].c>1){
			ans=qp(unk,dat[1].c-1)%mod;
		}else ans=1;
		for(int i=2;i<=m;i++){
			if(dat[i].c==dat[i-1].c){
				if(dat[i].d!=dat[i-1].d){ans=0;break;}
				continue;
			}
			ans=qmul(ans , ( qp(unk,dat[i].c - dat[i-1].c) - qmul(qp(v,dat[i].c - dat[i-1].c-1),v-1) +mod)%mod );
		}
		if(dat[m].c<n){
			ans=qmul(ans,qp(unk,n-dat[m].c))%mod;
		}
		cout << ans << endl;
	}
	return 0;
}
