M=10**9+7 L=int(input()) ans=1 for i in range(L): P,e=map(int,input().split()) R=pow(P-1,M-2,M) X=pow(P,e,M) ans*=(R*((((X+(R*(X-1))%M)*P)%M-(e+1))%M))%M ans%=M print((ans+M)%M)