#include<bits/stdc++.h>
#define ll long long
#define db double
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define debug(...) fprintf(stderr,__VA_ARGS__)
using namespace std;
bool mem1;
namespace MATT{
const int maxn=1e5+10,mod=1e9+7;
int n,m,v;
pii a[maxn];
namespace FastMod{
	inline void madd(int &x,int y){x+=y;(x>=mod)&&(x-=mod);}
	inline void mdel(int &x,int y){x-=y;(x<0)&&(x+=mod);}
	inline void mmul(int &x,int y){x=1ll*x*y%mod;}
	inline int imadd(int x,int y){madd(x,y);return x;}
	inline int imdel(int x,int y){mdel(x,y);return x;}
	inline int immul(int x,int y){mmul(x,y);return x;}
	inline int qpow(int x,int y){int res=1;while(y){if(y&1)mmul(res,x);mmul(x,x);y>>=1;}return res;}
}
using namespace FastMod;
int dp[maxn];
void matt(){
	scanf("%d%d%d",&n,&m,&v);swap(n,m);
	for(int i=1;i<=n;i++)	scanf("%d%d",&a[i].fi,&a[i].se);
	sort(a+1,a+n+1);
	for(int i=1;i<=n;i++)
		if(a[i].fi==a[i+1].fi&&a[i].se!=a[i+1].se)	return puts("0"),void();
	n=unique(a+1,a+n+1)-a-1;
	if(n<=1)	return printf("%d\n",qpow(v,m+m-2)),void();
	dp[1]=qpow(v,a[1].fi+a[1].fi-2);
	for(int i=2;i<=n;i++){
		int res=immul(v-1,qpow(v,a[i].fi-a[i-1].fi-1));
		res=imdel(qpow(v,(a[i].fi-a[i-1].fi)*2),res);
		dp[i]=immul(dp[i-1],res);
	}
	int ans=dp[n];mmul(ans,qpow(v,(m-a[n].fi)*2));
	printf("%d\n",ans);
}
}
bool mem2;
int main(){
	freopen("assign.in","r",stdin);freopen("assign.out","w",stdout);
	int T=1;scanf("%d",&T);while(T--) MATT::matt();
}
