#include <iostream>
#include <cstring>
#include <cstdio>
#include <map>
#include <algorithm>
#define ll long long

using namespace std;
const ll MOD = 1000000007;
const int N = 10010;
map<ll,ll>a;
ll b[N],c[N],f[N],g[N],cnt;

ll qp(ll x,ll y)
{
	if(y < 0) return 1;
	ll res = 1;
	while(y)
	{
		if(y&1) res = res * x % MOD;
		x = x * x % MOD;
		y>>=1;
	}
	return res;
}

int main()
{
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	int T;
	cin>>T;
	while(T--)
	{
		a.clear();
		memset(b,0,sizeof(b));
		memset(f,0,sizeof(f));
		memset(g,0,sizeof(g));
		int n,m,v,i,j,k,cnt = 0;
		ll ans = 0;
		bool flag = 0;
		cin>>n>>m>>v;
		for(i = 1;i <= m;i++)
		{
			int x,y;
			cin>>x>>y;
			if(a[x]&&a[x] != y) flag = 1;
			b[i] = x;
			a[x] = y;
		}
		if(flag)
		{
			cout<<0<<endl;
			continue;
		}
		sort(b + 1,b + m + 1);
		cnt = unique(b + 1,b + m + 1) - (b + 1);
//		cout<<cnt<<endl;
//		if(cnt == 1)
//		{
//			cout<<qp(v * v % MOD,n - 1)<<endl;
//			continue;
//		}
        ll s = 0,hf = 1; 
		for(i = 1;i < cnt;i++)
		{
			ll len = b[i + 1] - b[i];
			s = (s + len) % MOD;
			ll x = 1;
			f[i] = (f[i - 1] + x * qp(v * v,len - 2) * v % MOD * (v - 1) * hf * qp(v * v % MOD,n - s - 1) % MOD) % MOD;
			hf = hf * (qp(v * v,len) - qp(v * v,len - 2) * v % MOD * (v - 1));
		}
		ans = (qp(v * v % MOD,n - 1) + MOD - f[cnt - 1]) % MOD;
		cout<<ans<<endl;
	}
	return 0;
}
