#include <bits/stdc++.h>
#define int long long
#define mod 1000000007
#define N 100005
using namespace std;
int n, m, v, invv, ans;

struct node {
	int x, v;
	bool operator <(const node &a) {
		return x < a.x;
	}
} a[N];

inline int read() {
	int x = 0, m = 1;
	char ch = 0;
	while (!isdigit(ch)) {
		if (ch == '-') m = -1;
		ch = getchar();
	}
	while (isdigit(ch)) {
		x = (x << 1) + (x << 3) + ch - 48;
		ch = getchar();
	}
	return x * m;
}

inline int ksmi(int a, int b) {
	int res = 1;
	while (b) {
		if (b & 1) res = res * a % mod;
		a = a * a % mod;
		b >>= 1;
	}
	return res;
}

struct jz {
	int a[3][3];
	jz() {
		a[1][1] = a[2][2] = 1;
		a[1][2] = a[2][1] = 0;
	}
	jz operator *(const jz &x) {
		jz res;
		res.a[1][1] = (a[1][1] * x.a[1][1] % mod + a[2][1] * x.a[1][2] % mod) % mod;
		res.a[1][2] = (a[1][2] * x.a[1][1] % mod + a[2][2] * x.a[1][2] % mod) % mod;
		res.a[2][2] = (a[1][1] * x.a[2][1] % mod + a[2][1] * x.a[2][2] % mod) % mod;
		res.a[2][2] = (a[1][2] * x.a[2][1] % mod + a[2][2] * x.a[2][2] % mod) % mod;
		return res;
	}
} o;

inline jz ksmi(jz a, int b) {
	jz res;
	while (b) {
		if (b & 1) res = res * a;
		a = a * a;
		b >>= 1;
	}
	return res;
}

inline int get(int x) {
	jz now;
	now.a[2][1] = v, now.a[2][2] = 0;
	now = now * ksmi(o, x);
	return now.a[1][1];
}

signed main() {
	freopen("assign.in", "r", stdin);
	freopen("assign.out", "w", stdout);
	int T = read();
	while (T--) {
		n = read(), m = read(), v = read();
		invv = ksmi(v, mod - 2);
		o.a[1][1] = v, o.a[1][2] = invv, o.a[2][2] = 1;
		for (int i = 1; i <= m; i++) {
			a[i].x = read(), a[i].v = read();
		}
		sort(a + 1, a + 1 + m);
		bool flag = 1;
		int l = 0;
		for (int i = 1; i <= m; i++) {
			if (a[i].x == a[i - 1].x && a[i].v != a[i - 1].v) {
				flag = 0;
				break;
			}
			if (a[i].x != a[l].x) a[++l] = a[i];
		}
		if (!flag) {
			printf("0\n");
			continue;
		}
		m = l;
		ans = ksmi(v, 2 * (a[1].x - 1));
		int res;
		for (int i = 1; i < m; i++) {
			res = (v - 1) * ksmi(v, a[i + 1].x - a[i].x) % mod * get(a[i + 1].x - a[i].x - 1) % mod;
			res = (res + ksmi(v, a[i + 1].x - a[i].x - 1)) % mod;
			ans = ans * res % mod;
		}
		if (a[m].x != n) {
			res = (v - 1) * ksmi(v, n - a[m].x) % mod * get(n - a[m].x - 1) % mod;
			res = (res + ksmi(v, n - a[m].x)) % mod;
			ans = ans * res % mod;
		}
		printf("%lld\n", ans);
	}
	return 0;
}

