#include <iostream>
#include <cstdio>
#include <map>
using namespace std;

typedef unsigned long long ll; 
ll n, m, v; 

const ll mod=1e9+7;  
const ll maxn=1e5+5; 
ll a[maxn]; 
ll dp[5][5]; 

ll readint(){
	char c=getchar(); 
	while (c < '0' || c > '9') c=getchar(); 
	ll ret=0; 
	while (c >= '0' && c <= '9') {
		ret *= 10; 
		ret += c-'0';
		c=getchar(); 
	}
	return ret; 
}

struct matrix{
	ll f[3][3]; 
	matrix operator*(matrix other) const {
		matrix ret;
		ret.f[1][1] = (f[1][1]*other.f[1][1]+f[1][2]*other.f[2][1])%mod; 
		ret.f[1][2] = (f[1][1]*other.f[1][2]+f[1][2]*other.f[2][2])%mod; 
		ret.f[2][1] = (f[2][1]*other.f[1][1]+f[2][2]*other.f[2][1])%mod; 
		ret.f[2][2] = (f[2][1]*other.f[1][2]+f[2][2]*other.f[2][2])%mod; 
		return ret; 
	} 
};
matrix base; 

matrix qpow(matrix base, ll k){
	matrix ret;
	ret.f[1][1] =1;
	ret.f[1][2] = 0;
	ret.f[2][1] = 0;
	ret.f[2][2] = 1;
	while (k){
		if (k&1) ret = ret*base; 
		base = base*base; 
		k >>= 1; 
	}
	return ret; 
}

pair<ll, ll> Get(ll f0, ll f1, ll k){
	matrix tmp=qpow(base, k); 
	return {f0*tmp.f[1][1]%mod, (f0*tmp.f[1][2]+f1*tmp.f[2][2])%mod}; 
}

void solve(){
	ll now=0, bef=1;  
	n = readint(); 
	m = readint(); 
	v = readint(); 
	base.f[1][1] = v%mod; 
	base.f[1][2] = (v-1)*v%mod; 
	base.f[2][1] = 0; 
	base.f[2][2] = v*v%mod; 
	
	map<ll, ll> a; 
	for (ll i=1; i<=m; i++){
		ll x, v;
		x = readint(); 
		v = readint(); 
		if (a.count(x) && a[x]!=v) {
			cout << 0 << endl;
			return; 
		}
		a[x] = v; 
	}
	ll l=2; 
	if (a.count(1)){
		dp[1][0] = 1; 
		dp[1][1] = 0;
		a.erase(1); 
	} else {
		dp[1][0] = 0;
		dp[1][1] = 1;
	}
	while (a.size()){
		auto it=a.begin();  
		auto tmp=Get(dp[bef][0], dp[bef][1], (it->first)-l); 
		l = it->first+1; 
		dp[now][0] = tmp.first; 
		dp[now][1] = tmp.second;  
		now ^= 1;
		bef ^= 1; 
		dp[now][0] = dp[bef][1]*v%mod*v%mod; 
		dp[now][0] += dp[bef][0]*(v*(v-1)%mod+1)%mod;  
		dp[now][1] = 0; 
		//cout << it->first << ' ' << dp[bef][0] << ' ' << dp[bef][1] << endl; 
		now ^= 1;
		bef ^= 1; 
		a.erase(it); 
		//cout << it->first << ' ' << dp[bef][0] << ' ' << dp[bef][1] << endl; 
	}
	auto tmp=Get(dp[bef][0], dp[bef][1], n+1-l); 
	cout << (tmp.first+tmp.second)%mod << endl; 
	
	/*
	for (ll i=2; i<=n; i++){
		if (a[i]){
			dp[i][0] = dp[i-1][1]*v*v; // ai=any bi=any
			dp[i][0] %= mod; 
			dp[i][0] += dp[i-1][0]*(v*(v-1)+1); // ai=any!=c bi=any or ai=c bi=c
			dp[i][0] %= mod; 
			dp[i][1] = 0; 
		} else {
			dp[i][0] = dp[i-1][0]*v; 
			dp[i][0] %= mod; 
			dp[i][1] = dp[i-1][0]*((v-1)*v); 
			dp[i][1] %= mod; 
			dp[i][1] += dp[i-1][1]*v*v; 
			dp[i][1] %= mod; 
		}
	}
	cout << dp[n][0]+dp[n][1] << endl; 
	*/
}

int main(){
	freopen("assign.in", "r", stdin); 
	freopen("assign.out", "w", stdin); 
	ll t;
	t = readint(); 
	while (t--) solve(); 
	return 0; 
}

