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

const int N = 1e5 +10, MOD = 1e9 + 7;

int t, n, m, v;
int ans, cnt1, cnt2, sum, tot, cnt;
pair<int, int> a[N];
vector<int> g;

int qpow(int, int);
void dfs(int, int);

signed main()
{
    freopen("assign.in", "r", stdin);
    freopen("assign.out", "w", stdout);
    scanf("%lld", &t);
    while(t--)
    {
        cnt1 = cnt2 = 0;
        scanf("%lld%lld%lld", &n, &m, &v);
        for (int i = 1; i <= m; i++)
        {
            int l, r;
            scanf("%lld%lld", &l, &r);
            a[i] = make_pair(l, r);
        }
        sort(a + 1, a + m + 1);
        for (int i = 1; i < m; i++)
        {
            if (a[i].first == a[i + 1].first && a[i].second != a[i + 1].second)
            {
                printf("0\n");
                goto end;
            }
        }
        m = unique(a + 1, a + m + 1) - a - 1;
        for (int i = 1; i <= m; i++)
        {
            if (a[i].first == 1)
                continue;
            if (i > 1 && a[i - 1].first +1 == a[i].first)
                cnt1++;
            else
                cnt2++;
            if (i > 1)
            {
                if (a[i].first - a[i - 1].first >1)
                    g.push_back(a[i].first - a[i - 1].first + 1);
                cnt2 += a[i].first - a[i - 1].first - 1;
            }
            else
            {
                cnt2 += a[i].first - 1;
            }
        }
        if (n > a[m].first)
        {
            cnt2 += n - a[m].first;
        }
        ans = (qpow(v * v % MOD, cnt2) * qpow(1 + v * (v - 1) % MOD, cnt1)) % MOD;
        for (int i = 1; i <= g.size(); i++)
        {
            cnt = 0;
            sum = 0;
            tot = 0;
            dfs(1, i);
            if (i & 1)
                ans = ans + MOD - tot;
            else
                ans = ans + tot;
            ans = ans % MOD;
        }
        printf("%lld\n", ans);
        end:;
    }
}

void dfs(int x, int y)
{
    if (g.size() - x + 1 < y - cnt)
        return;

    if (x == g.size() + 1)
    {
        tot += qpow(v * v % MOD, cnt2 - sum) * qpow(1 + v * (v - 1), cnt1) % MOD;
        tot %= MOD;
        return;
    }
    for (int i = x - 1; i < g.size(); i++)
    {
        cnt++;
        sum += g[i];
        dfs(i + 2, y);
        sum -= g[i];
        cnt--;
    }
}

int qpow(int x, int k)
{
    int res = 1;
    while (k)
    {
        if (k & 1)
        {
            res = res *x;
            res = res % MOD;
        }
        x *= x;
        x %= MOD;
        k >>= 1;
    }
    return res;
}
