#include<bits/stdc++.h>
#define rise(i,l,r) for(int i=l;i<=r;i++)
#define fall(i,r,l) for(int i=r;i>=l;i--)
#define db cout<<"work\n";
#define div cout<<"___________________\n";
using namespace std;
const int maxn=1e5+10,mod=1e9+7;
int T,n,v,m;
int c[maxn],d[maxn];
int num[maxn],f[maxn];
int ans=0;
int calc(int x){
	int res=1;
	rise(i,1,x){
		res*=i;
		res%=mod;
	} 
	return res;
}
bool check(){
	rise(i,1,n){
		
	}
}
void dfs(int x){
	if(x==n){
		ans+=check();
		return ;
	} 
	rise(i,1,v){
		num[x]=i;
		dfs(x+1);
	}
}
void work(){
	dfs(1);
}
int main(){
	freopen("assign.in","r",stdin);
	freopen("assign.out	","w",stdout);
	scanf("%d",&T);
	while(T--){
		scanf("%d%d%d",&n,&m,&v);
		rise(i,1,m){
			scanf("%d%d",&c[i],&d[i]);
			f[c[i]]=d[i];
		}
		ans=calc(v-1)+1;
		printf("%d\n",ans);
	}
	return 0;
}

