#include<iostream>
#include<vector>
#include<algorithm>
#include<unordered_map>
#include<queue>
#define N int(1e5+7)
#define Mod int(1e9+7)
namespace reading{
	#define RR register
	#define getchar() (P==EE&&(EE=(P=buffer)+fread(buffer,1,1<<15,stdin),P==EE)?EOF:*P++)
	char buffer[1<<15],*P=buffer,*EE=buffer;
}
using namespace std;
inline long long read(void){
	using namespace reading;
	RR long long x=0,f=1;
	RR char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
	if(ch=='-')f=-1,ch=getchar();
	while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
	return f*x;
}
inline int mult(int a,int b){//a*(b+c)=a*c+a*b
	return (a*(b>>16)%Mod*(1<<16)%Mod+a*(b&((1<<16)-1))%Mod)%Mod;
}
inline int qpow(int a,int b){
	int pos=1,base=a,tmp=1;
	while(pos<=b){
		if(b&pos){
			tmp=mult(base,tmp);
		}
		pos<<=1;
		base=mult(base,base);
	}
	return tmp;
}
pair<int,int>num[N];
int main(){
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	int t=read();
	while(t--){
		bool flag=false;
		long long ans=1;
		int n=read(),m=read(),v=read();
		vector<bool>it(n,1); 
		for(int i=0,c,d;i<m;i++){
			c=read();
			d=read();
			num[i]={c,d};
		}
		sort(num,num+m);
		ans=mult(ans,qpow(mult(v,v),num[0].first-1));
		if(!ans)ans=1;
		for(int i=0;i<m-1;i++){
			if(num[i].first==num[i+1].first-1){
				ans=mult(ans,mult(v-1,v)+1);
			}
			else{
				if(num[i].first==num[i+1].first){
					if(num[i].second!=num[i+1].second){
						putchar('0'),putchar('\n');
						flag=true;
						break;
					}
				}else{
					int len=num[i+1].first-num[i].first;
					ans=mult(ans,qpow(mult(v,v),len));
				}
			}
		}
		int tm=qpow(mult(v,v),n-num[m-1].first);
		if(tm)
		ans=mult(ans,tm);
		if(flag)continue;
		else{
			if(ans==1)printf("0\n");
			else
			printf("%lld\n",ans);
		}
	}
	return 0;
}
