#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=2e5+10,mod=1e9+7;
int T,n,m,v;
struct node
{
	int e,d;
}a[1000009],b[1000009];
int mp[N];
bool cmp(node x,node y)
{
	return x.e<y.e;
}
int ksm(int u,int cs)
{
	int cnt=1;
	while(cs!=0)
	{
		if(cs%2==1)
		{
			cs--;
			cnt=cnt*u;
			cnt=cnt%mod;
		}
		else
		{
			u=u*u;
			u=u%mod;
			cs=cs/2;
		}
	}
	return cnt;
}
signed main()
{
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	cin>>T;
	while(T--)
	{
		scanf("%lld%lld%lld",&n,&m,&v);
		for(int i=1;i<=m;i++)
		{
			scanf("%lld%lld",&a[i].e,&a[i].d);
		}
		sort(a+1,a+m+1,cmp);
		int ans=0,sum=0,m1=0;
		for(int i=1;i<=m;i++)
		{
			if(a[i].e==a[i+1].e&&a[i].d!=a[i+1].d&&i!=m+1)
			{
				ans=-1;
				break;
			}
			else if(a[i].e!=a[i-1].e)
			{
				m1++;
				b[m1].e=a[i].e;
				b[m1].d=a[i].d;
			}
			//cout<<ans<<endl;
		}
		if(ans==-1)
		{
			 cout<<0<<endl;
			 continue;
		}
		ans=1,sum=0;
		for(int i=1;i<=m1;i++)
		{
			if(b[i].e==1)
			{
				continue;
			}
			else if(i==1)
			{
				ans*=ksm((v*v)%mod,b[i].e-1);
				ans%=mod;
				continue;
			}
			if(b[i].e-1==b[i-1].e)
			{
				ans*=(v*v-v+1)%mod;
				ans=ans%mod;
				sum++;
			}
			else 
			{
				sum++;
				ans*=(ksm((v*v)%mod,b[i].e-b[i-1].e)-(v*(v-1))%mod+mod)%mod;
				ans=ans%mod;
			}
		} 
		ans*=ksm((v*v)%mod,n-b[m1].e);
		ans%=mod;
		//cout<<ans<<" "<<m1<<endl;
		cout<<ans<<endl;
		
	}
	return 0;
}
/*
1  
10 11 2 
10 2 
7 2 
7 2 
2 2 
3 2 
4 2 
10 2 
7 2 
10 2 
3 2 
3 2 

1
5 1 2
1 2

*/ 
