#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
using namespace std;
const int N = 1e5 + 10;
long long mod;
long long T,n,m,v,ans,res;
struct my_node{
	long long c,d;
}a[N];
bool my_cmp(my_node p,my_node q){
	return (p.c<q.c)||(p.c==q.c&&p.d<q.d);
}
long long my_p(long long k,long long b){
	long long r = 1;
	while(b)
	{
		if(b&1) r = r*k%mod;
		k = k * k%mod;
		b >>= 1; 
	}
	return r%mod;
}
int main(){
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout); 
	
	bool flag;
	mod = 1e9 + 7;
	scanf("%lld",&T);
	while(T--)
	{
		flag = 0;
		bool ok = 0;
		ans = res = 0;
		scanf("%lld %lld %lld",&n,&m,&v);
		for(int i=1;i<=m;i++)
		{
			scanf("%lld %lld",&a[i].c,&a[i].d);
		}
		sort(a+1,a+m+1,my_cmp);
		for(int i=2;i<=m;i++)
		{
			if(a[i].c==a[i-1].c&&a[i].d!=a[i-1].d)
			{
				flag = 1;
				printf("0\n");
				break;
			}
			if(a[i].c==a[i-1].c+1)
			{
				ok = 1;
			}
			
		}
		if(flag) continue;
		ans = my_p(v,(n-1)*v);
		ans = (ans-res)%mod;
		printf("%lld\n",ans%mod);
	}
	//bye bye
	return 0;
}
