#include #define rep(i, n) for (int (i) = 0; (i) < (int)(n); (i)++) const int dx[] = {1, 0, -1, 0}; const int dy[] = {0, 1, 0, -1}; using namespace std; typedef long long ll; const ll MOD = 1e9+7; const ll MM = MOD-1; ll getMod(const string& s) { int n = s.size(); ll ans = 0; for (int i = 0; i < n; i++) { ans *= 10; ans += (s[i]-'0'); ans %= MM; } return ans; } template class Mat { public: Mat() : mat(R, vector(C)) {} Mat& operator=(const Mat rhs) {return rhs;} vector& operator[](int r) {return mat[r];} const vector operator[](int r) const {return mat[r];} Mat& operator+=(const Mat rhs) { for (int i = 0; i < R; i++) for (int j = 0; j < C; j++) { mat[i][j] += rhs.mat[i][j]; if (mat[i][j] >= mod) mat[i][j] %= mod; } return (*this); } Mat& operator-=(const Mat rhs) { for (int i = 0; i < R; i++) for (int j = 0; j < C; j++) { mat[i][j] -= rhs.mat[i][j]; mat[i][j] %= mod; if (mat[i][j] < 0) mat[i][j] += mod; } return (*this); } const Mat operator+(const Mat rhs) const { Mat ret = (*this); ret += rhs; return ret; } const Mat operator-(const Mat rhs) const { Mat ret = (*this); ret -= rhs; return ret; } const Mat operator*(const Mat rhs) const { Mat ret; for (int i = 0; i < R; i++) for (int j = 0; j < R; j++) { for (int k = 0; k < C; k++) { ret[i][j] += (*this)[i][k] * rhs[k][j]; if (ret[i][j] >= mod) ret[i][j] %= mod; } } return ret; } const Mat pow(ll N) const { if (N == 0) { Mat E; for (int i = 0; i < R; i++) E[i][i] = 1; return E; } if (N == 1) { return (*this); } if (N % 2 == 1) { Mat tmp = pow(N-1); return tmp * (*this); } else { Mat tmp = pow(N/2); return tmp*tmp; } } void print() const { for (int i = 0; i < R; i++) { for (int j = 0; j < C; j++) { cout << mat[i][j] << "\t"; } cout << endl; } } private: vector > mat; }; typedef Mat<2, 2, MOD> Mat2x2; // x^p ll powmod(ll x, ll p, ll m = MOD) { if (x == 0) return 0; if (p == 0) return 1; if (p == 1) return x; if (p % 2 == 0) { ll tmp = powmod(x, p/2, m); return (tmp*tmp)%m; } else { ll tmp = powmod(x, p-1, m); return (tmp*x)%m; } } int main() { int N; cin >> N; ll ans = 1; while (N--) { ll C; string D; cin >> C >> D; ll d = getMod(D); Mat2x2 a; a[0][1] = a[1][0] = a[1][1] = 1; Mat2x2 b = a.pow(C-1); ll tmp = (b[1][0]+b[1][1]*2)%MOD; tmp = powmod(tmp, d); ans *= tmp; ans %= MOD; } cout << ans << endl; return 0; }