def xgcd(a, b): x0, y0, x1, y1 = 1, 0, 0, 1 while b != 0: q, a, b = a // b, b, a % b x0, x1 = x1, x0 - q * x1 y0, y1 = y1, y0 - q * y1 return a, x0, y0 def modinv(a, m): g, x, y = xgcd(a, m) if g != 1: raise Exception('modular inverse does not exist') else: return x % m n = int(input()) mod = 10**9 + 7 ans = 1 for _ in range(n): p, e = map(int, input().split()) temp1 = (e + 1) * (pow(p, e + 1, mod) - 1) % mod temp1 *= modinv(p - 1, mod) temp1 %= mod temp2 = 1 - ((e + 1) * pow(p, e, mod) % mod) + (e * pow(p, e + 1, mod) % mod) temp2 %= mod temp2 *= modinv((p - 1)**2, mod) * p % mod temp2 %= mod ans *= (temp1 - temp2) % mod ans %= mod print(ans)