import numpy mo=1000000007 def matmult(matrix1, matrix2): global mo matrix1=numpy.array(matrix1) matrix2=numpy.array(matrix2) return numpy.mod(matrix1@matrix2,mo).tolist() #二乗法の累乗 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 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)