#include<bits/stdc++.h>
#define Yzl unsigned long long
#define fi first
#define se second
#define pi pair<int,int>
#define mp make_pair
#define pb emplace_back
#define lob lower_bound
#define upb upper_bound
typedef long long LL;

using namespace std;

const Yzl Lty=20120712;

const int MAXN=1e5+10,P=1e9+7;
int n,m,v;
struct ddl {
	int c,d;
}a[MAXN];
bool cmp(ddl a,ddl b) {
	return a.c<b.c;
}
LL fad(LL x,LL y) {
	return (x+y>=P?x+y-P:x+y);
}
struct Matrix {
	LL a[2][2];
	Matrix() { memset(a,0,sizeof(a)); }
	friend Matrix operator *(Matrix &a,Matrix &b) { Matrix ls;
		for(int i=0;i<2;++i) for(int k=0;k<2;++k) for(int j=0;j<2;++j) {
			ls.a[i][j]=fad(ls.a[i][j],a.a[i][k]*b.a[k][j]%P);
		} return ls;
	}
};
LL ksm(LL x,LL y=P-2) { LL ret=1;
	while(y) {
		if(y&1) ret=ret*x%P;
		x=x*x%P; y>>=1;
	} return ret;
}
pi calc(LL x) {
	Matrix Ans,zy;
	Ans.a[0][0]=(LL)(v-1)*v%P;
	Ans.a[0][1]=v;
	zy.a[0][0]=(LL)v*v%P; zy.a[1][0]=(LL)(v-1)*v%P;
	zy.a[1][1]=v; --x;
	while(x) {
		if(x&1) Ans=Ans*zy;
		zy=zy*zy; x>>=1;
	} return mp(Ans.a[0][0],Ans.a[0][1]);
}
void vmain() {
	scanf("%d%d%d",&n,&m,&v);
	for(int i=1;i<=m;++i) scanf("%d%d",&a[i].c,&a[i].d);
	sort(a+1,a+1+m,cmp);
	for(int i=1;i<m;++i) if(a[i].c==a[i+1].c&&a[i].d!=a[i+1].d) return puts("0"),void();
	int lm=0;
	for(int i=1;i<=m;++i) {
		if(a[i].c!=a[i-1].c) a[++lm]=a[i];
	} m=lm;
	LL res=1,iv=ksm(v);
	for(int i=1;i<m;++i) {
		pi coef=calc(a[i+1].c-a[i].c);
		res=res*fad(coef.fi,(LL)coef.se*iv%P)%P;
	} res=res*ksm((LL)v*v%P,a[1].c-1+(n-a[m].c))%P;
//	cout<<coef.fi<<" "<<coef.se<<endl;
	printf("%lld\n",res);
}
int main () {
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	int T=1; scanf("%d",&T); while(T--) vmain();
	return 0;
}

