#include<bits/stdc++.h>
using namespace std;
#define int long long
const int mod=1e9+7;
int t;
int n,m,v;
struct node
{
	int a,b;
}c[100005];
bool cmp(node ai,node bi){return ai.a<bi.a;}
int qpow(int aa,int bb)
{
	int res=1;
	while(bb)
	{
		if(bb&1) res=res*aa%mod;
		aa=aa*aa%mod;
		bb>>=1;
	}
	return res;
}
signed main()
{
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	scanf("%lld",&t);
	while(t--)
	{
		scanf("%lld%lld%lld",&n,&m,&v);
		for(int i=1;i<=m;i++)
			scanf("%lld%lld",&c[i].a,&c[i].b);	
		sort(c+1,c+m+1,cmp);
		int ans=1;
		int pd=1;
		if(c[1].a>1) ans=ans*qpow(v*v%mod,c[1].a-1)%mod;
		if(c[m].a<n) ans=ans*qpow(v*v%mod,n-c[m].a)%mod;
		for(int i=1;i<m;i++)
		{
			if(c[i].a==c[i+1].a)
			{
				if(c[i].b!=c[i+1].b)
				{
					printf("0\n");
					pd=0;
					break;
				}
				continue;
			}
			ans=ans*((qpow(v*v%mod,c[i+1].a-c[i].a)+mod-qpow(v,c[i+1].a-c[i].a-1)*(v-1)%mod)%mod)%mod;
		}
		if(!pd) continue;
		printf("%lld\n",ans); 
	}
	return 0;
 } 
