#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define oF(l,r,i) for(int i=l;i<=r;i++)
#define of(l,r) oF(l,r,i)
#define tF(n,i) oF(1,n,i)
#define tf(n) tF(n,i)
#define nF(i) tF(n,i)
#define nf() nF(i)
#define mF(i) tF(m,i)
#define mf() mF(i)
#define pint pair<int,int>
#define mp make_pair
#define f first
#define s second
#define fin(x) freopen(#x".in","r",stdin)
#define fout(x) freopen(#x".out","w",stdout)
#define file(x) (fin(x),fout(x))
#define Read(x) (fin(x),read())
#define READ(x) (file(x),read())
ll read(){
	int x=0;
	char c=getchar();
	while(c<48||c>57)c=getchar();
	while(c>47&&c<58){
		x=(x<<1)+(x<<3)+(c^48);
		c=getchar();
	}
	return x;
}
void write(ll x){
	if(x>9ll)write(x/10);
	putchar(x%10|48);
}
char gtch(){
	char c=getchar();
	while(c<33)c=getchar();
	return c;
}
//int T=read();
//int T=Read(assign1);
int T=READ(assign);
pint s[100005];
#define mod 1000000007
int p[1<<16|5],p16[1<<16|5];
int Lp(int x){
	return p16[x>>16]*p[x&((1<<16)-1)]%mod;
}
void solve(){
	int n=read(),m=read(),v=read();
	mf()s[i].f=read(),s[i].s=read();
	tf(1<<16)p[i]=p[i-1]*v%mod;
	tf(1<<16)p16[i]=p16[i-1]*p[1<<16]%mod;
	sort(s+1,s+m+1);
	int ans=Lp((s[1].f-1<<1));
	tf(m-1){
		if(s[i].f==s[i+1].f){
			if(s[i].s^s[i+1].s)return write(0),putchar(10),void();
			continue;
		}
		else (ans*=((Lp(s[i+1].f-s[i].f<<1)-(v-1)*Lp(s[i+1].f-s[i].f-1)%mod)%mod+mod)%mod)%=mod;
	}
	write(ans*Lp(n-s[m].f<<1)%mod);putchar(10);
}
signed main(){
//	cerr<<T<<'\n';
	p[0]=p16[0]=1;
	while(T--)solve();
	cerr<<"times: "<<(clock()*1./CLOCKS_PER_SEC)<<" s";
}
//May all the beauty be blessed
