#include<bits/stdc++.h>
#define int long long
#define pii pair<int,int>
using namespace std;
const int maxn=1e5+10,mod=1e9+7;
int t,n,m,v,cnt,flag,ans;
pii a[maxn],b[maxn];
int po(int x,int y)
{
	int res=1ll,r=x;
	for(int i=y;i;i>>=1)
	{
		if(i&1) res=res*r%mod;
		r=r*r%mod;
	}
	return res;
}
signed main()
{
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	cin>>t;
	while(t--)
	{
		cnt=flag=0;
		cin>>n>>m>>v;
		for(int i=1;i<=m;i++) cin>>a[i].first>>a[i].second;
		sort(a+1,a+m+1);
		b[++cnt]=a[1];
		for(int i=2;i<=m;i++)
			if(a[i].first==a[i-1].first&&a[i].second!=a[i-1].second)
			{
				cout<<0<<endl;
				flag=1;
				break;
			}
			else if(a[i]!=b[cnt]) b[++cnt]=a[i];
		if(flag) continue;
		ans=po(v*v%mod,b[1].first-1+n-b[cnt].first);
		for(int i=2;i<=cnt;i++) ans=ans*(po(v*v%mod,b[i].first-b[i-1].first)-po(v,b[i].first-b[i-1].first-1)*(v-1+mod)%mod+mod)%mod;
	}
	return 0;
}
/*
2
7 1 2
4 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
*/
