#include <bits/stdc++.h>
#define ll long long
#define P 1000000007
#define N 100010
using namespace std;
int T, m;
ll n, v;
struct node {
    int c;
    ll d;
} a[N];
ll qpow(ll x, ll y) {
    if(y == 0) return 1;
    if(y & 1) return x * qpow(x, y - 1) % P;
    ll tmp = qpow(x, y / 2);
    return tmp * tmp % P;
}
void solve() {
    scanf("%lld %d %lld", &n, &m, &v);
    ll vv = qpow(v, 2);
    for(int i = 1; i <= m; i ++) {
        scanf("%d %lld", &a[i].c, &a[i].d);
    }
    sort(a + 1, a + 1 + m, [](const auto &x, const auto &y) {
        if(x.c == y.c) return x.d < y.d;
        return x.c < y.c;
    });
    for(int i = 1; i < m; i ++) {
        if(a[i].c == a[i + 1].c && a[i].d != a[i + 1].d) {
            printf("0\n");
            return ;
        }
    }
    ll ans = 1;
    // 从首项第一项前都可以随便赋值
    ans *= qpow(vv, a[1].c - 1);
    for(int i = 1; i < m; i ++) {
        if(a[i].c == a[i + 1].c && a[i].d == a[i + 1].d) continue;
        // 容斥
        ll tot = qpow(vv, a[i + 1].c - a[i].c);
        (tot += P - qpow(v, a[i + 1].c - a[i].c - 1) * (v - 1) % P) %= P;
        (ans *= tot) %= P;
    }
    // 从最后一项开始都可以随便赋值
    (ans *= qpow(vv, n - a[m].c)) %= P;
    printf("%lld\n", ans);
}
int main() {
    freopen("assign.in", "r", stdin);
    freopen("assign.out", "w", stdout);
    scanf("%d", &T);
    while(T --) {
        solve();
    }
}