#include <bits/stdc++.h>
#define ll long long
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define _rep(i,a,b) for(int i=(a);i>=(b);--i)
#define eb emplace_back
#define MISAKA main
#define FIO(FILE) freopen(FILE".in","r",stdin),freopen(FILE".out","w",stdout)
using namespace std;
bool __st;
inline int read(){
	char c=getchar();int x=0,f=1;
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while('0'<=c&&c<='9') x=(x<<3)+(x<<1)+(c^48),c=getchar();
	return x*f;
}
const int N=1e5+10,mod=1e9+7;
int n,m,v,d[N],f[1010][1010];
void misaka(){
	rep(i,1,n)rep(j,1,v) f[i][j]=0;
	n=read(),m=read(),v=read();
	rep(i,1,m){
		int x=read();
		d[x]=read();
	}
	f[1][d[1]]=1;
	rep(i,1,n-1){
		if(!d[i+1]){
			f[i+1][0]=1ll*f[i][0]*v%mod*v%mod;
			rep(j,1,v){
				rep(k,1,v) (f[i+1][k]+=f[i][j])%=mod;
				(f[i+1][0]+=1ll*(v-1)*v%mod*f[i][j]%mod)%=mod;
			}
		}
		else{
			f[i+1][d[i+1]]=1ll*v*v%mod*f[i][0]%mod;
			rep(j,1,v) (f[i+1][d[i+1]]+=1ll*((v-1)*v%mod+1)*f[i][j]%mod)%=mod;
		}
	}
	int ans=0;
	rep(i,0,v) (ans+=f[n][i])%=mod;
	printf("%d\n",ans);
}
bool __ed;
signed MISAKA(){
	FIO("assign");
	int T=read();
	while(T--) misaka();
	return 0;
}

