#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
using namespace std; bool MEM;
using ll=long long; using ld=long double;
using pii=pair<int,int>; using pll=pair<ll,ll>;
const int I=1e9;
const ll J=1e18,N=1e5+7,P=1e9+7;
ll qp(ll x,ll y=P-2) { return y?(y&1?x:1)*qp(x*x%P,y>>1)%P:1; }
ll n,m,v,dp[N];
pll b[N];
void mian() {
	scanf("%lld%lld%lld",&n,&m,&v);
	for (ll i=1;i<=m;i++) scanf("%lld%lld",&b[i].fi,&b[i].se);
	sort(b+1,b+m+1),m=unique(b+1,b+m+1)-1-b;
	for (ll i=1;i<=m;i++) if (b[i].se<1||b[i].se>v) return cout<<"0\n",void();
	for (ll i=1;i<m;i++) if (b[i].fi==b[i+1].fi&&b[i].se!=b[i+1].se) return cout<<"0\n",void();
	dp[1]=qp(v,(b[1].fi-1)*2);
	for (ll i=2;i<=m;i++) {
		ll k=b[i].fi-b[i-1].fi;
		dp[i]=dp[i-1]*(qp(v,k*2)+P-qp(v,k-1)*(v-1)%P)%P;
	}
	cout<<dp[m]*qp(v,(n-b[m].fi)*2)%P<<"\n";
}
bool ORY; int main() {
//	freopen("assign3.in","r",stdin);
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
//	while (1)
	int t; for (scanf("%d",&t);t--;)
	mian();
	cerr<<"\n"<<abs(&MEM-&ORY)/1048576<<"MB";
	return 0; 
}
