mod = 10 ** 9 + 7 L = int(input()) ans = 1 for _ in range(L): p, e = map(int, input().split()) # a(p^e) = (p*(p^(e+1)-1)-(p-1)*(e+1))/(p-1)^2 numer = (p * (pow(p, e + 1, mod) - 1) - (p - 1) * (e + 1)) % mod ans = ans * numer % mod * pow(p - 1, mod - 3, mod) % mod print(ans)