#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
const int maxm = 1e5 + 5;
const ll mod = 1e9 + 7;
struct node
{
	ll c, d;
	bool operator <(const node p) const
	{
		return c < p.c;
	}
	bool operator ==(const node p) const
	{
		return (c == p.c && d == p.d);
	}
}ifs[maxm];

ll fpow(ll a, ll b)
{
	ll ans = 1;
	while(b)
	{
		if(b % 2)
			ans = ans * a % mod;
		a = a * a % mod;
		b >>= 1;
	}
	return ans % mod;
}

void work()
{
	ll n,m;
	ll v;
	scanf("%lld%lld%lld", &n,&m, &v);
	for(int i = 1; i <= m; i++)
		scanf("%lld%lld", &ifs[i].c, &ifs[i].d);
	ll ans = fpow(v * v % mod, n - 1);
	for(int i = 2; i <= m; i ++)
	{
		if(ifs[i - 1].c == ifs[i].c && ifs[i].d != ifs[i - 1].d)
		{
			puts("0");
			return ;
		}
	}
	sort(ifs + 1, ifs + m + 1);
	unique(ifs + 1, ifs + m + 1);
	for(int i = 1; i < m; i ++)
		if(ifs[i].c >= ifs[i + 1].c)
		{
			m = i;
			break; 
		}
	if(m == 1)
	{
		printf("%lld\n", ans);
		return ;
	}
	int st = 1, ed = 1;
	if(ifs[1].c + 1 != ifs[2].c)
		st = 2;
	for(int i = 2; i <= m ;i ++ )
	{
		if(ifs[i - 1].c + 1 == ifs[i].c)
		{
			ed = i;
//			ans = (ans - v + 1 + mod) % mod;
		}
		if(ifs[i - 1].c + 1 != ifs[i].c || i == m)
		{
			//printf("%d\n", ed - st + 1);
			int cnt = ed - st + 1;
			st = ed = i;
			if(cnt == 1)
				continue;
			ans = (((ans - fpow(v * v % mod, cnt - 1) + mod + fpow((v * v % mod - v + mod + 1) % mod, cnt - 1)) % mod) + mod) % mod;
		}
	}
	printf("%lld\n", ans);
	return ;
}

int main()
{
	freopen("assign.in","r",stdin);
	freopen("assign.out", "w", stdout);
	int t;
	scanf("%d", &t);
	while(t--)
		work();
	return 0;
}

/*
3
2 1 2
1 1
2 2 2
1 1
2 2
2 2 2
1 1
1 2

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

1
12 2 2
7 2
7 2
*/
