#include<bits/stdc++.h>
#define ll long long
#define mp(a,b) make_pair(a,b)
using namespace std;
const ll MAXN=1e5+5,MOD=1e9+7;
ll T,n,m,v,dp[MAXN];//0:No,1:Yes
//all:v^(2k)
//false:v^(k-1)*(v-1)
pair<ll,ll> d[MAXN];
bool Legal()
{
	bool b=true;
	for(ll i=1;i<m;i++)
		if(d[i].first==d[i+1].first&&d[i].second!=d[i+1].second)
		{
			b=false;
			break;
		}
	return b;
}
ll Pow(ll a,ll x)
{
	ll s=1;
	while(x)
	{
		if(x%2) s=s*a%MOD;
		x/=2;
		a=a*a%MOD;
	}
	return s;
}
int main()
{
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	scanf("%lld",&T);
	while(T--)
	{
		scanf("%lld%lld%lld",&n,&m,&v);
		for(ll i=1;i<=m;i++)
			scanf("%lld%lld",&d[i].first,&d[i].second);
		sort(d+1,d+m+1);
		if(!Legal())
		{
			printf("0\n");
			continue;
		}
		dp[1]=Pow(v,2*(d[1].first-1));
		for(ll i=2,pre=1;i<=m;i++)
		{
			if(d[i].first==d[i-1].first)
			{
				dp[i]=dp[i-1];
				continue;
			}
			ll k=d[i].first-d[pre].first;
			dp[i]=dp[pre]*((Pow(v,2*k)-Pow(v,k-1)*(v-1)%MOD+MOD)%MOD)%MOD;
			pre=i;
		}
		printf("%lld\n",dp[m]*Pow(v,2*(n-d[m].first))%MOD);
	}
	return 0;
}
