#include <bits/stdc++.h>
using namespace std;

const int maxn = 1e5 + 5;
const int mod = 1e9 + 7;

int n, m, v;
pair<int, int> lim[maxn];

int qpow(int a, int n) {
    int ans = 1;
    for (; n; n >>= 1, a = 1ll * a * a % mod)
        if (n & 1) ans = 1ll * ans * a % mod;
    return ans;
}

int main() {
    freopen("assign.in", "r", stdin);
    freopen("assign.out", "w", stdout);
    int T;
    scanf("%d", &T);
    while (T--) {
        scanf("%d%d%d", &n, &m, &v);
        for (int i = 1; i <= m; ++i)
            scanf("%d%d", &lim[i].first, &lim[i].second);
        sort(lim + 1, lim + m + 1);
        m = unique(lim + 1, lim + m + 1) - lim - 1;
        int ans = qpow(v, 2 * (lim[1].first - 1));
        for (int i = 1; i < m; ++i) {
            int k = lim[i + 1].first - lim[i].first - 1;
            if (k < 0) {
                ans = 0;
                break;
            }
            ans = ans * (0ll + qpow(v, 2 * k + 2) - qpow(v, k + 1) + qpow(v, k) + mod) % mod;
        }
        ans = 1ll * ans * qpow(v, 2 * (n - lim[m].first)) % mod;
        printf("%d\n", ans);
    }
    return 0;
}
