#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int N=1e5+5, P=1e9+7;
ll pos[N]; 
ll n, m, v;
map<ll, ll> val;
ll fsp(ll a, ll b) {
	ll c=1;
	for(; b; b>>=1, a=a*a%P)
		if(b&1) c=c*a%P;
	return c;
}
void Sol() {
	scanf("%lld %lld %lld", &n, &m, &v); val.clear();
	int fl=1;
	for(int i=1; i<=m; i++) {
		ll vl;
		scanf("%lld %lld", &pos[i], &vl);
//		cout<<pos[i]<<" "<<vl<<"??";
		if(val.count(pos[i])&&val[pos[i]]!=vl) fl=0;
		else val[pos[i]]=vl;
	}
	if(!fl) {
		printf("0\n");
		return ;
	}
	sort(pos+1, pos+1+m);
	m=unique(pos+1, pos+1+m)-pos-1;
	
	if(!m) {
		printf("%lld\n", fsp(v*v%P, n-1));
		return ;
	}
	ll ans=fsp(v*v%P, (pos[1]-1)+(n-pos[m]));
	for(int i=1; i<m; i++) {
		ll len=pos[i+1]-pos[i];
//		if(len==1) continue ;
		ll al=fsp(v*v%P, len);
		ll dv=fsp(v, len-1)*(v-1)%P;
//		cout<<al<<" "<<dv<<endl;
		ans=ans*(al-dv+P)%P;
	} 
	printf("%lld\n", ans);
}
int main() {
	freopen("assign.in", "r", stdin);
	freopen("assign.out","w",stdout);
	int T; 
	scanf("%d", &T);
	while(T--) Sol();
	return 0;
} 
