#include<bits/stdc++.h>
using namespace std;
int t,n,m,v,a[100005],zzz;
long long pw[105],ans,ans2;
const int mod=1e9+7;
long long solve(int x)
{
	long long sum=1;
	for (int i=1;i<=20;i++)
	{
		if (x%2==1)
		{
			sum*=pw[i];
			sum%=mod;
		}
		x/=2;
	}
	return sum;
}
int main()
{
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	cin>>t;pw[0]=1;
	while (t--)
	{
		cin>>n>>m>>v;pw[1]=v;ans=0;ans2=0;
		map<int,int> p;
		for (int i=2;i<=20;i++)
		{
			pw[i]=pw[i-1]*pw[i-1];
			pw[i]%=mod;
		}
		ans=solve(n-1);
		ans*=ans;
		ans%=mod;
		bool pd=true;
		scanf("%d%d",&a[1],&zzz);
		p[a[1]]=zzz;
		for (int i=2;i<=m;i++)
		{
			scanf("%d%d",&a[i],&zzz);
			if (p[a[i]]!=0&&p[a[i]]!=zzz) pd=false;
			p[a[i]]=zzz;
		}
		sort(a+1,a+m+1);
		if (pd==false)
		{
			cout<<0<<endl;
			continue;
		}
		int sumsum=0;
		for (int i=2;i<=m;i++)
		{
			if (a[i]==a[i-1]) continue;
			long long gg=solve(a[i]-a[i-1]-1)*(v-1);
			gg%=mod;
			gg*=solve(n-a[i]+a[i-1]-1)*solve(n-a[i]+a[i-1]-1);
			for (int j=2;j<i;j--)
			{
				int ggg=golve(a[j]-a[j-1]-1)*(v-1)*solve(a[i]-a[i-1]-1)*(v-1);
				ggg%=mod;
				if (j!=i-1)
				ggg*=solve(n-a[i]+a[i-1]-1-a[j]+a[j-1]-1)*solve(n-a[i]+a[i-1]-1-a[j]+a[j-1]-1);
				else
				ggg*=solve(n-a[i]+a[i-1]-1-a[j]+a[j-1])*solve(n-a[i]+a[i-1]-1-a[j]+a[j-1]);
				gg-=ggg;
			}
			ans2+=gg;
			ans2%=mod;
		}
		ans-=ans2;
		if (ans<0) ans+=mod;
		cout<<ans<<endl;
	}
	return 0;
}
