#include<bits/stdc++.h>
using namespace std;

using ll = long long;

const int M = 1e5 + 5;
const ll mod = 1e9 + 7;

int T,n,m,v;
pair<int,int> a[M];

ll fpw(ll x,ll p,ll s = 1){
	for(;p;p >>= 1ll,(x *= x) %= mod)
		if(p & 1ll) (s *= x) %= mod;
	return s;
}

int main(){
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	for(scanf("%d",&T);T--;){
		scanf("%d%d%d",&n,&m,&v);
		for(int i = 1;i <= m;++i) scanf("%d%d",&a[i].first,&a[i].second);
		sort(a + 1,a + m + 1),m = unique(a + 1,a + m + 1) - a - 1;
		bool flg = 0;
		for(int i = 1;i < m;++i)
			if(a[i].first == a[i + 1].first && a[i].second != a[i + 1].second) flg = 1;
		if(flg){ puts("0"); continue; }
		ll ans = fpw(v,2ll * (a[1].first - 1));
		for(int i = 1;i < m;++i){
			ll s1 = fpw(v,a[i + 1].first - a[i].first - 1);
			ll s2 = fpw(v,2ll * (a[i + 1].first - a[i].first));
			ll s3 = fpw(v,a[i + 1].first - a[i].first - 1) * (v - 1) % mod;
			(ans *= (s2 - s3 + mod) % mod) %= mod;
		}
		(ans *= fpw(v,2ll * (n - a[m].first))) %= mod;
		printf("%lld\n",ans); 
	}
	return 0;
}
