#include using namespace std; #define LL long long #define PII pair const int N = 1e5 + 10, mod = 1e9 + 7; namespace IO { char buf[1 << 21], *p1 = buf, *p2 = buf; inline char gc() { if(p1 == p2) p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin); return p1 == p2 ? EOF : *p1++; } inline int read() { int f = 1, w = 0; char ch = gc(); while(ch < '0' || '9' < ch) { if(ch == '-') f = -1; ch = gc(); } while('0' <= ch && ch <= '9') { w = (w << 1) + (w << 3) + (ch ^ 48); ch = gc(); } return f * w; } char obuf[1 << 21], *p3 = obuf; inline void pc(char c) { p3 - obuf <= 1 << 20 ? *p3++ = c : (fwrite(obuf, p3 - obuf, 1, stdout), p3 = obuf, *p3++ = c); } inline void write(int x) { if(x < 0) pc('-'), x = -x; if(!x) pc('0'); static char c[50]; static int tt; while(x) c[++tt] = x % 10 ^ 48, x /= 10; while(tt) pc(c[tt--]); } } using namespace IO; int n, m, v, ans; PII a[N]; LL ksm(LL x, LL y) { LL res = 1; x %= mod; while(y) { if(y & 1) res = res * x % mod; y >>= 1; x = x * x % mod; } return res; } int main() { freopen("assign.in", "r", stdin); freopen("assign.out", "w", stdout); int T = read(); while(T--) { n = read(), m = read(), v = read(); for(int i = 1; i <= m; i++) a[i].first = read(), a[i].second = read(); sort(a + 1, a + m + 1); m = unique(a + 1, a + m + 1) - a - 1; bool flag = 1; for(int i = 1; i < m; i++) if(a[i].first == a[i + 1].first) { flag = 0; break; } if(!flag) { puts("0"); continue; } ans = ksm(1ll * v * v, a[1].first - 1) * ksm(1ll * v * v, n - a[m].first) % mod; for(int i = 1; i < m; i++) ans = ans * (ksm(1ll * v * v, a[i + 1].first - a[i].first) - ksm(v, a[i + 1].first - a[i].first - 1) * (v - 1) % mod + mod) % mod; printf("%d\n", ans); } return 0; }