#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define INF 1000000000 using namespace std; typedef long long ll; const ll MOD = 1000000007; ll mod10[210]; void init() { mod10[0] = 1; for (int i = 1; i < 210; i++) { mod10[i] = (mod10[i-1]*10) % (MOD-1); } } class Mat { public: ll a, b, c, d; }; Mat mul(const Mat& A, const Mat& B) { Mat C; C.a = ((A.a * B.a) % MOD + (A.b * B.c) % MOD) % MOD; C.b = ((A.a * B.b) % MOD + (A.b * B.d) % MOD) % MOD; C.c = ((A.c * B.a) % MOD + (A.d * B.c) % MOD) % MOD; C.d = ((A.c * B.b) % MOD + (A.d * B.d) % MOD) % MOD; return C; } Mat modMul(const Mat& A, const ll p) { if (p == 0) { Mat E; E.a = 1; E.b = 0, E.c = 0; E.d = 1; return E; } if (p == 1) { return A; } if (p % 2 == 0) { const Mat B = modMul(A, p/2); return mul(B, B); } const Mat B = modMul(A, p-1); return mul(A, B); } ll modpow(ll a, ll n) { if (a == 0) return 0; if (n == 0) return 1; if (n == 1) return a; if (n % 2 == 0) { ll tmp = modpow(a, n/2); return (tmp * tmp) % MOD; } ll tmp = modpow(a, n-1); return (tmp * a) % MOD; } int main(void) { init(); int N; cin >> N; ll ans = 1; while (N--) { ll C; string D; cin >> C >> D; int len = D.size(); ll d = 0; for (int i = 0; i < len; i++) { d += (mod10[len-i-1] * (D[i]-'0')) % (MOD-1); d %= (MOD-1); } Mat A; A.a = 0; A.b = 1; A.c = 1; A.d = 1; A = modMul(A, C-1); // cout << A.a << "\t" << A.b << endl; // cout << A.c << "\t" << A.d << endl; ll tmp = (A.c + 2LL * A.d) % MOD; ll p = modpow(tmp, d); ans *= p; ans %= MOD; } cout << ans << endl; return 0; }