#define _USE_MATH_DEFINES #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair i_i; typedef pair ll_i; typedef pair d_i; typedef pair ll_ll; typedef pair d_d; struct edge { int u, v, w; }; ll MOD = 1000000007; ll _MOD = 1000000009; double EPS = 1e-10; int INF = INT_MAX / 2; vector< vector > matmul(vector< vector >& A, vector< vector >& B) { int n = A.size(); vector< vector > C(n, vector(n)); for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) for (int k = 0; k < n; k++) C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % MOD; return C; } vector< vector > matpow(vector< vector > A, ll x) { int n = A.size(); vector< vector > B(n, vector(n)); for (int i = 0; i < n; i++) B[i][i] = 1; while (x > 0) { if (x % 2) B = matmul(B, A); x /= 2; A = matmul(A, A); } return B; } int pow_mod(ll x, ll n, int m) { if (n == 0) return 0; ll res = 1; for (; n > 0; n >>= 1) { if (n & 1) res = (res * x) % m; x = (x * x) % m; } return res; } int main() { vector< vector > A(2, vector(2)); A[0][0] = 1; A[0][1] = 1; A[1][0] = 1; A[1][1] = 0; vector a(201); a[0] = 1; for (int i = 1; i <= 200; i++) a[i] = a[i - 1] * 10 % (MOD - 1); int N; cin >> N; ll ans = 1; while (N--) { ll C; string D; cin >> C >> D; ll x = matpow(A, C + 1)[0][0]; ll y = 0; for (int i = 0; i < D.length(); i++) y = (y + a[D.length() - i - 1] * (D[i] - '0')) % (MOD - 1); ans = ans * pow_mod(x, y, MOD) % MOD; } cout << ans << endl; }