#include <bits/stdc++.h>
#define LL long long
#define sl(s) strlen(s)
#define endline puts("")
#define pii pair<int, int>
#define pr_q priority_queue
#define debug puts("DEBUG.")
using namespace std;
const int N = 1e5 + 10;
const int inf = ~0u >> 2;
const int p = 1e9 + 7;
inline int qpow(int a , int k)
{
	int res = 1;
	while(k)
	{
		if(k & 1)
			res = 1ll * res * a % p;
		a = 1ll * a * a % p,k >>= 1;
	}
	return res;
}
int ct,n,m,v;
pii pr[N];
#define fir first
#define sec second
inline int getmod(int x)
{
	return x >= p ? x - p : x;
}
inline int calc(int n , int v)
{
	int pw = qpow(v , n - 2);
	int pwv = 1ll * pw * v % p;
	return getmod(1ll * pwv * (pwv - 1) % p + pw);
}
int main()
{
	freopen("assign.in" , "r" , stdin);
	freopen("assign.out" , "w" , stdout);
	cin >> ct;
	while(ct--)
	{
		scanf("%d%d%d" , &n , &m , &v);
		for(int i = 1;i <= m;i++)
			scanf("%d%d" , &pr[i].fir , &pr[i].sec);
		sort(pr + 1 , pr + m + 1);
		int ans = 1;
		for(int i = 1;i <= m - 1;i++)
		{
			if(pr[i].fir == pr[i + 1].fir)
			{
				if(pr[i].sec == pr[i + 1].sec)
					continue;
				ans = 0;
				break;
			}
			ans = 1ll * ans * calc(pr[i + 1].fir - pr[i].fir + 1 , v) % p;
		}
		ans = 1ll * ans * qpow(v , pr[1].fir - 1 + n - pr[m].fir << 1) % p;
		printf("%d\n" , ans);
	}
	return 0;
}
// ¹þÆ¤ 
