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

typedef long long ll;

const int N = 1e6 + 106;
const ll MOD = 1e9 + 7;

int T;
ll n, m, v;
ll f[N][2];
pair<int, int> lim[N];

struct matrix {
    ll a[2][2];
    int n, m;
}bg, fn, trans;

matrix mult(matrix a, matrix b) {
    matrix res;
    res.n = a.n, res.m = b.m;
    for(int i = 0; i < res.n; i++) {
        for(int j = 0; j < res.m; j++) {
            res.a[i][j] = 0;
            for(int k = 0; k < a.m; k++) {
                res.a[i][j] += a.a[i][k] * b.a[k][j] % MOD;
                res.a[i][j] %= MOD;
            }
        }
    }
    return res;
}

matrix qpow(matrix bas, ll exp) {
    matrix res;
    res.n = 2, res.m = 2;
    res.a[0][0] = 1, res.a[0][1] = 0;
    res.a[1][0] = 0, res.a[1][1] = 1;
    while(exp) {
        if(exp & 1ll)
            res = mult(res, bas);
        bas = mult(bas, bas);
        exp >>= 1ll;
    }
    return res;
}

int main() {
    freopen("assign.in", "r", stdin);
    freopen("assign.out", "w", stdout);
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> T;
    for(; T; --T) {
        cin >> n >> m >> v;
        int ans = 1;
        for(int i = 1; i <= m; i++) {
            int c, d;
            cin >> c >> d;
            lim[i].first = c, lim[i].second = d;
        }
        sort(lim + 1, lim + m + 1);
        for(int i = 1; i < m; i++) {
            if(lim[i].first == lim[i + 1].first && lim[i].second != lim[i + 1].second)
                ans = 0;
        }
        if(!ans) {
            cout << "0\n";
            continue;
        }
        f[0][0] = f[0][1] = 0;
        if(lim[1].first == 1) f[0][1] = 1;
        else f[0][0] = 1;
        lim[0].first = 1;
        for(int i = 1; i <= m; i++) {
            if(lim[i].first == lim[i - 1].first) {
                f[i][0] = f[i - 1][0], f[i][1] = f[i - 1][1];
                continue;
            }
            // nxp : lim[i].first, bef = lim[i - 1].first
            ll len = lim[i].first - lim[i - 1].first - 1;
            trans.n = 2, trans.m = 2;
            trans.a[0][0] = 1ll * v * v % MOD, trans.a[0][1] = 0,
            trans.a[1][0] = 1ll * v * (v - 1ll) % MOD, trans.a[1][1] = v;
            trans = qpow(trans, len);
            bg.n = 1, bg.m = 2;
            bg.a[0][0] = f[i - 1][0], bg.a[0][1] = f[i - 1][1];
            fn = mult(bg, trans);
            f[i][1] = 1ll * fn.a[0][0] * v % MOD * v % MOD + 1ll * fn.a[0][1] * v % MOD * (v - 1ll) % MOD + fn.a[0][1];
            f[i][1] %= MOD;
            f[i][0] = 0;
        }
        ll len = n - lim[m].first;

        trans.n = 2, trans.m = 2;
        trans.a[0][0] = 1ll * v * v % MOD, trans.a[0][1] = 0,
        trans.a[1][0] = 1ll * v * (v - 1ll) % MOD, trans.a[1][1] = v;
        trans = qpow(trans, len);
        bg.n = 1, bg.m = 2;
        bg.a[0][0] = f[m][0], bg.a[0][1] = f[m][1];
        fn = mult(bg, trans);

        cout << (fn.a[0][0] + fn.a[0][1]) % MOD << '\n';
    }
    return 0;
}
