#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=1e5+50,mod=1e9+7;
bool fl;
int T,n,m,v,now;
struct jgt {int c,d;}a[N];
bool cmp(jgt t1,jgt t2) {return t1.c<t2.c;}
struct jz
{
	int b[2][2];
}A,B,C,ze;
jz operator * (jz t1,jz t2)
{
	jz re=ze;
	for(int i=0;i<2;i++)
	for(int j=0;j<2;j++)
	for(int k=0;k<2;k++)
		re.b[i][j]=(re.b[i][j]+1ll*t1.b[i][k]*t2.b[k][j]%mod)%mod;
	return re;
}
void ksm(int zs)
{
	B.b[0][0]=1ll*v*v%mod;
	B.b[0][1]=0;
	B.b[1][0]=1ll*(v-1)*v%mod;
	B.b[1][1]=v;
	while(zs)
	{
		if(zs&1) A=A*B;
		B=B*B;
		zs=zs/2;
	}
}
int main()
{
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	ze.b[0][0]=ze.b[0][1]=ze.b[1][0]=ze.b[1][1]=0;
	scanf("%d",&T);
	while(T--)
	{
		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+m+1,cmp);
		
		//判断是否合法 
		fl=true;
		for(int i=2;i<=m;i++) if(a[i].c==a[i-1].c&&a[i].d!=a[i-1].d) {fl=false;break;}
		if(!fl) {puts("0");continue;}
		
		//初始化 
		A=B=C=ze;
		
		if(a[1].c==1) A.b[0][0]=0,A.b[0][1]=1;
		else A.b[0][0]=1,A.b[0][1]=0;
		
		C.b[0][0]=0,C.b[0][1]=1ll*v*v%mod,C.b[1][0]=0,C.b[1][1]=(1ll*(v-1)*v%mod+1ll)%mod;
		now=1;
		
		//计算答案 
		for(int i=1;i<=m;i++) if(now<a[i].c)
			ksm(a[i].c-now-1),A=A*C,now=a[i].c;
		if(now<n) ksm(n-now);
		
		//输出 
		printf("%d\n",(A.b[0][0]+A.b[0][1])%mod);
	}
	return 0;
}
