#include<cstdio>
#include<algorithm>
using namespace std;
const int N=1e5+5,mod=1e9+7;
#define ll long long
int T,n,m; ll v,ans,vv; struct node{int c,d;}a[N];
bool cmp(node x,node y){return x.c<y.c;}
bool operator==(node x,node y){return x.c==y.c;}
ll qpow(ll a,int b){
	if(b<0) return 0;
	ll res=1ll;
	for(;b;b>>=1){
		if(b&1) res=res*a%mod;
		a=a*a%mod;
	}
	return res;
}
void sol(){
	scanf("%d%d%lld",&n,&m,&v); ans=1ll; vv=v*v%mod;
	for(int i=1;i<=m;++i)
		scanf("%d%d",&a[i].c,&a[i].d);
	std::sort(a+1,a+m+1,cmp);
	for(int i=1;i<m;++i)
		if(a[i].c==a[i+1].c&&a[i].d!=a[i+1].d){puts("0"); return;}
	m=unique(a+1,a+m+1)-a-1;
	for(int i=1;i<=m;++i)
		if(a[i].c>1){
			if(i>1) (ans*=(qpow(vv,a[i].c-a[i-1].c)-qpow(v,a[i].c-a[i-1].c-1)*(v-1)%mod+mod)%mod)%=mod;
			else (ans*=qpow(vv,a[i].c-1))%=mod;
		}
//	printf(":::%lld\n",ans);
	(ans*=qpow(vv,n-a[m].c))%=mod;
	printf("%lld\n",ans);
}
int main(){
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	scanf("%d",&T); while(T--) sol();
	return 0;
}
