using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static int NN => int.Parse(ReadLine()); static int[] NList => ReadLine().Split().Select(int.Parse).ToArray(); static int[][] NArr(long n) => Enumerable.Repeat(0, (int)n).Select(_ => NList).ToArray(); public static void Main() { Solve(); } static void Solve() { var L = NN; var map = NArr(L); var mod = 1_000_000_007; var ans = 1L; for (var i = 0; i < L; ++i) { var p = (long)map[i][0]; var e = (long)map[i][1]; var rp = Exp(p - 1, mod - 2, mod); ans = ans * (Exp(p, e + 2, mod) - p * (e + 2) % mod + e + 1 + mod) % mod * rp % mod * rp % mod; } WriteLine(ans); } static long Exp(long n, long p, int mod) { long _n = n % mod; var _p = p; var result = 1L; if ((_p & 1) == 1) result *= _n; while (_p > 0) { _n = _n * _n % mod; _p >>= 1; if ((_p & 1) == 1) result = result * _n % mod; } return result; } }