#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
using namespace std;
const int N=1e5+5;
const long long M=1e9+7;
long long ans,T,n,m,v;
bool flag;
struct lmt{
	int c,d;
	lmt(){}
	lmt(int lc,int ld):c(lc),d(ld){}
	bool operator < (const lmt &L2) const{
		return c<L2.c;
	}
};
lmt L[N];
long long quick_pow(long long num,long long p){
	if(p==0) return 1;
	if(p==1) return num%M;
	long long qp=quick_pow(num,p/2);
	if(p&1) return ((qp*qp)%M)*num%M;
	else return (qp*qp)%M;
}
int main(){
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	int ic,id;
	long long k;
	long long cnt;
	scanf("%lld",&T);
	while(T--){
		ans=1;
		flag=false;
		scanf("%lld %lld %lld",&n,&m,&v);
		for(int i=0;i<m;i++){
			scanf("%d %d",&ic,&id);
			L[i]=lmt(ic,id);
		}
		sort(L,L+m);
		k=L[0].c-1+n-L[m-1].c;
		ans*=quick_pow(v,2*k);
		for(int i=1;i<m;i++){
			if(L[i-1].c==L[i].c){
				if(L[i-1].d!=L[i].d){
					printf("0\n");
					flag=true;
					break;
				}
				else{
					continue;
				}
			}
			k=L[i].c-L[i-1].c;
			cnt=quick_pow(v,k-1);
			cnt=((cnt*v%M)*(cnt*v%M)%M+(M-cnt*v%M)%M+cnt%M)%M;
			ans=(ans*cnt)%M;
		}
		if(flag) continue;
		printf("%lld\n",ans);
	}
	fclose(stdin);
	fclose(stdout);
	return 0;
}
