#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
const int N=1e5+10;
const ll M=1e9+7;
int T,n,m,v,i,cur;
ll ans;
struct node{
	int c,d;
}a[N];
bool cmp(node a,node b){
	return a.c<b.c;
}
ll mi(ll a,ll b){
	a%=M;
	ll ans=1;
	while(b){
		if(b&1) ans=ans*a%M;
		a=a*a%M;
		b>>=1;
	}
	return ans;
}
int main(){
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	scanf("%d",&T);
	while(T--){
		scanf("%d%d%d",&n,&m,&v);
		for(i=1;i<=m;++i) scanf("%d%d",&a[i].c,&a[i].d);
		sort(a+1,a+1+m,cmp);
		ans=mi(v,2*a[1].c-2),cur=a[1].d;
		for(i=2;i<=m;++i){
			if(a[i].c!=a[i-1].c){
				cur=a[i].d;
				ans=ans*(mi(v,2*(a[i].c-a[i-1].c))-mi(v,a[i].c-a[i-1].c-1)*(v-1)%M+M)%M;
			}else if(a[i].d!=cur){
				ans=0;
				break;
			}
		}
		ans=ans*mi(v,2*(n-a[m].c))%M;
		printf("%lld\n",ans);
	}
	fclose(stdin);
	fclose(stdout);
	return 0;
}

