#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define ll long long
using namespace std;
const int N=1e5+5;
const ll P=1e9+7; 
int Takanashi_Hoshino;
ll n, m, v, ans, t, p;
// ÌØÅÐv=1, dÖØ¸´£¡

struct Node{
	ll c, d;
	Node(){}
	bool operator < (const Node X)const{
		if(c==X.c) return d < X.d;
		return c < X.c;
	}
}a[N];
inline ll fast_pow(ll a, ll b){
	ll res = 1;
	while(b){
		if(b & 1) res = (res * a) % P;
		a = (a * a) % P;
		b >>= 1;
	}
	return res;
}

int main(){
	freopen("assign.in", "r", stdin);
	freopen("assign.out", "w", stdout);
	ios::sync_with_stdio(false);
	cin>>Takanashi_Hoshino;
	while(Takanashi_Hoshino--){
		cin>>n>>m>>v;
		if(v==1){ cout<"1\n"; continue; }
		ans = 1;
		for(int i=1; i<=m; i++) cin>>a[i].c>>a[i].d;
		sort(a+1, a+m+1, less<Node>());
		
//		cout<<"Contri "<<fast_pow(v, 2*a[1].c-2)<<endl;
		ans = fast_pow(v, 2*a[1].c-2);
		for(int i=2; i<=m; i++){
			if(a[i].c==a[i-1].c){
				if(a[i].d == a[i-1].d) continue;
				else{ v=0; break; } 
			}
			ll x = a[i].c - a[i-1].c;
			t = ((v-1) * fast_pow(v, 2*x-1) % P + P) % P; // ai != di
			p = ((fast_pow(v, 2*x-1) - fast_pow(v, x-1) * (v-1) % P) % P + P) % P;
			ans = ((ans * (p+t)) % P + P) % P;
//			cout<<"Contri "<<p+t<<endl;
		}
		t = fast_pow(v, 2*(n-a[m].c));
		ans = (ans * t) % P;
//		cout<<"Contri "<<t<<endl;
		cout << (ans + P) % P << '\n';
	}
	return 0; 
}
