#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll P=1e9+7;
ll t,f,ans;
ll n,m,v,x,y;
struct abc{
	ll xx,yy;
}a[100100];
ll k[100100];
ll cmp(abc lss,abc wzc){
	if(lss.xx==wzc.xx) return lss.yy<wzc.yy;
	return lss.xx<wzc.xx;
}
int main()
{
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	scanf("%lld",&t);
	while(t--){
		ans=1;
		f=0;
		scanf("%lld%lld%lld",&n,&m,&v);
		memset(a,0,sizeof(a));
		for(ll i=1;i<=m;i++){
			scanf("%lld%lld",&x,&y);
			a[i].xx=x;
			a[i].yy=y;
		}
		if(m==1){
			for(ll i=1;i<n;i++){
				ans=(((v*v)%P)*ans)%P;
			}
			printf("%lld\n",ans);
		}
		else if(m==n){
			for(ll i=1;i<n;i++){
				ans=((((v-1)*v+1)%P)*ans)%P;
			}
			printf("%lld\n",ans);
		}
		else{
			sort(a+1,a+1+m,cmp);
			for(ll i=1;i<a[1].xx;i++){
				ans=(((v*v)%P)*ans)%P;
			}
			for(ll i=1;i<m;i++){
				if(a[i].xx==a[i+1].xx && a[i].yy!=a[i+1].yy){
					f=1;
					break;
				}
				else if(a[i].xx+1==a[i+1].xx){
					ans=((((v-1)*v+1)%P)*ans)%P;
				}
				else{
					for(ll j=a[i].xx;j<a[i+1].xx;j++){
						ans=(((v*v)%P)*ans)%P;
					}
				}
			}
			for(ll k=a[m].xx;k<n;k++){
				ans=(((v*v)%P)*ans)%P;
			}
			if(f!=1) printf("%lld\n",ans);
			else printf("0\n");
		}
	}
	return 0;
}
