from re import A l = int(input()) mod = 10**9+7 ans = 1 for i in range(l): p,e = map(int,input().split()) rp = pow(p-1,mod-2,mod) a = p*(pow(p,e+1,mod)-1)%mod*rp%mod a -= (e+1) a %= mod a *= rp ans *= a ans %= mod print(ans)