#include <algorithm>
#include <iostream>
#include <cstring>
#include <utility>
#include <cstdio>
#include <vector>
#include <cmath>
#include <queue>
#define fi first
#define se second
#define mod 1000000007
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int N = 100005;
int t, n, m, q, k, ans;pii a[N];
inline void mul(int& x, int y){x = 1ll * x * y % mod;}
int qpow(int bse, int p){int ans = 1;for (;p;p >>= 1, mul(bse, bse)) if (p & 1) mul(ans, bse);return ans;}
int main(){
	freopen("assign.in", "r", stdin);
	freopen("assign.out", "w", stdout);
	scanf("%d", &t);
	while (t --){scanf("%d%d%d", &m, &q, &k), ans = 1;
		for (int i = 1;i <= q;i ++) scanf("%d%d", &a[i].fi, &a[i].se);
		sort(a + 1, a + q + 1), n = unique(a + 1, a + q + 1) - a - 1;
		for (int i = 1;i < n;i ++) if (a[i].fi == a[i + 1].fi){ans = 0;goto Nxt;}
		for (int i = 1;i < n;i ++) mul(ans, qpow(k, a[i + 1].fi - a[i].fi << 1) - (k - 1ll) * qpow(k, a[i + 1].fi - a[i].fi - 1) % mod + mod);
		mul(ans, qpow(k, a[1].fi - 1 << 1)), mul(ans, qpow(k, m - a[n].fi << 1));
		Nxt:printf("%d\n", ans);
	}
}