#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll mod=1e9+7;
const int M=1e6+7;
ll qpow(ll a,ll b){
	ll res=1ll;
	while(b){
		if(b&1)res=res*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return res;
}
int t;
ll n,m,v,c,ans,tmp,lst,sum,p[M],tt;
map<ll,ll> vis;
int main(){
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	scanf("%d",&t);
	while(t--){
		ans=1ll,tmp=0ll,lst=0ll,sum=0ll;
		int ff=0;vis.clear();
		scanf("%lld%lld%lld",&n,&m,&v);
		for(int i=1;i<=m;i++){
			scanf("%lld%lld",&p[i],&tt);
			if(vis[p[i]]&&vis[p[i]]!=tt)ff=1;
			vis[p[i]]=tt;
		}
		if(ff){
			printf("0\n");
			continue;
		}
		sort(p+1,p+m+1);p[m+1]=n;
		for(ll i=m;i>=1;i--){
			if(p[i]==n){
				tmp=v-1;continue;
			}
			if(p[i]==p[i+1])continue;
			ll c=p[i];lst=p[i+1];
			tmp=tmp*qpow(v,lst-c-1)%mod;
			ans=(ans*qpow(v,2ll*(lst-c))%mod-tmp+mod)%mod;
			//out<<v<<" "<<c<<" "<<lst<<" "<<tmp<<" "<<ans<<" "<<tmp+ans<<endl;
			tmp=((tmp+ans*v%mod)%mod-ans%mod+mod)%mod;
		}
		ans=ans*qpow(v,2ll*(p[1]-1))%mod;
		printf("%lld\n",ans);
		//if(ans==797858048)cout<<n<<" "<<m<<" "<<p[1]<<" "<<p[2]<<" "<<v<<endl;
 }
}
