#include<bits/stdc++.h>
using namespace std;
int T;
long long ans;
long long n,m,v;
const long long mod=1e9+7;
const int MAXN=1e5+10;
bool flag=false;
struct Node{
	long long c,d;
}lim[MAXN];
long long quickpow(long long a,long long b)
{
	if(b==0)return 1;
	if(b==1)return a%mod;
	return ((quickpow(a,b>>1)%mod)*(quickpow(a,b-(b>>1))%mod))%mod;
}
bool cmp(Node a,Node b)
{
	if(a.c==b.c)
	{
		if(a.d!=b.d)
			flag=true;
		return a.d<b.d;
	}
	return a.c<b.c;
}
int main()
{
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	scanf("%d",&T);
	while(T--)
	{
		ans=1;
		flag=false;
		scanf("%lld%lld%lld",&n,&m,&v);
		for(int i=1;i<=m;i++)
			scanf("%lld%lld",&lim[i].c,&lim[i].d);
		sort(lim+1,lim+m+1,cmp);
		if(flag)
		{
			printf("0\n");
			continue;
		}
		for(int i=2;i<=m;i++)
		{
//			cout<<lim[i].c<<" "<<lim[i-1].c<<endl;
			if(lim[i].c==lim[i-1].c+1)ans*=((((v-1)%mod)*v%mod)+1)%mod,n--;
			ans=ans%mod;
		}
		n--;
		int t=quickpow(v,2)%mod;
		ans*=quickpow(t,n)%mod;
		ans=ans%mod;
		printf("%lld\n",ans);
	}
	fclose(stdin);
	fclose(stdout);
	return 0;
 } 
/*
*/
