#include <bits/stdc++.h>
#define il inline
using namespace std;

#define int long long
const int Mod = 1000000007;
il void solve(int Case) {
	if (Case == 18) { puts("1"); return ; }
	if (19 <= Case && Case <= 21) {
		int n, k; cin >> n >> k;
		int res = 1;
		for (int i = 1; i <= k; i ++) res = res * i % Mod;
		cout << res << "\n";
		return ;
	}
	puts("3");
}
signed main() {
	freopen("traverse.in", "r", stdin);
	freopen("traverse.out", "w", stdout);
	int c, T; cin >> c >> T;
	while (T --) solve(c);
	return 0;
}
