#include using namespace std; typedef array F; const int mod = 1e9 + 7; const int B = 8; F dub[64 / B][1 << B]; int mul(int x, int y) { return int64_t(x) * y % mod; } int add(int x, int y) { return (x += y) >= mod ? x - mod : x; } template int add(int x, T... y) { return add(x, add(y...)); } void upd(int &x, int y) { x = add(x, y); } int pow(int a, int64_t b) { if (a == 0) return 0; int res = 1; while (b > 0) { if (b & 1) res = mul(res, a); a = mul(a, a); b >>= 1; } return res; } F mul(F a, F b) { F res; int t = mul(a[1], b[1]); res[0] = add(mul(a[0], b[0]), t); res[1] = add(mul(a[0], b[1]), mul(a[1], b[0]), t); return res; } F fib(int64_t n) { F f = { 1, 0 }; for (int i = 0; n > 0; i++) { if (n % (1 << B) != 0) f = mul(f, dub[i][n % (1 << B)]); n >>= B; } return f; } int main() { dub[0][1][1] = 1; for (int i = 0; i < 64 / B; i++) { if (i > 0) dub[i][1] = mul(dub[i - 1][(1 << B) - 1], dub[i - 1][1]); for (int j = 2; j < 1 << B; j++) { dub[i][j] = mul(dub[i][1], dub[i][j - 1]); } } int n; cin >> n; int ans = 1; while (n--) { int64_t C; static char D[210]; scanf("%lld %s", &C, D); int64_t d = 0; for (int i = 0; D[i] != 0; i++) { d = (d * 10 + D[i] - '0') % (mod - 1); } F f = fib(C); ans = mul(ans, pow(add(f[0], f[1], f[1]), d)); } cout << ans << endl; }