FunKingDoor @ 2024-12-14 08:57:00
#include <iostream>
#include <map>
#include <algorithm>
using namespace std;
#define int long long
const int MXM = 1e5 + 5;
const int mod = 1e9 + 7;
int c[MXM];
int qpow(int x, int b) {
int ans = 1;
while(b) {
if(b & 1) ((ans *= x) += mod * 100) %= mod;
((x *= x) += mod * 100) %= mod;
b >>= 1;
}
return ans;
}
signed main() {
int T;
cin >> T;
while(T--) {
int n, m, v;
cin >> n >> m >> v;
//v %= mod;
map<int, int> mp;
for(int i = 1; i <= m; i++) {
int d;
cin >> c[i] >> d;
if(mp[c[i]] != 0 && mp[c[i]] != d)
mp[114514] = 1919810;
mp[c[i]] = d;
}
if(mp[114514] == 1919810) {
cout << 0 << endl;
continue;
}
sort(c + 1, c + m + 1);
c[m + 1] = n;
int ans = qpow(v * v % mod, c[1] - 1);
ans %= mod;
for(int i = 1; i <= m - 1; i++) {
if(c[i + 1] == c[i]) continue;
((ans *= qpow(v * v % mod, c[i + 1] - c[i]) - qpow(v, c[i + 1] - c[i] - 1) * (v - 1)) += mod) %= mod;
ans %= mod;
ans += mod * 100;
ans %= mod;
}
ans *= qpow(v * v % mod, n - c[m]);
ans %= mod;
ans += mod * 100;
ans %= mod;
cout << ans << endl;
}
return 0;
}