#include <iostream>
#include <cstdio>
#include <algorithm>
#define mod 1000000007
using namespace std;
typedef long long ll; 
ll t,n,m,v;
pair<ll,ll>a[100001];
ll ksm(ll x,ll y) {
	ll res=1;
	while(y) {
		if(y&1) res=res*x%mod;
		x=x*x%mod;
		y>>=1;
	}
	return res;
}
void work() {
	scanf("%lld%lld%lld",&n,&m,&v);
	for(int i=1;i<=m;++i) scanf("%lld%lld",&a[i].first,&a[i].second);
	sort(a+1,a+m+1);
	m=unique(a+1,a+m+1)-a-1;
	for(int i=2;i<=m;++i)
		if(a[i].first==a[i-1].first) {
			puts("0");
			return;
		}
	ll ans=ksm(v*v%mod,a[1].first-1+n-a[m].first);
	for(int i=2;i<=m;++i) {
		ll x=a[i].first-a[i-1].first;
		ans=ans*(ksm(v*v%mod,x)-ksm(v,x)+ksm(v,x-1))%mod;
	}
	printf("%lld\n",(ans+mod)%mod);
}
int main() {
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	scanf("%lld",&t);
	while(t--) work();
	return 0;
}
