Can anyone please help me…It’s failing subtask 2 task 2… I dont know why?

```
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define f first
#define s second
ll N = 1000000007;
ll power(ll x, ll y, ll p)
{
ll res = 1;
x = x % p;
while (y > 0)
{
if (y & 1)
res = (res*x) % p;
y = y>>1;
x = (x*x) % p;
}
return res;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll t;
cin >> t;
while(t--)
{
ll n , k;
cin >> n >> k;
ll ans ;
if(n==2)
{
k--;
if(k%2==0)
{
ll temp = k/2;
ll temp1 = (k%N + 1)%N;
ans = ((temp%N)*(temp1%N))%N;
}
else
{
ll temp = (k+1)/2;
ll temp1 = (k%N);
ans = ((temp%N)*(temp1%N))%N;
}
cout << ans << endl;
}
else
{
if(k<=n)
cout << k-1 << endl;
else
{
ll ans;
ll first = k-1;
ll diff = n-1;
ll last = (k-1)%(n-1);
if(last==0)
last = n-1;
ll t = (first - last)/diff + 1;
ll sum = (first%N + last%N)%N;
ans = (sum%N)*(t%N)%N;
ans = (power(2,N-2,N)*(ans%N))%N;
cout << ans << endl;
}
}
}
}
```