#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e5+5;
const int mod=1e9+7;
int qpow(int n,int m)
{
	int ans=1;
	while(m)
	{
		if(m&1)ans=ans*n%mod;
		n=n*n%mod;
		m>>=1; 
	}
	return ans;
}
int T;
int n,m,v;
struct node
{
	int c,d;
	bool operator <(const node &ot)const{return c<ot.c;}
}x[N];
int num[N];
int ans;
signed main()
{
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	cin>>T;
	while(T--)
	{
		ans=1;
		cin>>n>>m>>v;
		for(int i=1;i<=m;i++)cin>>x[i].c>>x[i].d;
		sort(x+1,x+1+m);
		for(int i=1;i<m;i++)
		{
			num[i]=0;
			if(x[i].c==x[i+1].c)
			{
				if(x[i].d!=x[i+1].d)ans=0;
				else continue;
			}
			else num[i]=mod-qpow(qpow(v,(x[i+1].c-x[i].c)*2%mod),mod-2)*qpow(v,x[i+1].c-x[i].c-1)%mod*(v-1)%mod;
		}
		for(int i=1;i<m;i++)
			ans=(ans+ans*num[i]%mod)%mod;
		ans=ans*qpow(v,(n-1)*2)%mod;
		cout<<ans<<'\n';
	}
	return 0;
}

