#!/usr/bin/env python3 # %% import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines from functools import reduce MOD = 10 ** 9 + 7 # %% N = int(readline()) m = map(int, read().split()) CD = zip(m, m) # %% def Fibonacci(n): """return (a,b) such that x^n = a + bx mod x^2-x-1""" if n == 0: return 1, 0 a, b = Fibonacci(n // 2) a, b = a * a + b * b, 2 * a * b + b * b if n % 2 == 0: return a % MOD, b % MOD a, b = b, a + b return a % MOD, b % MOD # %% def solve(C, D): f = Fibonacci(C + 2)[1] if f == 0: return 0 return pow(f, D % (MOD - 1), MOD) # %% nums = (solve(C, D) for C, D in CD) answer = reduce(lambda x, y: x * y % MOD, nums) print(answer)