package main import ( "bufio" "fmt" "os" "strconv" ) var sc = bufio.NewScanner(os.Stdin) func next() string { sc.Split(bufio.ScanWords) if !sc.Scan() { panic("could not scan a word from the reader") } return sc.Text() } func nextInt() int { i, e := strconv.Atoi(next()) if e != nil { panic(e) } return i } func nextLong() int64 { i, e := strconv.ParseInt(next(), 10, 64) if e != nil { panic(e) } return i } // 10^9 + 7 const P = 1000000007 func fib(n, p int64) int64 { var a, b, c, d, e, f, g, h int64 a, b, c, d, e, f, g, h = 1, 1, 1, 0, 1, 0, 0, 1 for n > 0 { if n&1 == 1 { e, f, g, h = (a*e+b*g)%p, (a*f+b*h)%p, (c*e+d*g)%p, (c*f+d*h)%p } n >>= 1 a, b, c, d = (a*a+b*c)%p, (b*(a+d))%p, (c*(a+d))%p, (b*c+d*d)%p } return g } 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) { if x == 0 { return 0 } 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(fib(c+2, P), decode(d)) } func main() { N := nextInt() res := int64(1) for i := 0; i < N; i++ { C, D := nextLong(), next() res = res * pat(C, D) % P } fmt.Println(res) }