// MagicDark #include #define debug cerr << "\33[33m[" << __LINE__ << "]\33[m " #define all(x) x.begin(), x.end() #define SZ(x) ((int) x.size() - 1) #define ms(x, y) memset(x, y, sizeof x) #define F(i, x, y) for (int i = (x); i <= (y); ++i) #define DF(i, x, y) for (int i = (x); i >= (y); --i) using namespace std; typedef long long ll; typedef unsigned long long ull; template T& chkmin(T& x, T y) {return x = min(x, y);} template T& chkmax(T& x, T y) {return x = max(x, y);} template T& read(T& x) { x = 0; int f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = - 1; for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48); return x *= f; } const int N = 1e5 + 10, MOD = 1e9 + 7; int n, m, v; // f[2], nf[2]; pair t[N]; int power(int x, int y = MOD - 1) { int ans = 1; for (; y; x = (ll) x * x % MOD, y >>= 1) if (y & 1) ans = (ll) ans * x % MOD; return ans; } void add(int& x, ll y) { x = (x + y) % MOD; } void zhk() { read(n), read(m), read(v); F(i, 1, m) { read(t[i].first), read(t[i].second); } sort(t + 1, t + m + 1); // int f[2]; // ms(f, 0); // f[0] = 1; // int vv = (ll) v * v % MOD; // int w = power(((ll) v * v - 1) % MOD); int ans = 1; F(i, 1, m) { if (t[i].first == t[i - 1].first) { if (t[i].second != t[i - 1].second) { cout << 0 << '\n'; return; } continue; } if (i == 1) { ans = power(v, (t[i].first - 1) * 2); } else { // ans = (ll) ans * power(vv, t[i].first - 1); int len = t[i].first - t[i - 1].first - 1; ans = (ll) ans * (power(v, 2 * len + 2) - (ll) (v - 1) * power(v, len) % MOD + MOD) % MOD; // add(s, power(v, )); } } ans = (ll) ans * power(v, (n - t[m].first) * 2) % MOD; // ans = (ans + MOD) cout << ans << '\n'; // if (t[m].first ) } signed main() { freopen("assign.in", "r", stdin); freopen("assign.out", "w", stdout); int _; read(_); while (_--) zhk(); return 0; } /* why */