#include <bits/stdc++.h>
#define FileIO_(file) \
    freopen (file ".in", "r", stdin); \
    freopen (file ".out", "w", stdout);

using namespace std;

namespace Main {

namespace IO {

void read () {}

template<typename Tp, typename... Args>
void read (Tp &x, Args&... rest) {
    int c = getchar (); x = 0;
    while (!isdigit (c)) c = getchar ();
    do x = (x << 1) + (x << 3) + (c & 15);
    while (isdigit (c = getchar ()));
    read (rest...);
}

template<typename Tp>
void write (Tp x) {
    static int top, wr[50];
    do wr[++top] = x % 10; while (x /= 10);
    while (top) putchar (wr[top--] | 48);
}

} // namespace IO

using namespace IO;
using ll = long long;

const ll mod = 1e9 + 7;
const int maxm = 1e5 + 20;
int n, m, v;
ll ans;

struct Node {
    int c, d;
} a[maxm];

void add (ll &x, ll y) {
    if ((x += y) >= mod) x -= mod;
}

void sub (ll &x, ll y) {
    if ((x -= y) < 0) x += mod;
}

ll qpow (ll x, ll d) {
    ll res = 1ll;
    while (d) {
        if (d & 1) res = res * x % mod;
        x = x * x % mod; d >>= 1;
    }
    return res;
}

void solve () {
    read (n, m, v);
    for (int i = 1; i <= m; ++i) {
        read (a[i].c, a[i].d);
    }
    sort (a + 1, a + m + 1,
        [] (const Node &lhs, const Node &rhs) {
            return lhs.c < rhs.c;
        }
    );
    int num = m, m = 1;
    for (int i = 2; i <= num; ++i) {
        if (a[i].c == a[m].c) {
            if (a[i].d != a[m].d) {
                puts ("0");
                return;
            }
        } else {
            a[++m] = a[i];
        }
    }
    ans = qpow (v, 2 * ((a[1].c - 1) + (n - a[m].c)));
    for (int i = 2; i <= m; ++i) {
        int d = a[i].c - a[i - 1].c;
        (ans *= (qpow (v, d) + mod - 1) * qpow (v, d) % mod + qpow (v, d - 1)) %= mod;
    }
    write (ans); putchar (10);
}

int main () {
    int t; read (t);
    while (t--) solve ();
    return 0;
}

} // namespace Main

int main () {
    FileIO_("assign");
    return Main::main ();
}