#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int maxn=1e9+10, maxm=1e5+10, mod=1e9+7;
typedef long long ll;
int t, n, m, v;
struct P{
	ll c, d;
	bool operator<(struct P &obj)
	{
		return c<obj.c;
	} 
	bool operator==(struct P &obj)
	{
		return c==obj.c;
	}
}p[maxm];
ll ans=0;
inline ll fpow(ll a, ll n)
{
	ll r=1;
	while(n)
	{
		if(n&1) r=(r*a)%mod;
		a=(a*a)%mod;
		n>>=1;
	}
	return r%mod;
}
ll res(int k)
{
	if(k==-1) return 1;
	return v*((v-1)*fpow(v,2*k)%mod+res(k-1))%mod;
}
void solve()
{
	cin>>n>>m>>v;
	for(int i=0;i<m;i++)
		cin>>p[i].c>>p[i].d;
	sort(p, p+m);
	for(int i=0;i<m-1;i++)
	{
		if(p[i].c==p[i+1].c&&p[i].d!=p[i+1].d) {
			cout<<0<<endl;
			return;
		}
	}
	m = unique(p, p+m)-p;
	ans=fpow(v,2*(p[0].c+n-p[m-1].c-1));
	for(int i=0;i<m-1;i++)
	{
		ans=(ans*res(p[i+1].c-p[i].c-1))%mod; 
	}
	cout<<(ans)%mod<<endl; 
}
int main()
{
	ios::sync_with_stdio(false);
	freopen("assign.in", "r", stdin);
	freopen("assign.out", "w", stdout);
	
	cin>>t;
	while(t--)solve();
	
	fclose(stdin);
	fclose(stdout);
	return 0; 
}
