package main import ( "fmt" ) // 10^9 + 7 const P = 1000000007 type mat [2][2]int64 func mul(A, B mat) (C mat) { for i := 0; i < 2; i++ { for j := 0; j < 2; j++ { for k := 0; k < 2; k++ { C[i][j] = (C[i][j] + A[i][k]*B[k][j]) % P } } } return } func powM(n int64) mat { A := [2][2]int64{{1, 1}, {1, 0}} C := [2][2]int64{{1, 0}, {0, 1}} for n > 0 { if (n & 1) == 1 { C = mul(A, C) } n >>= 1 A = mul(A, A) } return C } func decode(s string) (z int64) { for _, r := range s { z = (z*10 + int64(r-'0')) % (P - 1) } return } func pow(x, n int64) (z int64) { z = 1 for n > 0 { if n&1 > 0 { z = z * x % P } x = x * x % P n >>= 1 } return } func pat(c int64, d string) int64 { return pow(powM(c + 1)[0][0], decode(d)) } func main() { var N int fmt.Scan(&N) res := int64(1) for i := 0; i < N; i++ { var C int64 var D string fmt.Scan(&C, &D) res = res * pat(C, D) % P } fmt.Println(res) }