#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 long long ll; 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, ll 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; } ll pow_mod(ll x, ll y, ll MOD) { ll res = 1; while (y > 0) { if (y & 1) res = res * x % MOD; x = x * x % MOD; y >>= 1; } return res; } int main(void){ int N; cin >> N; vector a(201); a[0] = 1; for (int i = 1; i <= 200; i++) a[i] = a[i - 1] * 10 % (MOD - 1); ll ans = 1; while (N--) { ll C; string D; cin >> C >> D; mat A(2, vec(2)); A[0][0] = 1; A[0][1] = 1; A[1][0] = 1; A[1][1] = 0; ll comb = pow(A,C+2)[1][0]; ll 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; }