#include<bits/stdc++.h>
#define ll long long
#define fo(i,j,k) for(register ll i=j;i<=k;++i)
using namespace std;
const ll N=1e6+5,mod=1e9+7;
ll n,m,T,c,u,v,dp[N];
int main(){
	freopen("traverse.in","r",stdin);
//	freopen("traverse.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	cin>>c>>T;
	dp[2]=1;
//	fo(i,3,10000){
//		fo(j,2,i-1){
//			dp[i]+=dp[i-1]*i-1;
//		}
//		dp[i]++;
//		dp[i]%=mod;
//	}
	while(T--){
		cin>>n>>m;
		fo(i,1,n){
			cin>>u>>v;
		}
		if(c==18){
			cout<<1<<endl;
			continue;
		}
		cout<<(dp[n]*m)%mod;
	}
	return 0;
}
