#include<bits/stdc++.h>
#define fo(i,l,r) for(int i=l;i<=r;++i)
#define fd(i,r,l) for(int i=r;i>=l;--i)
#define ll long long
#define V inline void
#define I inline int
using namespace std;
const int N=1e6+10,mod=1e9+7;
int n,m,v,f[N][2];
struct Mat {
	int n,m,a[3][3];
	Mat() {memset(a,0,sizeof(a));n=m=0;}
};
Mat operator *(Mat x,Mat y) {
	Mat z;z.n=x.n;z.m=y.m;
	fo(i,1,z.n) fo(j,1,z.m) {
		z.a[i][j]=0;
		fo(k,1,x.m) {
			z.a[i][j]=(z.a[i][j]+1ll*x.a[i][k]*y.a[k][j]%mod)%mod;
		}
	}
	return z;
}
Mat ksm(Mat x,int y) {
	Mat t;t=x;
	fo(i,1,t.n) fo(j,1,t.m) t.a[i][j]=i==j;
	for(;y;y>>=1,x=x*x) if(y&1) t=t*x;
	return t;
}
#define pi pair<int,int>
#define fi first
#define se second
#define mk make_pair
pi a[N];
V solve() {
	scanf("%d%d%d",&n,&m,&v);
	int bj(1),bj2(0);ll ans(0);
	fo(i,1,m) {
		int x,y;scanf("%d%d",&x,&y);
		a[i]=mk(x,y);
		if(x==n) bj2=1;
	}
	sort(a+1,a+m+1);
	m=unique(a+1,a+m+1)-a-1;
	fo(i,1,m) {
		if(a[i].fi==a[i-1].fi) {
			puts("0");return ;
		}
	}
	Mat s,S,T;s.n=1;s.m=2;s.a[1][1]=1;
	S.n=2;S.m=2;
	S.a[1][1]=1ll*(v-1)*v%mod;
	S.a[2][1]=1ll*(v-1)*v%mod;
	S.a[1][2]=1;S.a[2][2]=1;
	T.n=2;T.m=2;
	T.a[1][1]=1ll*v*v%mod;
	T.a[2][1]=1ll*v*(v-1)%mod*v%mod;
	T.a[1][2]=0;T.a[2][2]=v;
	fo(i,1,m) {
		s=s*ksm(T,a[i].fi-a[i-1].fi-1);
		if(a[i].fi!=n) s=s*S;
	}
	if(a[m].fi<n-1) s=s*ksm(T,n-1-a[m].fi);
	if(bj2) {
		ans=(s.a[1][1]+s.a[1][2])%mod;
	}
	else {
		ans=(s.a[1][1]+1ll*s.a[1][2]*v)%mod;
	}
	printf("%lld\n",ans%mod);
}
int main() {
//	return system("fc assign.out assign2.ans"),0;
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	int T;scanf("%d",&T);
	while(T--) solve();
}
