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

const int MXN = 100005;
const int DVS = 1e9 + 7;
int T, N, M, V, ans, V2;
pair<int, int> lim[MXN];

inline int pw(int b, int p) {
  int a(1);
  while (p) {
    if (p & 1) a = a * 1LL * b % DVS;
    b = b * 1LL * b % DVS;
    p >>= 1;
  }
  return a;
}

int main() {
  freopen("assign.in", "r", stdin);
  freopen("assign.out", "w", stdout);
  for (scanf("%d", &T); T--;) {
    scanf("%d %d %d", &N, &M, &V);
    for (int i(0); i != M; ++i)
      scanf("%d %d", &lim[i].first, &lim[i].second),
      --lim[i].first, --lim[i].second;
    sort(lim, lim + M);
    ans = pw(V2 = V * 1LL * V % DVS, lim[0].first);
    ans = ans * 1LL * pw(V2, N - 1 - lim[M - 1].first) % DVS;
    for (int i(0); i != M - 1; ++i) {
      int d(lim[i + 1].first - lim[i].first);
      if (!d) {
        if (lim[i].second != lim[i + 1].second) {
          ans = 0;
          break;
        }
        continue;
      }
      ans = ans * 1LL *
            (pw(V2, d) + DVS - pw(V, d - 1) * 1LL * (V - 1) % DVS) % DVS;
    }
    printf("%d\n", ans);
  }
  return 0;
}
