#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i)) #define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i)) #define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i)) #if defined(_MSC_VER) || __cplusplus > 199711L #define aut(r,v) auto r = (v) #else #define aut(r,v) __typeof(v) r = (v) #endif #define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it) #define all(o) (o).begin(), (o).end() #define pb(x) push_back(x) #define mp(x,y) make_pair((x),(y)) #define mset(m,v) memset(m,v,sizeof(m)) #define INF 0x3f3f3f3f #define INFL 0x3f3f3f3f3f3f3f3fLL using namespace std; typedef vector vi; typedef pair pii; typedef vector > vpii; typedef long long ll; template inline void amin(T &x, U y) { if(y < x) x = y; } template inline void amax(T &x, U y) { if(x < y) x = y; } template struct ModInt { static const int Mod = MOD; unsigned x; ModInt(): x(0) { } ModInt(signed sig) { int sigt = sig % MOD; if(sigt < 0) sigt += MOD; x = sigt; } ModInt(signed long long sig) { int sigt = sig % MOD; if(sigt < 0) sigt += MOD; x = sigt; } int get() const { return (int)x; } ModInt &operator+=(ModInt that) { if((x += that.x) >= MOD) x -= MOD; return *this; } ModInt &operator-=(ModInt that) { if((x += MOD - that.x) >= MOD) x -= MOD; return *this; } ModInt &operator*=(ModInt that) { x = (unsigned long long)x * that.x % MOD; return *this; } ModInt &operator/=(ModInt that) { return *this *= that.inverse(); } ModInt operator+(ModInt that) const { return ModInt(*this) += that; } ModInt operator-(ModInt that) const { return ModInt(*this) -= that; } ModInt operator*(ModInt that) const { return ModInt(*this) *= that; } ModInt operator/(ModInt that) const { return ModInt(*this) /= that; } ModInt inverse() const { signed a = x, b = MOD, u = 1, v = 0; while(b) { signed t = a / b; a -= t * b; std::swap(a, b); u -= t * v; std::swap(u, v); } if(u < 0) u += Mod; ModInt res; res.x = (unsigned)u; return res; } }; template ModInt operator^(ModInt a, unsigned long long k) { ModInt r = 1; while(k) { if(k & 1) r *= a; a *= a; k >>= 1; } return r; } typedef ModInt<1000000007> mint; int digitsMod(char s[], int n, int m) { int x = 0; long long pow10 = 1; for(int i = n-1; i >= 0; i --) { if((x += pow10 * (s[i] - '0') % m) >= m) x -= m; pow10 = pow10 * 10 % m; } return x; } struct Matrix { typedef mint Num; static const int MaxN = 2; int hei, wid; Num v[MaxN][MaxN]; Matrix() {} Matrix(int n, int m): hei(n), wid(m) { mset(v, 0); } inline int height() const { return hei; } inline int width() const { return wid; } inline Num& at(int i, int j) { return v[i][j]; } inline const Num& at(int i, int j) const { return v[i][j]; } static Matrix identity(int n) { Matrix A(n, n); rep(i, n) A.at(i, i) = 1; return A; } inline static Matrix identity(const Matrix& A) { return identity(A.height()); } Matrix& operator*=(const Matrix& B) { int n = height(), m = B.width(), p = B.height(); assert(p == width()); const unsigned (*b)[MaxN] = reinterpret_cast(B.v); Num w[MaxN][MaxN]; rep(i, n) { const unsigned *ai = reinterpret_cast(v[i]); rep(j, m) { unsigned long long x = 0; rep(k, p) x += (unsigned long long)ai[k] * b[k][j]; w[i][j].x = x % mint::Mod; } } memcpy(v, w, sizeof(v)); return *this; } }; Matrix operator^(const Matrix& t, ll k) { Matrix A = t, B = Matrix::identity(t); while(k) { if(k & 1) B *= A; A *= A; k >>= 1; } return B; } int fibonacci(long long n, int Mod) { int m2 = 1, m1 = 1, m0 = 0; int x2 = 1, x1 = 0, x0 = 1; while(n > 0) { if (n & 1) { int a2 = ((long long)x2 * m2 + (long long)x1 * m1) % Mod; int a1 = ((long long)x2 * m1 + (long long)x1 * m0) % Mod; int a0 = ((long long)x1 * m1 + (long long)x0 * m0) % Mod; x2 = a2, x1 = a1, x0 = a0; } n >>= 1; if (n > 0) { int a2 = ((long long)m2 * m2 + (long long)m1 * m1) % Mod; int a1 = ((long long)m2 * m1 + (long long)m1 * m0) % Mod; int a0 = ((long long)m1 * m1 + (long long)m0 * m0) % Mod; m2 = a2, m1 = a1, m0 = a0; } } return x1 % Mod; } int main() { int N; scanf("%d", &N); char *D = new char[202]; mint ans = 1; rep(i, N) { long long C; scanf("%lld%s", &C, D); mint f = fibonacci(C+2, mint::Mod); int d = digitsMod(D, strlen(D), mint::Mod-1); mint t = d == 0 && f.get() == 0 ? 0 : f ^ d; ans *= t; } printf("%d\n", ans.get()); return 0; }