#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#define int long long
using namespace std;

const int mod=1e9+7;

int T;
int n,m,v;

struct abc{
	int id,x;
}a[100010];

int cmp(abc p,abc q)
{
	return p.id<q.id;
}

int ksm(int x,int k)
{
	int s=1;
	while(k)
	{
		if(k&1)
			s=s*x%mod;
		x=x*x%mod;
		k>>=1;
	}
	return s;
}

signed main()
{
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	cin>>T;
	while(T--)
	{
		memset(a,0,sizeof(a));
		scanf("%lld%lld%lld",&n,&m,&v);
		int t;
		for(int i=1;i<=m;i++)
			scanf("%lld%lld",&a[i].id,&a[i].x);
		sort(a+1,a+m+1,cmp);
		int flg=1;
		for(int i=2;i<=m;i++)
			if(a[i].id==a[i-1].id&&a[i].x!=a[i-1].x)
			{
				flg=0;
				break;
			}
		if(flg)
		{
			int ans=ksm(v*v%mod,a[1].id-1);
			for(int i=2;i<=m;i++)
				if(a[i].id!=a[i-1].id)
					ans=ans*ksm((v*(v-1)+1)%mod,a[i].id-a[i-1].id)%mod;
			ans=ans*ksm(v*v%mod,n-a[m].id)%mod;
			printf("%lld\n",ans);
		}
		else
			printf("0\n");
	}
}
