#include using namespace std; using ll = long long; const ll MOD = 1e9 + 7; typedef vector vec; typedef vector mat; mat mul(mat& A, mat& B) { mat C(A.size(), vec(B[0].size(), 0)); for (int i = 0; i < A.size(); i++) { for (int k = 0; k < B.size(); k++) { for (int j = 0; j < B[0].size(); j++) { (C[i][j] += A[i][k] * B[k][j] % MOD) %= MOD; } } } return C; } mat pow(mat A, ll n) { mat B(A.size(), vec(A.size(), 0)); for (int i = 0; i < A.size(); i++) { B[i][i] = 1; } while (n > 0) { if (n & 1) B = mul(B, A); A = mul(A, A); n >>= 1; } return B; } ll bignum_mod(string d) { ll res = 0; for (char c : d) { res = (res * 10 + c - '0') % (MOD - 1); } return res; } ll modpow(ll x, ll n) { ll res = 1; while (n > 0) { if (n & 1) res = res * x % MOD; x = x * x % MOD; n >>= 1; } return res; } int main() { cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; ll ans = 1; mat A = {{1, 1}, {1, 0}}; mat B = {{3}, {2}}; for (int i = 0; i < n; i++) { ll c; string d; cin >> c >> d; ll m = bignum_mod(d); mat C = pow(A, c - 1); C = mul(C, B); (ans *= modpow(C[1][0], m)) %= MOD; } cout << ans << endl; return 0; }