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

typedef long long ll;

const ll maxm=1e5+100, mod=1e9+7;
struct xianz {
	long long c, d;
	bool operator < (xianz &other){
		return c < other.c;
	}
	bool operator == (xianz &other){
		return c==other.c && d==other.d;
	}
} xz[maxm];

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

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	freopen("assign.in", "r", stdin);
	freopen("assign.out", "w", stdout);
	
	int t;
	cin >> t;
	while(t--){
//		memset(xz, 0, sizeof xz);
		long long n, m, v;
		cin >> n >> m >> v;
		for (int i=1; i<=m; i++){
			cin >> xz[i].c >> xz[i].d;
		}
		
		sort(xz+1, xz+m+1);
		m = unique(xz+1, xz+m+1) - (xz+1);
		
		ll ans=1;
		bool ansis0 = false;
		for (int i=2; i<=m; i++){
			if (xz[i].c == xz[i-1].c){
				ansis0 = true;
				break;
			}
			
			ll thans = qpow(v, 2*(xz[i].c-xz[i-1].c));
			ll noans = qpow(v, xz[i].c-xz[i-1].c-1);
			noans = noans * (v-1) % mod;
			ans *= (thans-noans+mod) % mod;
			ans %= mod;
//			printf("thans=%d, noans=%d\n", thans, noans);
		}
		
		if (m){
			ans *= qpow(v, 2*(xz[1].c-1));
			ans %= mod;
			ans *= qpow(v, 2*(n-xz[m].c));
			ans %= mod;
		} else {
			ans *= qpow(v, 2*(n-1));
			ans %= mod;
		}
		
		if (ansis0){
			cout << "0\n";
		} else {
			cout << ((ans+mod)%mod) << '\n';
		}
	}
	
	
	return 0;
}
 
