#include using namespace std; using ll = long long; ll m = 1e9 + 7; ll mpow(ll a, ll n) { ll ret = 1; while (n) { if (n % 2) { ret *= a; ret %= m; } n /= 2; a = (a * a) % m; } return ret; } int main () { int N; cin >> N; ll ans = 1; for (int i = 0; i < N; i ++) { ll p, e; cin >> p >> e; ll q = mpow(p, e + 1); q = (q * p) % m; q = (q * mpow(p - 1, m - 2)) % m; q += (m - 1); q %= m; q = (q * mpow(p - 1, m - 2)) % m; ans *= q; ans %= m; } cout << ans << endl; }