#include<bits/stdc++.h>
# define Maxn 100005
# define ll long long
# define mod 1000000007
using namespace std;
bool vis[Maxn];
int T,n,m,tot;
ll v,ans,V;
struct Node{
	ll x,y;
}a[Maxn],a1[Maxn];
bool cmp(Node x,Node y) {return x.x<y.x;}
ll ksm(ll a,ll b)
{
	ll res=1;
	while(b)
	{
		if(b&1) res=(res*a)%mod;
		a=(a*a)%mod;
		b>>=1;
	}return res;
}
int main()
{
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
//	freopen("my.out","w",stdout);
	scanf("%d",&T);
	while(T--)
	{
		bool bz=0;
		scanf("%d%d%lld",&n,&m,&v);ans=1;V=v*v%mod;tot=0;
		for(int i=1;i<=m;i++) scanf("%lld%lld",&a1[i].x,&a1[i].y);
		sort(a1+1,a1+1+m,cmp);
		for(int i=1;i<m;i++)
		{
			if(a1[i].x==a1[i+1].x&&a1[i].y!=a1[i+1].y)
			{bz=1;printf("0\n");break;}
		}
		if(bz==1) continue;
		a[++tot].x=a1[1].x;a[tot].y=a1[1].y;
		for(int i=2;i<=m;i++)
		{
			if(a1[i].x!=a1[i-1].x)
			{a[++tot].x=a1[i].x;a[tot].y=a1[i].y;}
		}m=tot;
		for(int i=1;i<m;i++)
		{
			ll cnt=a[i+1].x-a[i].x;
			ll all=ksm(V,cnt);
			ll Not=ksm(v,cnt-1);
			Not=Not*(v-1ll)%mod;
			all=((all-Not)%mod+mod)%mod; 
			ans=ans*all%mod;
		}
		ll cnt=a[1].x-1;
		ans=ans*ksm(V,cnt)%mod;
		cnt=n-a[m].x;
		ans=ans*ksm(V,cnt)%mod;
		printf("%lld\n",ans);
	}
	return 0;
}
