#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10; 
const long long mod=1e9+7;
long long t,n,m,v,f[N];
struct node
{
	long long pos,val;	
}a[N],b[N];
long long read()
{
	long long s=0,w=1;
	char ch=getchar();
	while(ch<'0'||ch>'9')
	{
		if(ch=='-')
			w=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')
		s=s*10+(ch-'0'),ch=getchar();
	return s*w;
}
bool cmp(node a,node b)
{
	return a.pos<b.pos;
}
long long ksm(long long a,long long b)
{
	long long sum=1;
	while(b)
	{
		if(b&1)
			sum=sum*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return sum;
}
void work(int T)
{
	n=read(),m=read(),v=read();
	for(int i=1;i<=m;++i)	
		a[i]=(node){read(),read()};
	sort(a+1,a+m+1,cmp);
	long long ans=ksm(v*v%mod,n-1);
	bool flag=true;
	int tot=0;
	for(int i=1;i<=m;++i)
	{
		int j=i;
		while(j+1<=m&&a[j+1].pos==a[i].pos)
		{
			if(a[j+1].val!=a[i].val)
				flag=false;
			j++;	
		}
		i=j;
		b[++tot]=a[i];
	}
	if(!flag)
	{
		printf("0\n");
		return ;
	}
	f[1]=ksm(v*v%mod,b[1].pos-1);
	for(int i=2;i<=tot;++i)
	{
		long long sum=ksm(v*v%mod,n-b[i].pos),val=ksm(v,b[i].pos-1-b[i-1].pos)*(v-1)%mod;
		ans=(ans-f[i-1]*val%mod*sum%mod+mod)%mod;
		f[i]=f[i-1]*((ksm(v*v%mod,b[i].pos-b[i-1].pos)-val+mod)%mod)%mod;
	}
	printf("%lld\n",ans);
}
int main()
{
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	t=read();
	for(int T=1;T<=t;++T)
		work(T);
	return 0;
} 
