#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5,mod = 1e9 + 7;
int T,n,m,v,ans;
pair <int,int> l[N];
int ksm(int x,int y)
{
	int ret = 1;
	while(y)
	{
		if(y & 1) ret = 1LL * ret * x % mod;
		x = 1LL * x * x % mod,y >>= 1;
	}
	return ret;
}
int main()
{
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	scanf("%d",&T);
	while(T--)
	{
		scanf("%d%d%d",&n,&m,&v);
		for(int i = 1;i <= m;i++) scanf("%d%d",&l[i].first,&l[i].second);
		sort(l + 1,l + m + 1);
		m = unique(l + 1,l + m + 1) - l - 1;
		bool flag = false;
		for(int i = 1;i < m;i++)
			if(l[i].first == l[i + 1].first && l[i].second != l[i + 1].second)
			{
				flag = true;
				break;
			}
		if(flag)
		{
			puts("0");
			continue;
		}
		ans = 1LL * ksm(v,2 * (l[1].first - 1)) * ksm(v,2 * (n - l[m].first)) % mod;
		for(int i = 1;i < m;i++)
			ans = 1LL * ans * (ksm(v,2 * (l[i + 1].first - l[i].first)) - 1LL * ksm(v,l[i + 1].first - l[i].first - 1) * (v - 1) % mod + mod) % mod;
		printf("%d\n",ans);
	}
	return 0;
}
