#include <cstdio> #include <cmath> const int MOD = 9999991; int table[MOD + 1]; void create_table() { table[1] = 1; for (int i = 2; i < MOD; i++) { table[i] = (int)((((long long)table[i - 1]) * i) % MOD); } } int fact_mod(int n) { if (n >= MOD) return 0; return table[n]; } int pow_mod(int a, int t) { if (t == 1) return a % MOD; if (t % 2) return (((long long)pow_mod(a, t - 1)) * a) % MOD; long long h = pow_mod(a, t / 2); return (int)((h * h) % MOD); } int main() { int n, a, t; const double P = 0.9189385332046727; // magic number (Stirling’s approximation) create_table(); scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d%d", &a, &t); double l = log(t); double x = P + l / 2 + t * l - t + 1.0 / (12.0 * t); double y = t * log(a); printf("%d ", x > y ? fact_mod(t) : pow_mod(a, t)); } return 0; }