#include <bits/stdc++.h>
using namespace std;
const int p = 1e9 + 7;
typedef long long ll;

int t,n,m,v,dp[20][2][2],a[20];
struct info{
	int c,d;
}x[100010];

bool cmp(info a,info b){
	return a.c < b.c;
}

ll ksm(ll a,ll b){
	a %= p;
	ll ans = 1;
	while(b){
		if(b & 1)
			ans = (ans * a) % p;
		a = (a * a) % p;
		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(int i = 1;i <= m;i++)
			scanf("%d%d",&x[i].c,&x[i].d);
		sort(x + 1,x + m + 1,cmp);
		bool flag = 1;
		for(int i = 2;i <= m;i++)
			if(x[i].c == x[i - 1].c && x[i].d != x[i - 1].d){
				puts("0");
				flag = 0;
				break;
			}
		if(!flag)
			continue;
		ll ans = 1;
		for(int i = 1;i <= m;i++){
			if(x[i].c == x[i - 1].c)
				continue;
			if(i == 1)
				ans *= ksm(ksm(v,2),x[i].c - 1) % p;
			else if(x[i].c == x[i - 1].c + 1)
				ans *= (v + 1ll * (v - 1) * (v - 1) % p) % p, ans %= p;
			else 
				ans *= ksm(ksm(v,2),x[i].c - x[i - 1].c - 1) * v % p * (v - 1) % p * (x[i].c - x[i - 1].c) % p, ans %= p;
		}if(x[m].c != n)
			ans *= ksm(ksm(v,2),n - x[m].c) % p;
		printf("%lld\n",ans % p);
	}
}
