#include using namespace std; using ll = long long; using P = pair; #define rep(i, n) for(ll i = 0; i < n; i++) #define all(x) (x).begin(),(x).end() templatebool chmin(T&a, const T&b){if(a>b){a=b;return 1;}return 0;} templatebool chmax(T&a, const T&b){if(a> l; rep(i,l){ ll r,n; cin >> r >> n; n++; ll x = mpow(r-1, MOD-2); ans = ans * ((r * (mpow(r,n) - 1) % MOD * x % MOD - n + MOD) * x % MOD) % MOD; } cout << ans << endl; return 0; }