#include<bits/stdc++.h>
#define ll long long
const ll MOD=1e9+7;
using namespace std;
void work()
{
	ll n,m,v,x[100010]={0},a,b;
	scanf("%lld%lld%lld",&n,&m,&v);
	for(int i=1;i<=m;i++)
	{
		scanf("%lld%lld",&a,&b);
		if(x[a] && b!=x[a])
		{
			cout<<0<<endl;
			return ;
		}
		x[a]=b;
	}
	ll ans=1,xy=v*v;
	for(int i=1;i<n;i++)
	{
		if(x[i] && x[i+1])
			ans*=(xy-v+1);
		else ans*=xy;
		ans%=MOD;	
	}
	cout<<ans%MOD<<endl;
}
int main()
{
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	int T;
	cin>>T;
	while(T--)
		work();
	fclose(stdin);
	fclose(stdout);
	return 0;
}
