#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=1e6+100,mod=1e9+7;
bool f[N];
int a[3],b[3],c[3],_vx;
bool flag,del=1;
int T,n,m,v,x,d;
inline int in(){
	int a=0,f=1;
	char ch=getchar();
	for(;!isdigit(ch);ch=getchar())if(ch=='-')f=-1;
	for(;isdigit(ch);ch=getchar())a=(a<<3)+(a<<1)+ch-'0';
	return a*f;
}inline void out(int a){
	if(a<10)cout<<a;
	else{
		char ch=a%10+'0';
		out(a/10);
		putchar(ch);
	}
	return ;
}
void init(){
	memset(a,0,sizeof(a));
	memset(b,0,sizeof(b));
	memset(c,0,sizeof(c));
	memset(f,0,sizeof(f));
	flag=0;
	del=1;
	_vx=v*(v-1)%mod;
	a[1]=v;
	c[1]=0;
	b[1]=0;
	return ;
}
signed main(){
	freopen("assign.in","r",stdin); 
//	freopen("assign.out","w",stdout); 
	cin>>T;
	while(T--){
		n=in();m=in();v=in();
		init();
		for(int i=1;i<=m;i++){
			x=in();d=in();
			if(!f[x])f[x]=1;
			else{
				cout<<0<<"\n";
				flag=1; 
			}
		}if(flag)continue;
		if(f[1]){
			b[1]=1;
			a[1]--;
		}
		for(int i=2;i<=n;i++){
			del^=1;
			if(f[i]){
				a[del]=(a[del^1]*(v-1))%mod;
				b[del]=(b[del^1]+a[del^1])%mod;
				if(i>2)c[del]=(((c[del^1]+a[del^1]+b[del^1])%mod)*_vx)%mod;
			}else{
				a[del]=(a[del^1]*v)%mod; 
				b[del]=(b[del^1]*v)%mod;
				if(i>2)c[del]=((c[del^1]+a[del^1]+b[del^1])*_vx)%mod;//0 
			}
		}
		out(((a[del]+b[del])%mod+c[del])%mod);
		printf("\n"); 
	}
	return 0;
}
