import std; void main() { int L; readf("%d\n", L); ulong M = 10 ^^ 9 + 7; ulong res = 1; foreach (_; 0 .. L) { ulong P, e; readf("%d %d\n", P, e); if (res == 0) continue; ulong inv = powmod(P-1, M-2, M); ulong num = powmod(P, e+2, M); if (num < P) num += M; num -= P; num *= inv; if (num < e + 1) num += M; num -= e + 1; if (num > M) num %= M; num *= inv; if (num > M) num %= M; res *= num; if (res > M) res %= M; } res.writeln; }