#include #include #include #include #define REP(i,a,b) for(int i = (a); i < (b); i++) #define rep(i,a) REP(i,0,a) using namespace std; typedef vector vec; typedef vector mat; const int MOD = 1000000007; mat mul(mat &A, mat&B) { mat C(A.size(), vec(B[0].size())); rep(i, A.size()) { rep(k, B.size()) { rep(j, B[0].size()) { C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % MOD; } } } return C; } mat pow(mat A, int n) { mat B(A.size(), vec(A.size())); rep(i, A.size()) { B[i][i] = 1; } while (n > 0) { if (n & 1) B = mul(B, A); A = mul(A, A); n >>= 1; } return B; } int pow_mod(int a, int p, int MOD) { if (p == 0) return 0; int res = 1; while (p > 0) { if (p & 1) res = res * a % MOD; a = a * a % MOD; p >>= 1; } return res; } int main(void){ mat A(2, vec(2)); A[0][0] = 1; A[0][1] = 1; A[1][0] = 1; A[1][1] = 0; vector a(201); a[0] = 1; for (int i = 1; i <= 200; i++) a[i] = a[i - 1] * 10 % (MOD - 1); int ans = 1; int N; cin >> N; while (N--) { int C; string D; cin >> C >> D; int comb = pow(A,C+2)[1][0] % MOD; int p = 0; rep(i, D.size()) { p = (p + a[D.length() - i - 1] * (D[i] - '0')) % (MOD - 1); } ans = (ans * pow_mod(comb, p, MOD)) % MOD; } cout << ans << endl; return 0; }