#include<bits/stdc++.h>
using namespace std;
long long read()
{
	long long ans=0;
	char c=getchar();
	while(c<'0'||c>'9')
	c=getchar();
	while(c>='0'&&c<='9')
	ans=(ans<<1)+(ans<<3)+c-'0',c=getchar();
	return ans;
}
const long long N=1e5+9;
const long long mod=1e9+7;
long long n,m,t,v,tj,gs;
struct dd
{
	int zz,wz;
}cc[N];
bool zt=0;
long long ksm(long long x)
{
	long long ans=1,dq=v;
	while(x)
	{
		if(x&1)
		ans*=dq,ans%=mod;
		dq*=dq,dq%=mod;
		x>>=1;
	}
	ans%=mod;
	return ans;
}
bool cmp(dd&a,dd&b)
{
	if(a.wz<b.wz)
	return true;
	return false;
}
bool qc()
{
	int dq=1,pd=0,zz1=0;
	while(dq<=m)
	{
		if(pd!=cc[dq].wz)
		pd=cc[dq].wz,zz1=cc[dq].zz;
		while(cc[dq].wz==pd&&dq<=m)
		{
			if(cc[dq].zz!=zz1)
			return true;
			dq++;
		}
		gs++,cc[gs].wz=pd;
	}
	return false;
}
int main()
{
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	t=read();
	while(t)
	{
		t--;
		n=read(),m=read(),v=read(),gs=0;
		v=v%mod;
		tj=1;
		memset(cc,0,sizeof(cc));
		for(long long i=1,l,r;i<=m;i++)
		cc[i].wz=read(),cc[i].zz=read();
		sort(cc+1,cc+m+1,cmp);
		if(qc())
		{
			cout<<0<<endl;
			continue;
		}
		tj=tj*ksm(2*cc[1].wz-2),tj%=mod;
		tj*=ksm(2*n-2*cc[gs].wz),tj%=mod;
		for(long long i=1,l;i<=gs-1;i++)
		l=cc[i+1].wz-cc[i].wz,tj*=((ksm(l*2)-ksm(l)+ksm(l-1))%mod),tj%=mod;
		cout<<tj<<endl;
	}
}
