#include<algorithm>
#include<iostream>
#define ll long long
using namespace std;
const int N=1e5+5;
const ll mod=1e9+7;
ll T,n,m,v;
struct node{
	ll idx,val;
	bool operator == (const node t)const{
		return t.idx==idx&&val==t.val;
	}
}a[N];
ll qpow(ll a,ll b){
	ll ret=1;
	while(b){
		if(b&1)ret=ret*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return ret;
}
void solve(){
	cin>>n>>m>>v;
	for(int i=1;i<=m;++i)cin>>a[i].idx>>a[i].val;
	sort(a+1,a+1+m,[](node x,node y){
		return (x.idx^y.idx)?x.idx<y.idx:x.val<y.val;
	});
	for(int i=2;i<=m;++i)if(a[i].idx==a[i-1].idx&&a[i].val!=a[i-1].val){
		cout<<"0\n";
		return;
	}
	m=unique(a+1,a+1+m)-a-1;
	if(m==1){
		cout<<qpow(v*v%mod,n-1)<<endl;
		return;
	}
	ll t1,t2,ans=1;
	for(int i=2;i<=m;++i){
		t1=qpow(v,a[i].idx-a[i-1].idx-1);
		t1=t1*(v-1)%mod;
		t2=qpow(v*v%mod,a[i].idx-a[i-1].idx);
		ans=ans*(t2+mod-t1)%mod;
	}
	ans=ans*qpow(v*v%mod,a[1].idx-1)%mod*qpow(v*v%mod,n-a[m].idx)%mod;
	cout<<ans<<endl;
}
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--)solve();
	return 0;
}
