import sys input = sys.stdin.buffer.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 ans = 1 N = int(input()) for _ in range(N): C, D = map(int, input().split()) C = enum(C) ans *= pow(C, D, P) ans %= P print(ans)