#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod=1000000007;
ll qpow(ll x,ll y){
	if(!y)return 1ll;
	ll t=qpow(x,y/2);
	if(y&1)return t*t%mod*x%mod;
	else return t*t%mod;
}
ll solve(ll x,ll y,ll dis,ll v){
	if(x==0||y==0||dis==0)return qpow(v,dis*2);
	return (qpow(v,dis*2)+mod+qpow(v,dis-1)-qpow(v,dis))%mod;
}
struct Q{
	int lim,lim2;
}q[100005];
bool cmp(Q x,Q y){return(x.lim<y.lim);}
template<typename T>inline void read(T &x){
	x=0;char c='-';
	while(c<'0'||c>'9')c=getchar();
	while(c>='0'&&c<='9'){
		x=x*10+c-'0';
		c=getchar(); 
	}
	return;
}
int main(){
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	q[0].lim=1;
	int T;read(T);
	while(T--){
		int n,m,v;
		read(n);read(m);read(v);
		ll ans=1;
		for(int i=1;i<=m;i++){
			read(q[i].lim);
			read(q[i].lim2);
		}
		sort(q+1,q+m+1,cmp);
		for(int i=1;i<=m;i++){
			if(q[i].lim==q[i+1].lim&&q[i].lim2!=q[i+1].lim2)ans=0;
			ans*=solve(q[i-1].lim2,q[i].lim2,q[i].lim-q[i-1].lim,v);
			ans%=mod;
		}
		ans*=solve(q[m].lim2,0,n-q[m].lim,v);
		ans%=mod;
		cout<<ans<<endl;
	}
	return 0;
}
