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

typedef long long ll;

#define rep(i, a, b) for(int i = (a); i <= (b); ++i)
#define per(i, a, b) for(int i = (a); i >= (b); --i)
#define pil pair<int, ll>
#define fi first
#define se second
#define mkp make_pair
bool Mst;

const int maxn = 1e5 + 5;
const ll mod = 1e9 + 7;

int n, m; ll v;
pil b[maxn];

struct Matrix{
	ll a[2][2];
	Matrix(){ a[0][0] = a[0][1] = a[1][0] = a[1][1] = 0ll; }
};

inline Matrix operator *(Matrix x, Matrix y){
	Matrix z;
	for(int i : {0, 1}) for(int k : {0, 1}) for(int j : {0, 1})
		(z.a[i][j] += x.a[i][k] * y.a[k][j] % mod) %= mod;
	return z;
}

inline Matrix pwM(Matrix x, int p){
	Matrix res; res.a[0][0] = res.a[1][1] = 1ll;
	while(p){
		if(p & 1) res = res * x;
		p >>= 1; x = x * x;
	} return res;
}

inline void slv(){
	cin >> n >> m >> v;
	rep(i, 1, m) cin >> b[i].fi >> b[i].se;
	
//	cout << "complete input" << '\n';
	
	sort(b + 1, b + m + 1);
	
	Matrix res, bs[2]; int Begin = 1;
	bs[0].a[0][0] = v * v % mod, bs[0].a[0][1] = 0ll, bs[0].a[1][0] = (v * v % mod + mod - v) % mod, bs[0].a[1][1] = v % mod;
	bs[1].a[0][0] = 0ll, bs[1].a[0][1] = v * v % mod, bs[1].a[1][0] = 0ll, bs[1].a[1][1] = (v * v % mod + mod - v + 1) % mod;
	
	if(b[1].fi == 1) res.a[0][1] = 1ll, ++Begin;
	else res.a[0][0] = 1ll, b[0].fi = 1;
	
	rep(i, Begin, m){
		if(i > 1 and b[i].fi == b[i - 1].fi and b[i].se != b[i - 1].se){
			cout << 0 << '\n';
			return;
		} else if(b[i].fi == b[i - 1].fi) continue;
			
		res = res * pwM(bs[0], b[i].fi - b[i - 1].fi - 1);
		res = res * bs[1];
	}
	
//	cout << (res.a[0][0] + res.a[0][1]) % mod << '\n';
	
	res = res * pwM(bs[0], n - b[m].fi);
	
	ll ans = (res.a[0][0] + res.a[0][1] + mod) % mod;
	
	cout << ans << '\n'; 
}

bool Med;
signed main(){
//	return system("fc assign3.ans assign.out"), 0;
	
	freopen("assign.in", "r", stdin); freopen("assign.out", "w", stdout);
	
	fprintf(stderr, "%.2lfMB\n", abs(&Mst - &Med) / 1024. / 1024.);
	
	ios_base::sync_with_stdio(0); cin.tie(NULL), cout.tie(NULL);
	
	int T; cin >> T;
	while(T--) slv();
	return 0;
}
/*
1
7 1 2
4 1

4
5 1 2
1 2
6 5 2
4 2
5 1
4 2
2 2
2 1
7 1 2
4 1

1
10 11 2
10 2
7 2
7 2
2 2
3 2
4 2
10 2
7 2
10 2
3 2
3 2
*/
