import sys input = sys.stdin.readline sys.setrecursionlimit(10 ** 7) P = 10 ** 9 + 7 def mat_mul(A, B): res = [[0] * len(B[0]) for _ in range(len(A))] for i in range(len(A)): for k in range(len(A[0])): for j in range(len(B[0])): res[i][j] += A[i][k] * B[k][j] res[i][j] %= P return res def mat_pow(A, n): size = len(A) res = [[0] * size for _ in range(size)] for i in range(size): res[i][i] = 1 while n: if n & 1: res = mat_mul(res, A) A = mat_mul(A, A) n >>= 1 return res A = [[1, 1], [1, 0]] def enum(n): if n == 1: return 2 if n == 2: return 3 B = mat_pow(A, n - 2) return (3 * B[0][0] + 2 * B[0][1]) % P def reduction(D): if len(D) < 10: return int(D) % P res = 0 for d in D: res = (res * 10 + int(d)) % (P - 1) return res ans = 1 N = int(input()) CD = tuple(input().rstrip().split() for _ in range(N)) for C, D in CD: C = enum(int(C)) if not C: ans = 0 break D = reduction(D) ans *= pow(C, D, P) ans %= P print(ans)