#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<map>
#define int long long
#define mod 1000000007ll
using namespace std;
int read()
{
	int ans=0,fl=1;
	char c=getchar();
	while ((c<'0'||c>'9')&&c!='-') c=getchar();
	if (c=='-')
	{
		c=getchar();
		fl=-1;
	}
	while (c>='0'&&c<='9')
	{
		ans=ans*10+c-48;
		c=getchar();
	}
	return ans*fl;
}
int T,n,m,v,f[100105][2];
pair<int,int> cc[100105];
struct nd{
	int a[2][2];
} bg1,bg2,ans,fq;
nd operator *(const nd &x,const nd &y)
{
	nd z;
	z.a[0][0]=0;
	z.a[1][0]=0;
	z.a[0][1]=0;
	z.a[1][1]=0;
	for (int k=0;k<2;++k) for (int i=0;i<2;++i) for (int j=0;j<2;++j)
	{
		z.a[i][j]+=x.a[i][k]*y.a[k][j]%mod;
		if (z.a[i][j]>=mod) z.a[i][j]-=mod;
	}
	return z;
}
nd ksm(nd x,int y)
{
	nd ans;
	ans.a[0][0]=1;
	ans.a[1][1]=1;
	ans.a[1][0]=0;
	ans.a[0][1]=0;
	while (y)
	{
		if (y&1) ans=ans*x;
		x=x*x;
		y>>=1;
	}
	return ans;
}
int wh[100105];
signed main()
{
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	T=read();
	while (T--)
	{
		n=read(),m=read(),v=read();
		for (int i=1;i<=m;i++)
		{
			cc[i].first=read();
			cc[i].second=read();
		}
		sort(cc+1,cc+1+m);
		int fl=1,tot=0;
		for (int i=1;i<=m;i++)
		{
			if (i!=m&&cc[i].first==cc[i+1].first&&cc[i].second!=cc[i+1].second)
			{
				fl=0;
			}
			if (cc[i].first!=cc[i-1].first) wh[++tot]=cc[i].first;
		}
		if (fl==0)
		{
			printf("0\n");
			continue;
		}
		ans.a[0][0]=1,ans.a[0][1]=0;
		ans.a[1][0]=0,ans.a[1][1]=0;
		bg1.a[0][0]=v*v%mod;
		bg1.a[1][0]=(v-1)*v%mod;
		bg1.a[1][1]=v;
		bg1.a[0][1]=0;
		bg2.a[0][0]=0;
		bg2.a[1][0]=0;
		bg2.a[1][1]=(1+v*(v-1)%mod)%mod;
		bg2.a[0][1]=v*v%mod;
		int lst=1;
		for (int i=1;i<=tot;i++)
		{
			int le=max(wh[i]-lst-1,0ll);
			fq=ksm(bg1,le);
			ans=ans*fq;
			if (wh[i]!=1) ans=ans*bg2;
			ans.a[0][1]+=ans.a[0][0];
			if (ans.a[0][1]>=mod) ans.a[0][1]-=mod;
			ans.a[0][0]=0,ans.a[1][0]=0,ans.a[1][1]=0;
			lst=wh[i];
		}
		int le=n-lst;
		fq=ksm(bg1,le);
		ans=ans*fq;
		printf("%lld\n",(ans.a[0][1]+ans.a[0][0])%mod);
	}
	return 0;
}
