#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<stack>
#include<queue>
#include<algorithm>
using namespace std;
typedef long long ll;
const ll maxn = 1e5+10;
const ll mod = 1e9+7;
ll T;
ll n,m,v;
struct node{
	int c;
	int d;
}p[maxn];
ll quick_mid(ll x,ll y){
	ll ans = 1;
	while(y){
		if(y%2) ans = (ans*x)%mod;
		x = (x*x)%mod;
		y/=2;
	}
	return ans;
}
bool cmp(node x,node y){
	return x.c < y.c;
}
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(int i = 1;i <= m;i++)
			scanf("%lld%lld",&p[i].c,&p[i].d); 
		sort(p+1,p+1+m,cmp); 
		ll ans = quick_mid((v*v)%mod,n-1);
		if(m == 1){
			printf("%lld\n",ans); 
			continue;
		}
		int flag = 1;
		for(int i = 2;i <= m;i++)
			if(p[i].c == p[i-1].c && p[i].d != p[i-1].d) flag = 0;
		if(flag == 0){
			printf("0\n");
			continue;
		} 
		for(int i = 1;i < m;i++){
			for(int j = i+1;j <= m;j++){
				ll dl = p[j].c-p[i].c;
				ll cnt = ((quick_mid((v*v)%mod,n-dl-1)*quick_mid(v-1,j-i))%mod*quick_mid(v,dl-(j-i)))%mod;
				ans = (ans-cnt+mod)%mod;	
			}
		}
		printf("%lld\n",ans);
	}
	fclose(stdin);
	fclose(stdout);
	return 0;
}

