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

struct JZ {
	long long c, d;
}a[100005];
const long long mod = 1e9+7;
long long t, n, m, v;
map<long long, long long> mp;
bool cmp(JZ x, JZ y) {
	return x.c < y.c;
}
int main() {
	freopen("assign.in", "r", stdin);
	freopen("assign.out", "w", stdout);
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	cin >> t;
	while (t--) {
		cin >> n >> m >> v;
		for (int i = 1; i <= m; i++) cin >> a[i].c >> a[i].d;
		sort(a+1, a+m+1, cmp);
		int cnt = 0;
		mp.clear();
		for (int i = 1; i < m; i++) {
			mp[a[i].c]++;
			if (mp[a[i].c] > 1) {
				cout << 0 << '\n';
				continue;
			}
			
			if (a[i].c+1 == a[i+1].c) cnt++;
		}
		if (mp[a[m].c] == 1) {
			cout << 0 << '\n';
			continue;
		}
		if (!cnt) {
			cout << v*v%mod << '\n';
			continue;
		}
		int sum = 0;
		for (auto i:mp) {
			if (i.second == 1) sum++;
		}
		cout << (v*(v-sum)%mod+sum)%mod << '\n';
	}
	return 0;
}
