#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5,M=1e9+7;
int t,n,m,V,VV;
struct val
{
	int c,d;
	friend bool operator <(const val a,const val b)
		{return a.c<b.c;}
}v[N];
int qpow(int a,int b)
{
	int ans=1;
	while(b>0)
	{
		if(b&1) ans=1ll*ans*a%M;
		a=1ll*a*a%M;
		b>>=1;
	}
	return ans;
}
int main()
{
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	cin>>t;
	while(t--)
	{
		cin>>n>>m>>V;VV=1ll*V*V%M;
		for(int i=1;i<=m;i++) cin>>v[i].c>>v[i].d;
		sort(v+1,v+1+m);
		int ans=qpow(V,2*v[1].c-2);
		for(int i=2;i<=m;i++)
		{
			if(v[i].c==v[i-1].c)
			{
				if(v[i].d!=v[i-1].d){ans=0;break;}
				else continue;
			}
			ans=1ll*ans*(0ll+M+qpow(VV,v[i].c-v[i-1].c)-1ll*qpow(V,v[i].c-v[i-1].c-1)*(V-1)%M)%M;
		}
		ans=1ll*ans*(qpow(V,2*(n-v[m].c)))%M;
		cout<<ans<<'\n';
	}
	return 0;
}
