#include<bits/stdc++.h>
using namespace std;
void Freop(int flag)
{
	if(flag)
	{
		freopen("assign.in","r",stdin);
		freopen("assign.out","w",stdout);
	}
}
inline int Read()
{
	int x=0,f=1;
	char ch=getchar();
	while(!isdigit(ch))
	{
		if(ch=='-')
			f=-1;
		ch=getchar();
	}
	while(isdigit(ch))
	{
		x=(x<<1)+(x<<3)+ch-48;
		ch=getchar();
	
	}
	return x*f;
}
const int Mod=1e9+7;
const int N=1e5+5;
int Qp(int a,int b)
{
	int ret=1;
	while(b)
	{
		if(b&1)
			ret=1ll*ret*a%Mod;
		b>>=1;
		a=1ll*a*a%Mod;
	}
	return ret;
}
struct data
{
	int c,d;
}a[N];
bool cmp(data x,data y)
{
	return x.c==y.c?x.d<y.d:x.c<y.c;
}
int main()
{
	Freop(1);
	int T=Read();
	while(T--)
	{
		int n=Read(),m=Read(),v=Read(),v2=1ll*v*v%Mod;
		long long ans=1;
		for(int i=1;i<=m;i++)
			a[i].c=Read(),a[i].d=Read();
		sort(a+1,a+m+1,cmp);
		int mm=1,flag=1;
		for(int i=2;i<=m;i++)
			if(a[i].c==a[i-1].c)
			{
				if(a[i].d!=a[i-1].d)
				{
					printf("0\n");
					flag=0;
					break;
				}
			}
			else
				a[++mm]=a[i];
		if(!flag)
			continue;
		m=mm;
		for(int i=1;i<m;i++)
			if(a[i+1].c-a[i].c==1)
				ans=(1ll*ans*((1+(1ll*v*(v-1)))%Mod))%Mod;
			else
				ans=(1ll*ans*(((1+(1ll*v*(v-1))%Mod)%Mod)*((1ll*v*v+1)%Mod))%Mod)*1ll*Qp(v2,a[i+1].c-a[i].c-2)%Mod;
		if(n-a[m].c)
			ans=(1ll*ans*Qp(v2,n-a[m].c)%Mod)%Mod;
		if(a[1].c-1)
			ans=(1ll*ans*Qp(v2,a[1].c-1))%Mod;
		printf("%lld\n",ans);
	}
	return 0;
}
