#include<bits/stdc++.h>
using namespace std;
#define ll long long
inline int read(){
	int x=0,t=0;
	char c=getchar();
	while(c<'0'||c>'9') t|=c=='-',c=getchar();
	while(c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
	return t?-x:x;
}
inline void putc(char c){
	putchar(c);
}
inline void write(int x){
	if(x<0) putc('-'),x=-x;
	if(x>9) write(x/10);
	putc('0'+x%10);
}
inline char getc(){
	char c=getchar();
	while(c<'0'||c>'1') c=getchar();
	return c;
}
#define pii pair<int,int>
#define mpr make_pair
#define fir first
#define sec second
const int N=1e5+10,mod=1e9+7;
inline int add(int x,int y){ return x+y>=mod?x+y-mod:x+y; }
inline int dec(int x,int y){ return x>=y?x-y:x-y+mod; }
inline void inc(int &x,int y){ x=add(x,y); }
inline int qpow(int x,int y){
	int res=1;
	while(y){
		if(y&1) res=1ll*res*x%mod;
		x=1ll*x*x%mod;
		y>>=1;
	}
	return res;
}
int n,m,v;
pii a[N];
int main(){
//	system("fc assign1.out assign1.ans /n");
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	int T=read();
	while(T--){
		n=read(),m=read(),v=read();
		for(int i=1;i<=m;i++)
			a[i].fir=read(),a[i].sec=read();
		sort(a+1,a+m+1);
		m=unique(a+1,a+m+1)-a-1;
		bool fl=0;
		for(int i=1;i<m;i++)
			if(a[i].fir==a[i+1].fir&&a[i].sec!=a[i+1].sec) 
				fl=1;
		if(fl){ write(0),putc('\n');continue; }
		int v2=1ll*v*v%mod;
		int s=1;
		for(int i=2;i<=m;i++)
			s=1ll*s*dec(qpow(v2,a[i].fir-a[i-1].fir),1ll*(v-1)*qpow(v,a[i].fir-a[i-1].fir-1)%mod)%mod;
		s=1ll*s*qpow(v2,a[1].fir-1+n-a[m].fir)%mod;
//		printf("%d %d %d %d\n",c0,c1,n-1,qpow(1ll*v*v%mod,n-1));
		write(s),putc('\n');
	}
}
