#include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; const ll INF=1LL<<60; typedef pair P; typedef pair PP; const ll MOD=1e9+7; const double PI=acos(-1); ll mod_pow(ll x,ll y,ll mod){ ll res=1; while(y>0){ if(y&1){ res*=x; res%=mod; } x*=x; x%=mod; y/=2; } return res; } int main(){ int L; cin>>L; vector> pe(L); for(int i=0;i>pe[i].first>>pe[i].second; } ll ans=1; for(auto [p,e]:pe){ ll invP=mod_pow((p-1+MOD)%MOD,MOD-2,MOD);//p-1の逆元 ll c=(mod_pow(p,e+1,MOD)-1+MOD)%MOD; c*=p%MOD; c%=MOD; c*=invP; c%=MOD; c-=(e+1)%MOD; c+=MOD; c%=MOD; c*=invP; c%=MOD; ans*=c; ans%=MOD; } cout<