#include<bits/stdc++.h>
using namespace std;
const int MAXN=1e5+5,MOD=1e9+7;
#define ll long long
ll n,m,v,c[MAXN],d[MAXN],f[MAXN],val[MAXN],ans;
struct node
{
	ll c,d;
}a[MAXN];
bool cmp(node x,node y)
{
	if(x.c!=y.c)return x.c<y.c;
	return x.d<y.d;
}
ll qpow(ll a,ll b)
{
	ll ans=1;
	while(b)
	{
		if(b&1)ans*=a,ans%=MOD;
		a*=a,a%=MOD;b>>=1;
	}
	return ans;
}
int main()
{
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	int T;
	cin>>T;
	while(T--)
	{
		cin>>n>>m>>v;
		for(int i=1;i<=m;i++)
			scanf("%lld%lld",c+i,d+i),a[i]={c[i],d[i]};
		sort(a+1,a+1+m,cmp);
		for(int i=1;i<=m;i++)
			c[i]=a[i].c,d[i]=a[i].d;
		int flg=0;
		for(int i=1;i<m;i++)
		{
			if(c[i]==c[i+1]&&d[i]!=d[i+1])
			{
				puts("0");
				flg=1;
				break;;
			}
		}
		if(flg)continue;
		ans=1;
		if(c[1]!=1)ans=qpow(v*v%MOD,c[1]-1)%MOD;
		for(int i=2;i<=m;i++)
			if(c[i]!=c[i-1])
			ans*=qpow(v*v%MOD,c[i]-c[i-1])-qpow(v,c[i]-c[i-1]-1)*(v-1)%MOD
			,ans%=MOD;
		if(c[m]!=n)ans*=qpow(v*v%MOD,n-c[m]);
		ans%=MOD;
		cout<<(ans+MOD)%MOD<<endl;
	}
	return 0;
}
