#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll N=1e5+5,M=1e6+5,P=1e9+7;
ll T,n,m,v;
struct node{
	ll x,y;
}a[N];
bool cmp(node x,node y){
	if(x.x!=y.x)
	return x.x<y.x;
	return x.y<y.y;
}
ll fp(ll a,ll b){
	ll res=1;
	while(b>0){
		if(b&1)res=res*a%P;
		b>>=1,a=a*a%P;
	}
	return res;
}
int main(){
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	scanf("%lld",&T);
	while(T--){
		scanf("%lld%lld%lld",&n,&m,&v);
		for(ll i=1;i<=m;i++){
			scanf("%lld%lld",&a[i].x,&a[i].y);
		}
		sort(a+1,a+m+1,cmp);
		bool fl=0;
		for(ll i=1;i<m;i++){
			if(a[i].x==a[i+1].x&&a[i].y!=a[i+1].y){
				printf("0\n");
				fl=1;
				break;
			}
		}
		if(fl==1){
			continue;
		}
		ll ans=fp((v*v%P),(n-1));
		for(int i=1;i<m;i++){
			for(int j=i+1;j<=m;j++){
				ans=(ans-fp(v,a[j].x-a[i].x-1)+P)%P;
			}
		}
		printf("%lld\n",ans);
	}
	return 0;
}
