#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
long long T,n,m,v,c,d,ans,t,f,s,k;
struct str
{
	long long i,x;
}a[10010];
bool cmp(str x,str y)
{
	return x.i<y.i;
}
long long kp(long long a,long long b)
{
	long long c=1;
	a%=mod;
	while(b)
	{
		if(b&1)
		c=(c*a)%mod;
		a=(a*a)%mod;
		b>>=1;
	}
	return c%mod;
}
int main()
{
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	cin>>T;
	while(T--)
	{
		cin>>n>>m>>v;
		t=kp(v,2);
		for(int i=1;i<=m;i++)
		{
			cin>>c>>d;
			a[i].i=c,a[i].x=d;
		}
		sort(a+1,a+m+1,cmp);
		f=s=k=0;
		ans=1;
		for(int i=2;i<=m+1;i++)
		{
			if(a[i].i==a[i-1].i)
			{
				if(a[i].x!=a[i-1].x)
				{
					ans=0;
					break;
				}
				continue;
			}
			if(a[i].i-1==a[i-1].i)
			{
				k++,f=1,s++;
			}
			else if(f)
			{
				if(i!=m+1) s+=4,k+=2,ans=(ans*(t+1)*(t+1))%mod;
				ans=(ans*kp((t-v+1),k))%mod,k=0,f=0;
			}
		}
		ans=(ans*kp(t,(n-1-s)))%mod;
		cout<<ans<<endl;
	}
	return 0;
}

