l = int(input())

#(1*3+2*2+4*1)(1*2+3)
#Σ(i P[i]^(e[i]-i+1))
mod = 10**9 + 7

ans = 1
for _ in range(l):
	p, e = map(int,input().split())
	tmp = (pow(p, e+1, mod) - e - 1 + p * (pow(p, e, mod) - 1) * pow(p-1, mod-2, mod)) % mod
	ans = ans * tmp * pow(p-1, mod-2, mod) % mod

print(ans)