#include "bits/stdc++.h" using namespace std; long long mod = (long long)1e9 + 7; vector> fmatrix(int N){ vector> ret(N, vector(N)); for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { if (i == j) ret[i][j] = 1; else ret[i][j] = 0; } } return ret; } vector> matrixmul(vector> v1, vector> v2){ int N = v1.size(); vector> ret(N, vector(N)); for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { for (int k = 0; k < N; k++) { ret[i][j] += v1[i][k] * v2[k][j]; } ret[i][j] %= mod; } } return ret; } vector> matrixpowmod(vector> v, long long p) { if (p == 0) return fmatrix(v.size()); if (p % 2 == 1){ return matrixmul(matrixpowmod(v, p - 1), v); } auto b = matrixpowmod(v, p / 2); return matrixmul(b, b); } long long powmod(long long a, int p){ if (p == 0) return 1; if (p % 2 == 1){ return a * powmod(a, p - 1) % mod; } long long b = powmod(a, p / 2); return b * b % mod; } int main() { int N; cin >> N; long long ans = 1; long mod = (int)1e9 + 7; for (int i = 0; i < N; i++) { long long C; string SD; cin >> C >> SD; long long D = 0; for (int i = 0; i < SD.size(); i++) { D *= 10; D += SD[i] - '0'; D %= (mod - 1); } vector> v(2, vector(2)); v[0][0] = 1; v[0][1] = 1; v[1][0] = 1; v[1][1] = 0; auto v2 = matrixpowmod(v, C); if (SD.size() != 1 && D == 0) D += mod; long long mul = v2[0][0] + v2[1][0]; mul %= mod; mul = powmod(mul, D); ans *= mul; ans %= mod; } cout << ans << endl; }