#include <bits/stdc++.h>
using namespace std;

#define LL long long
#define pb emplace_back
#define fr first
#define sc second
typedef const int Int;
typedef pair<int,int> pii;

Int N=1e5+5,M=1e9+7;

int T;

int A[N];

int n,m;
LL v;

LL dp[N];

map <int,int> Ma;

LL qpow(LL a,LL b){
	LL ret=1;
	while(b){
		if(b&1)ret=ret*a%M;
		a=a*a%M;
		b>>=1;
	}
	return ret;
}

LL apt(Int &len){
	return qpow(v,len-1)*(v-1)%M;
}

void solve(){
	Ma.clear();
	scanf("%d%d%lld",&n,&m,&v);
	for(int i=1;i<=m;i++){
		int x;
		scanf("%d%d",&A[i],&x);
		if(Ma.count(A[i])){
			if(Ma[A[i]]^x){
				printf("0\n");
				return;
			}
		}
		Ma[A[i]]=x;
	}
	sort(A+1,A+1+m);
	int cnt=unique(A+1,A+1+m)-A;
	m=cnt-1;
	dp[1]=0;
	for(int i=2;i<=m;i++){
		for(int j=1;j<i;j++)dp[i]=(apt(A[i]-A[j])*qpow(v*v%M,A[j]-1)%M+(qpow(v*v%M,A[i]-A[j])-apt(A[i]-A[j])+M)*dp[j]%M)%M;
	}
	printf("%lld\n",(qpow(v*v%M,n-1)-dp[m]*qpow(v*v%M,n-A[m])%M+M)%M);
}

int main(){
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	scanf("%d",&T);
	while(T--)solve();
	return 0;
}




















