#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
const int mod = 1e9 + 7;
long long T,n,m,v;
struct ty{
	long long c,d;
}a[maxn];
bool cmp(ty x,ty y)
{
	return x.c < y.c;
}
long long quick(long long x,int k)
{
	long long res = 1;
	while(k > 0)
	{
		if(k % 2 == 1)
			res = res * x % mod,k--;
		k /= 2,x = x * x % mod;
	}
	return res;
}
int main()
{
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);	
	scanf("%lld",&T);
	while(T--)
	{
		memset(a,0,sizeof(a));
		a[0].c = -1;
		scanf("%lld%lld%lld",&n,&m,&v);
		long long flag = 0,cnt = 0;//next
		for(int i = 1;i <= m;i++)
			scanf("%lld%lld",&a[i].c,&a[i].d);
		sort(a + 1,a + m + 1,cmp);
		for(int i = 1;i <= m;i++)
		{
			if(a[i].c == a[i - 1].c && a[i].d != a[i - 1].d)
				flag = 1;
			else if(a[i].c == a[i - 1].c + 1)
				cnt++;
		}
		if(flag == 1)
		{
			printf("0\n");
			continue;
		}
		long long ans = quick(v * v % mod,n - 1 - cnt)
					  * quick((v * (v-1) % mod + 1) % mod,cnt) % mod;
		printf("%lld\n",ans);
	}
	
}
/*
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
*/

