#include using namespace std; typedef long long ll; typedef vector vec; typedef vector matrix; const ll MOD = 1e9 + 7; matrix identity(int n) { matrix A(n, vec(n)); for (int i = 0; i < n; ++i) A[i][i] = 1; return A; } matrix mul(const matrix &A, const matrix &B) { matrix C(A.size(), vec(B[0].size())); for (int i = 0; i < C.size(); ++i) for (int j = 0; j < C[i].size(); ++j) for (int k = 0; k < A[i].size(); ++k) C[i][j] = (C[i][j] + A[i][k] * B[k][j] % MOD) % MOD; return C; } vec mul(const matrix &A, const vec &x) { vec y(A.size()); for (int i = 0; i < A.size(); ++i) for (int j = 0; j < A[0].size(); ++j) y[i] = (y[i] + A[i][j] * x[j] % MOD) % MOD; return y; } matrix pow(const matrix &A, ll e) { return e == 0 ? identity((int)A.size()) : e % 2 == 0 ? pow(mul(A, A), e/2) : mul(A, pow(A, e-1)); } ll fib(ll N){ matrix A(2, vec(2)); A[0][0] = 0; A[0][1] = 1; A[1][0] = 1; A[1][1] = 1; vec init(2); init[0] = 1; init[1] = 2; vec res = mul(pow(A, N), init); return res[0]; } ll mod_pow(ll x, ll e){ if(x == 0) return 0; ll v = 1; for(;e;e>>=1){ if(e & 1) v = (v * x) % MOD; x = (x * x) % MOD; } return v; } int main(){ int N; cin >> N; ll res = 1; while(N--){ ll C; cin >> C; string D; cin >> D; ll a = fib(C); ll b = 0; for(char c : D) b = (b * 10 + c - '0') % (MOD - 1); res = res * mod_pow(a, b) % MOD; } cout << res << endl; return 0; }