#include<bits/stdc++.h>
#define fre(s) freopen(#s".in","r",stdin);freopen(#s".out","w",stdout);
#define ll long long
using namespace std;
const ll mod=1e9+7;
const int N=1e5+5;
int n,m,v;
pair<int,int>a[N];
ll f[N];
ll qpow(ll a,ll b)
{
	ll res=1;
	for(;b;b>>=1,a=a*a%mod)
		if(b&1)
			res=res*a%mod;
	return res;
}
void work()
{
	scanf("%d%d%d",&n,&m,&v);
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d",&a[i].first,&a[i].second);
	}
	sort(a+1,a+m+1);
	m=unique(a+1,a+m+1)-a-1;
	f[1]=qpow(v,2*(a[1].first-1));
	for(int i=2;i<=m;i++)
	{
		if(a[i].first==a[i-1].first&&a[i].second!=a[i-1].second)
		{
			puts("0");
			return;
		}
		f[i]=f[i-1]*(qpow(v,2*(a[i].first-a[i-1].first)%mod)-qpow(v,(a[i].first-a[i-1].first-1))*(v-1)%mod+mod)%mod;
	}
	printf("%lld\n",f[m]*qpow(v,2*(n-a[m].first)%mod)%mod);
}
int main()
{
	fre(assign);
	int T;
	scanf("%d",&T);
	while(T--)work();
	return 0;
}
/*
3
2 1 2
1 1
2 2 2
1 1
2 2
2 2 2
1 1
1 2
*/
