// Luogu uid = 608273
#include <bits/stdc++.h>
#define endl '\n'

using namespace std;

using ll = long long;

const ll N = 1e5 + 5, P = 1e9 + 7;

ll n, m, v, ans;
struct node {
	ll id, val;
} a[N];

void init() {}

ll qpow(ll base, ll exp) {
	ll res = 1;
	while (exp) {
		if (exp & 1) res = res * base % P;
		base = base * base % P;
		exp >>= 1;
	}
	return res;
}

void solve() {
	cin >> n >> m >> v;
	for (int i = 1; i <= m; ++i) cin >> a[i].id >> a[i].val;
	sort(a + 1, a + m + 1, [](node x, node y) {
		return x.id < y.id;
	});
	ll t = 1;
	for (int i = 2; i <= m; ++i) {
		if (a[i].id == a[t].id) {
			if (a[i].val != a[t].val) return cout << (ans = 0) << endl, void();
		}
		else a[++t] = a[i];
	}
	m = t;
	ans = 1;
	for (int i = 1; i <= m; ++i) {
		if (i != m && a[i].id + 1 == a[i + 1].id) (ans *= v * (v - 1) % P + 1) %= P;
		else (ans *= (v - 1) * v * (v * v + v)) %= P;
		++t;
		if (a[i].id == 1) t -= 2;
		cout << t << endl;
	}
	cout << t << endl;
	cout << ans << endl;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	freopen("assign.in", "r", stdin);
	freopen("assign.out", "w", stdout);
	// freopen(".in", "w", stdout);
	// freopen(".out", "r", stdin);
	int _ = 1;
	cin >> _;
	while (_--) solve();
	return 0;
}
/*
g++ assign.cpp -o assign.exe -std=c++14 -O2 -fno-asm -Wall
*/

/*
11:14 废了现在才开始看T2
12:46 推完了，没时间写了
	  爆零，退役
*/