#include using namespace std; typedef long long ll; typedef unsigned long long ull; typedef vector VI; typedef vector VVI; #define REP(i, n) for(int(i)=0;(i)<(n);++(i)) #define FOR(i, f, t) for(int(i)=(f);(i)<(t);(++i)) #define RREP(i, n) for(int(i)=(n)-1;(i)>=0;--(i)) const int MOD = int(1e9+7); int N,M,W,H; template class Matrix { private: unsigned int r, c; vector > v; public: Matrix(unsigned int rows, unsigned int columns) : r(rows),c(columns){ v.resize(rows); for(unsigned int i = 0; i < rows; ++i) v[i].resize(columns); } vector<_Tc> &operator [](unsigned int row){ return v[row]; } const Matrix &operator *=(const Matrix &m){ if(c != m.r) throw; Matrix n(r,m.c); for(unsigned int i = 0; i < r; ++i) for(unsigned int j = 0; j < m.c; ++j) for(unsigned int k = 0; k < c; ++k) n.v[i][j] = (n.v[i][j] + v[i][k] * m.v[k][j] % MOD) % MOD; return *this=n; } static const Matrix unit(unsigned int s, _Tc v = 1){ Matrix n(s,s); for(unsigned int i = 0; i < s; ++i) n.v[i][i] = v; return n; } const Matrix pow(ll p) const { if(c != r) throw; Matrix n = Matrix::unit(r), m = *this; while(p > 0){ if(p & 1) n *= m; m *= m; p >>= 1; } return n; } }; ll in(){ ll r=0; string s; cin >> s; int l = s.size(); REP(i,l) r = (r*10+(s[i] - '0'))%(MOD-1); return r; } ll dp[10010][2]; long long fib(ll n){ Matrix a(2,2); a[0][0] = a[0][1] = a[1][0] = 1; a[1][1] = 0; a = a.pow(n); return a[1][0]; } int binpow(ull x, ull k, int m){ if(x==0) return 0; if(k==0) return 1; if(k%2==0) return binpow(((x%m)*(x%m))%m, k/2, m); else return ((x%m)*binpow(x, k-1, m)) % m; } int main(){ do { cin.tie(0); ios_base::sync_with_stdio(false); } while(0); cin >> N; ll c, d, res = 1; REP(i,N){ cin >> c; d = in(); res = binpow(fib(c+2), d, MOD) % MOD * res % MOD; } cout << res << endl; return 0; }