#include <iostream>
#include <utility>
#include <algorithm>

using namespace std;
using lint=long long;
const int maxn=1e5+18;
const int mod=1e9+7; 

char buf[1<<20], *p1, *p2;
#define getc() (p1==p2 && (p2=(p1=buf)+fread(buf, 1, 1<<20, stdin))==p1? EOF:*p1++)
using in_t =lint;
in_t read(in_t ret=0, char c=0){
	while ('9'<c||c<'0') c=getc();
	while ('0'<=c&&c<='9')
		ret=ret*10+(c^48), c=getc();
	return ret;
}

int n, m;
lint v;
lint ans=0;
struct loc{
	int c;
	lint d;
	
	bool operator == (loc const& b) const{
		return c==b.c && d==b.d;
	}	
} l[maxn];

lint qpow(lint e, int x){
	lint ret=1;
	while (x){
		if (x&1) ret=(ret*e)%mod;
		e=e*e%mod;
		x>>=1;
	} return ret;
}

int main(){
	int i, j, k;
	cout.tie(0), ios::sync_with_stdio(0);
	freopen("assign.in", "r", stdin);
	freopen("assign.out", "w", stdout);
	
	int t=read();
	while (t--){
		n=read(), m=read(), v=read();
		if (t==0) cerr<<n<<" "<<m<<" "<<v<<'\n';
		
		for (i=1; i<=m; ++i)
			l[i].c=read(), l[i].d=read();
		
		sort(l+1, l+m+1, [&](loc a, loc b){
			return a.c==b.c? a.d>b.d : a.c>b.c;
		});
		m=unique(l+1, l+m+1)-l-1;
		
		lint ans=1;
		bool outf=0;
		
		ans=(ans * qpow(v, (n-l[1].c)<<1))%mod;
		for (i=1; i<m; ++i){
			if (l[i].c==l[i+1].c)
				{ outf=1; break; }
			if (l[i].c>l[i+1].c+1)
				ans=(ans * qpow(v, (l[i].c-l[i+1].c)<<1))%mod;
			else ans=(ans * (v*v%mod - v + 1))%mod;
		}
		ans=(ans * qpow(v, (l[m].c-1)<<1))%mod;
		
		if (outf) cout<<"0\n";
		else cout<<ans<<'\n';
	}
	
	return 0;
}
