#include using namespace std; using std::cout; using std::cin; using std::endl; using ll=long long; const int INF=2100000000; ll mod=1e9+7; #define rep(i,a) for (ll i=0;i>N; ll ans=1; rep(i,N){ ll P,e; cin>>P>>e; ll rev=my_pow(P-1,mod-2); ll tmp=my_pow(P,e+1); ans*=(rev*((tmp-e-1+(((tmp-P)*rev)%mod))%mod))%mod; ans%=mod; } cout<<(ans+mod)%mod<