#include<bits/stdc++.h>
using namespace std;
const int N=1e5;
long long mod=1e9+7;
int T,n,m;
long long v,ans,fd,gd;
struct que{
	int c,d;
}w[N+5];
struct matrix{
	long long a[2][2];
	matrix operator*(const matrix ax)const{
		matrix cx;
		for(int i=0;i<2;i++){
			for(int j=0;j<2;j++){
				cx.a[i][j]=0;
				for(int k=0;k<2;k++){
					cx.a[i][j]=(cx.a[i][j]+a[i][k]*ax.a[k][j])%mod;
				}
			}
		}
		return cx;
	}
}h;
bool cmp(que ax,que bx){
	if(ax.c!=bx.c) return ax.c<bx.c;
	return ax.d<bx.d;
}
matrix mi(matrix t,int td){
	matrix re;
	re.a[0][1]=re.a[1][0]=0;
	re.a[0][0]=re.a[1][1]=1;
	while(td){
		if(td&1) re=re*t;
		td>>=1;t=t*t;
	}
	return re;
}
int main()
{
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	scanf("%d",&T);
	while(T--){
		scanf("%d%d%lld",&n,&m,&v);
		h.a[0][0]=v;h.a[0][1]=v*(v-1)%mod;
		h.a[1][0]=0;h.a[1][1]=v*v%mod;
		for(int i=1;i<=m;i++){
			scanf("%d%d",&w[i].c,&w[i].d);
		}
		sort(w+1,w+m+1,cmp);
		int fl=0;
		for(int i=1;i<m;i++){
			if(w[i].c==w[i+1].c&&w[i].d!=w[i+1].d){
				printf("0\n");
				fl=1;
				break;
			}
		}
		if(fl) continue;
		int lst=1;
		fd=0;gd=1;
		if(w[1].c==1) fd=1,gd=0;
		for(int i=1;i<=m;i++){
			if(w[i].c==1) continue;
			if(i>1&&w[i].c==w[i-1].c) continue;
			matrix p=mi(h,w[i].c-lst-1);
			long long tmpf=fd,tmpg=gd;
			fd=(tmpf*p.a[0][0]+tmpg*p.a[1][0])%mod;
			gd=(tmpf*p.a[0][1]+tmpg*p.a[1][1])%mod;
			tmpf=fd;tmpg=gd;
			fd=((v*(v-1)+1)%mod*tmpf+v*v%mod*tmpg)%mod;
			gd=0;
			lst=w[i].c;
		}
		matrix p=mi(h,n-lst);
		long long tmpf=fd,tmpg=gd;
		fd=(tmpf*p.a[0][0]+tmpg*p.a[1][0])%mod;
		gd=(tmpf*p.a[0][1]+tmpg*p.a[1][1])%mod;
		ans=(fd+gd)%mod;
		printf("%lld\n",ans);
	}
	return 0;
}
