import sys import math def matmult(A,B): n=len(A) C=[[0 for i in range(n)] for j in range(n)] for x in range(n): for z in range(n): for y in range(n): C[x][y] += A[x][z]*B[z][y] C[x][y] %= mo; return list(C) 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=input() ret = 1 mo=1000000007 for i in range(N): C,D=map(int,raw_input().strip().split(" ")) D %= mo-1 ret = ret * pow(pat(C),D,mo) % mo print ret