#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define exmod(x,y) ((x%y+y)%y)
const ll N=1e6+1e2,M=1e5+1e2;
const ll Mod=1e9+7;
ll T;
ll n,m,v;
ll dp[M];
struct Data
{
	ll c,d;
	bool operator < (const Data&P)const
	{
		if(c!=P.c)return c<P.c;
		return d<P.d;
	}
	bool operator == (const Data&P)const
	{
		if(c==P.c)
			return true;
		return false;
	}
}a[M];
ll quick_mi(ll a,ll b)
{
	ll s=1;
	while(b)
	{
		if(b&1)s=s*a%Mod;
		a=a*a%Mod;
		b>>=1;
	}
	return s;
}
signed main()
{
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	scanf("%lld",&T);
	while(T--)
	{
		scanf("%lld%lld%lld",&n,&m,&v);
		bool flag=false;
		for(ll i=1;i<=m;i++)
			scanf("%lld%lld",&a[i].c,&a[i].d);
		sort(a+1,a+m+1);
		for(ll i=2;i<=m;i++)
			if(a[i].c==a[i-1].c&&a[i].d!=a[i-1].d)
			{
				flag=true;
				break;
			}
		if(flag)
		{
			puts("0");
			continue;
		}
		m=unique(a+1,a+m+1)-a-1;
		memset(dp,0,sizeof dp);
		v%=Mod;
		dp[1]=quick_mi(v*v%Mod,a[1].c-1);
		for(ll i=2;i<=m;i++)
		{
			ll tim;
			if(a[i].c-a[i-1].c-2>=0)
				tim=quick_mi(v*v%Mod,a[i].c-a[i-1].c)-(v*(v-1)%Mod*quick_mi(v,a[i].c-a[i-1].c-2));
			else
				tim=v*v%Mod-(v-1);
			tim=(tim%Mod+Mod)%Mod;
			dp[i]=dp[i-1]*tim%Mod;
		}
		if(a[m].c==n)printf("%lld\n",exmod(dp[m],Mod));
		else
		{
			ll tim=quick_mi(v*v%Mod,n-a[m].c);
			tim=(tim%Mod+Mod)%Mod;
			ll ans=dp[m]*tim%Mod;
			printf("%lld\n",exmod(ans,Mod));
		}
	}
}
