#include #include #include #include using namespace std; #define RREP(i,s,e) for (i = s; i >= e; i--) #define rrep(i,n) RREP(i,n,0) #define REP(i,s,e) for (i = s; i < e; i++) #define rep(i,n) REP(i,0,n) #define INF 100000000 #define MOD 1000000007 typedef long long ll; vector> ini(2,vector(2)); vector> mult(vector> a, vector> b) { int i, j, k; vector> c(2,vector(2)); rep (i,2) rep (j,2) rep (k,2) { c[i][j] += a[i][k] * b[k][j]; c[i][j] %= MOD; } return c; } ll solve(ll c) { int i, j; vector> mat(2,vector(2)); auto x = ini; mat[0][0] = mat[1][1] = 1; mat[0][1] = mat[1][0] = 0; while (c > 0) { if (c % 2) mat = mult(x,mat); x = mult(x,x); c /= 2; } return (mat[1][0] * 2 + mat[1][1]) % MOD; } ll power(ll x, ll n) { ll ret = 1; if (x == 0) return 0; while (n > 0) { if (n % 2) { ret *= x; ret %= MOD; } x *= x; x %= MOD; n /= 2; } return ret; } int main() { int i, n; ll ans; cin >> n; ans = 1; ini[0][0] = ini[0][1] = ini[1][0] = 1; ini[1][1] = 0; rep (i,n) { ll c, d; string sd; cin >> c >> sd; d = 0; for (auto chr : sd) d = (d * 10 + chr - '0') % (MOD-1); ans *= power(solve(c),d) % MOD; ans %= MOD; } cout << ans << endl; return 0; }