#include <bits/stdc++.h>

#define MOD 1000000007

using namespace std;

int main()

{

int t;

cin>>t;

while(t–)

{

long long int n,k,ans,c,b1,a2;

cin>>n>>k;

if(n==2)

{

```
ans=(((k-1)*(k))/2);
ans=ans%MOD;
}
else
{
c=((k-1)/(n-1))+1;
if(c==1)
ans=(k-1)%MOD;
else
{
a2=((k-1)-((c-1)*(n-1)))%MOD;
b1=(((c)*((a2)+(k-1)))/2)%MOD;
ans=b1;
//cout<<c<<a2<<" "<<endl;
}
//cout<<c<<" "ans<<endl;
}
cout<<ans<<endl;
}
return 0;
```

}