#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1e5+10, mod = 1e9+7;
int f[N], n,m,v;
struct qj{
	int c,d;
}a[N];

int mi(int x,int k) {int p; return k?p=mi(x,k/2),p*p%mod*(k&1?x:1)%mod:1;}
signed main() {
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int T; cin>>T;
	while(T--) {
		memset(a,0,sizeof a);
		memset(f,0,sizeof f);
		cin>>n>>m>>v;
		for(int i=1;i<=m;i++) {
			cin>>a[i].c>>a[i].d;
		}
		sort(a+1,a+m+1,[](qj x, qj y) {
			return x.c < y.c;
		});
		int fllgg = 1;
		for(int i=1;i<m;i++) {
			if(a[i].c == a[i+1].c && a[i].d != a[i+1].d) fllgg = 0;
		}
		int _m = 0;
		for(int i=1;i<=m;i++) {
			if(a[i].c != a[_m].c || a[i].d != a[_m].d) a[++_m] = a[i];
		}
		m = _m;
		if(fllgg == 0) {
			cout << 0 << endl;
			continue;
		}
		f[1] = mi(v, (a[1].c-1) * 2);
		for(int i=2;i<=m;i++) {
			f[i] = (f[i-1] * mi(v, (a[i].c - a[i-1].c) * 2) % mod - f[i-1] * mi(v, a[i].c - a[i-1].c - 1) % mod * (v-1) % mod + mod ) % mod;
//			cout << i <<" " << f[i-1] << ' ' << (a[i].c - a[i-1].c) * 2 << ' ' <<  a[i].c - a[i-1].c << endl;
		}
		if(a[m].c == n) cout << f[m];
		else cout << f[m] * mi(v,((n-1) - a[m].c + 1) * 2) % mod;
		cout << endl;
	}
	return 0;
}

