#include<bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
int T, n, m, v;
struct pix{int id, x;} a[100005];
bool cmp(pix A, pix B){return (A.id == B.id) ? (A.x < B.x) : (A.id < B.id);}
long long fpow(long long ds, int zs){
	long long ans = 1;
	while(zs){
		if(zs & 1) ans = ans * ds % mod;
		zs >>= 1, ds = ds * ds % mod;
	} return ans;
}
int main(){
	freopen("assign.in", "r", stdin);
	freopen("assign.out", "w", stdout);
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> T;
	while(T--){
		cin >> n >> m >> v;
		for(int i = 1; i <= m; i++) cin >> a[i].id >> a[i].x;
		sort(a + 1, a + m + 1, cmp); bool flag = false;
		for(int i = 1; i < m; i++) if(a[i].id == a[i + 1].id && a[i].x != a[i + 1].x){flag = true; break;}
		if(flag){cout << 0 << endl; continue;}
		long long ans = fpow(1ll * v * v % mod, a[1].id - 1 + n - a[m].id);
		for(int i = 1; i < m; i++){
			if(a[i].id == a[i + 1].id) continue;
			ans = ans * (fpow(1ll * v * v % mod, a[i + 1].id - a[i].id) + mod - 1ll * (v - 1) * fpow(v, a[i + 1].id - a[i].id - 1) % mod) % mod;
		}
		cout << ans << endl; continue;
	}
	return 0;
}
