def get_inner_prod(raw, col): return sum([x*y for (x,y) in zip(raw,col)]) def get_matrix_trans(matrix): # malloc n*m matrix matrix_t = [[0 for j in range(len(matrix))] for i in range(len(matrix[0]))] for i in range(len(matrix)): for j in range(len(matrix[i])): matrix_t[j][i] = matrix[i][j] return matrix_t def matmult(matrix1, matrix2): # malloc A_m*B_n matrix result = [[0 for j in range(len(matrix2[0]))] for i in range(len(matrix1))] matrix2_t = get_matrix_trans(matrix2) for i in range(len(result)): for j in range(len(result[0])): result[i][j] = get_inner_prod(matrix1[i], matrix2_t[j]) return result #二乗法の累乗 def matpow(A,p): n=len(A) A=list(A) R=[[0 for i in range(n)] for j in range(n)] for i in range(n): R[i][i]=1 while p: if p%2: R = matmult(A,R) A=matmult(A,A) p >>= 1 return R def pat(c): A=[[1,1],[1,0]] B=matpow(A,c-1) return (B[0][0]+B[0][1]+B[1][0]+B[1][1])%mo N=int(input()) ret = 1 mo=1000000007 for i in range(N): C,D=map(int,input().split()) if D>mo-1: D %= mo-1 ret = ret * pow(pat(C),D,mo) % mo print(ret)