MOD = 10 ** 9 + 7 l = int(input()) ans = 1 for i in range(l): p, e = map(int, input().split()) ans *= (p * (pow(p, e + 1, MOD) - 1) - p * (e + 1) + (e + 1)) * pow((p - 1) * (p - 1), MOD - 2, MOD) ans %= MOD print(ans)