Chef wants to make a feast. In order to do that, he needs a lot of different ingredients. Each ingredient has a certain tastiness; the tastiness of each ingredient may be any positive integer. Initially, for each tastiness between $K$ and $K+N-1$ (inclusive), Chef has an infinite supply of ingredients with this tastiness.
The ingredients have a special property: any two of them can be mixed to create a new ingredient. If the original ingredients had tastiness $x$ and $y$ (possibly $x = y$), the new ingredient has tastiness $x+y$. The ingredients created this way may be used to mix other ingredients as well. Chef is free to mix ingredients in any way he chooses any number of times.
Let's call a tastiness $v$ ($v > 0$) unreachable if there is no way to obtain an ingredient with tastiness $v$; otherwise, tastiness $v$ is reachable. Chef wants to make ingredients with all reachable values of tastiness and he would like to know the number of unreachable values. Help him solve this problem. Since the answer may be large, compute it modulo $1,000,000,007$ ($10^9+7$).
Note that there is an infinite number of reachable values of tastiness, but it can be proven that the number of unreachable values is always finite for $N \ge 2$.

-----Input-----
- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
- The first and only line of each test case contains two space-separated integers $N$ and $K$.

-----Output-----
For each test case, print a single line containing one integer — the number of unreachable values of tastiness, modulo $1,000,000,007$.

-----Constraints-----
- $1 \le T \le 10^5$
- $2 \le N \le 10^{18}$
- $1 \le K \le 10^{18}$

-----Subtasks-----
Subtask #1 (20 points): $N = 2$
Subtask #2 (80 points): original constraints

-----Example Input-----
2
2 1
3 3

-----Example Output-----
0
2

-----Explanation-----
Example case 1: It is possible to obtain ingredients with all values of tastiness.
Example case 2: Ingredients with tastiness $1$ and $2$ cannot be made.

Starter code:

Solutions:
__author__ = 'Prateek'

MOD = int(10**9+7)

def test():
 n,k=list(map(int,input().split()))
 l = k
 d =n-1
 ans = l-1
 ans = ans%MOD
 a = k-n
 term = (d+a)//d
 ll = (a%MOD - (((term-1)%MOD)*(d%MOD))%MOD)%MOD
 if ll < 0:
  ll = (ll +MOD)%MOD
 m = ((term%MOD)*((a%MOD+ll%MOD)%MOD))%MOD
 m = (m*pow(2,MOD-2,MOD))%MOD
 ans += m
 ans = ans%MOD
 print(ans)


if __author__ == 'Prateek':
 t = int(input())
 for _ in range(t):
  test()


# cook your dish here
for i in range(int(input())):
 n, k = list(map(int,input().split()))
 remainder= (k-2) % (n-1) 
 quotient = (k-2) //(n-1) 
 k+=remainder
 if ( quotient % 2 == 1):
  feast = (1+quotient)//2 
  print(((k% 1000000007)*(feast % 1000000007))%1000000007) 
 else :
  feast = 1 + quotient 
  k=k //2 
  print(((k%1000000007)*(feast % 1000000007))%1000000007)
 
  


# cook your dish here
for t in range (int(input())):
 n, k = map(int, input().split())
 a = k - 1
 b = k * 2
 c = k + n - 1
 d = b - c - 1
 #print(a,b,c, d)
 print(a + ((d * (d + 1)) // 2) % 1000000007)

# cook your dish here
import math
t = int(input())
for _ in range(t):
 m=10**9 + 7
 s = 0
 n,k = list(map(int,input().split()))
 if(n==2):
  print(((k*(k-1))//2)%m)
 else:
  p = (k-1)//(n-1)
  s = (((p+1)*(2*k- n*p + p -2))//2)%m
  print(s)
   
   


# cook your dish here
import math
t = int(input())
for _ in range(t):
 m=10**9 + 7
 p = 0
 s = 0
 n,k = list(map(int,input().split()))
 if(n==2):
  print(((k*(k-1))//2)%m)
 else:
  while((k-1-p*(n-1))>0):
   s+=(k-1-p*(n-1))%m
   p+=1
  print(s)
   
   


# cook your dish here
import math
t = int(input())
for _ in range(t):
 m=10**9 + 7
 p = 0
 s = 0
 n,k = list(map(int,input().split()))
 if(n==2):
  print(((k*(k-1))//2)%m)
 else:
  while((k-1-p*(n-1))>0):
   s+=k-1-p*(n-1)
   p+=1
  print(s)
   
   


# cook your dish here
import math
t = int(input())
for _ in range(t):
 m=10**9 + 7
 n,k = list(map(int,input().split()))
 if(n==2):
  print(((k*(k-1))//2)%m)


mod=10**9+7

for _ in range(int(input())):
 n,k=map(int,input().split())
 if k<=n:
  print((k-1)%mod)
  continue
 x=(k-1)//(n-1)+1;
 if (x%2):
  d=(((x-1)//2)%mod)*(x%mod);
 else:
  d=((x//2)%mod)*((mod+x-1)%mod);
 d=d%mod
 x=x%mod
 k=(k-1)%mod
 n=(n-1)%mod
 ans=(k*x)%mod-(d*n)%mod;
 if ans<0:
  ans=mod+ans;
 print(ans%mod);

# cook your dish here
# cook your dish here
MOD=10**9+7
for _ in range (int(input())):
 n,k=map(int,input().split())
 a=k
 b=n+k-1
 c=(a-1)%MOD
 req=a*2-b-1
 d=n-1
 if req>0:
  if req%d==0:
   nt=req//d
  else:
   nt=req//d+1
  c+=(((nt*(2*req+(nt-1)*(-d)))//2)%MOD)%MOD
 print(c%MOD)

t=int(input())
for i in range(t):
 [n,k]=input().split()
 n=int(n)
 k=int(k)
 a=k-1
 d=1-n
 x=(a//(n-1))+1
 ans= ((x*(2*a+(x-1)*d))//2)%1000000007;
 print(ans)



from sys import stdin,stdout
Mod=10**9+7
t=int(stdin.readline())
for i in range(t):
 n,k=list(map(int,stdin.readline().split()))
 a=(k-1)%(n-1)
 d=n-1
 num=(k-1)//(n-1)+1
 res=(num*(2*a+(num-1)*d))//2
 stdout.write(str(res%Mod)+"\n")
 



def main():
 from sys import stdin,stdout
 Mod=10**9+7
 t=int(stdin.readline())
 for i in range(t):
  n,k=list(map(int,stdin.readline().split()))
  a=(k-1)%(n-1)
  d=n-1
  num=(k-1)//(n-1)+1
  res=(num*(2*a+(num-1)*d))//2
  stdout.write(str(res%Mod)+"\n")
 
def __starting_point():
 main()
__starting_point()

def main():
 Mod=10**9+7
 t=int(input())
 for i in range(t):
  n,k=list(map(int,input().split()))
  a=(k-1)%(n-1)
  d=n-1
  num=(k-1)//(n-1)+1
  res=(num*(2*a+(num-1)*d))//2
  print(res%Mod)
 
def __starting_point():
 main()
__starting_point()

for i in range(int(input())):
 n,k = [int(i) for i in input().split()]
 mod = 1000000007
 c = (k - 1) % mod
 dif = (2 * k) - (n + k - 1) - 1
 if dif > 0:
  no = dif // (n - 1)
  if dif % (n - 1) != 0:
   no += 1
  c = (c + (no * (2 * dif - (no - 1)*(n - 1)) // 2) % mod) % mod
 print(c)

# cook your dish here
t=int(input())
for _ in range(t):
 n,k=map(int,input().split())
 summation=0
 last_term=k-1
 common_difference=n-1
 first_term=last_term%common_difference
 if first_term==0:
  first_term=common_difference
 no_of_terms=(last_term-first_term)//common_difference + 1
 #print(no_of_terms,first_term,last_term,common_difference)
 summation=(((no_of_terms)*(first_term+last_term))//2)%1000000007
 print(summation)

import math
import bisect

def power(x, y, p) : 
 res = 1
 x = x%p
 while (y>0):
  if ((y&1)==1):
   res = (res*x)%p
  y = y>>1 # y = y/2 
  x = (x*x)%p 
 return res 

def inn():
 return int(input())

def inl():
 return list(map(int, input().split()))
 
MOD = 10**9+7
INF = inf = 10**18+5

for t in range(int(input())):
 n, k = inl()
 
 # if n>=k or k<3:
 #     print(k-1)
 #     continue
 
 a = k-1
 d = n-1
 m = a//d+1
 ans = ((m*(2*a-(m-1)*d))//2)%MOD
 print(ans)

import math
import bisect

def power(x, y, p) : 
 res = 1
 x = x%p
 while (y>0):
  if ((y&1)==1):
   res = (res*x)%p
  y = y>>1 # y = y/2 
  x = (x*x)%p 
 return res 

def inn():
 return int(input())

def inl():
 return list(map(int, input().split()))
 
MOD = 10**9+7
INF = inf = 10**18+5

for t in range(int(input())):
 n, k = inl()
 
 if n>=k or k<3:
  print(k-1)
  continue
 
 a = k-1
 d = n-1
 m = a//d+1
 ans = ((m*(2*a-(m-1)*d))//2)%MOD
 print(ans)

# cook your dish here
t=int(input())
mod=10**9+7
for i in range(t):
 n,k=input().split(' ')
 ki=int(k)
 ni=int(n)
 km=ki-1
 nm=ni-1
 q=km//nm
 r=km%nm
 #print(r,q)
 a=km+(q*r)+(nm*q*(q-1))//2
 ans=a%mod
 print(ans)
 #print(r,q,a)


# cook your dish here
t=int(input())
mod=10**9+7
for i in range(t):
 n,k=input().split(' ')
 ki=int(k)
 ni=int(n)
 km=ki-1
 nm=ni-1
 q=km//nm
 r=km%nm
 #print(r,q)
 a=km+(q*r)+(nm*q*(q-1))//2
 if ni==2:
  a=(((ki)*(ki-1))//2)%mod
 ans=a%mod
 print(ans)
 #print(r,q,a)


MOD = 1000000007
for _ in range(int(input())):
 n, k = map(int, input().split())
 last_term = k - 1
 if n == 2:
  ans = (last_term * (last_term + 1)) // 2
  print(ans % MOD)

 else:
  diff = n - 1
  first_term = last_term%diff
  if first_term==0:
   first_term = diff
  no_of_terms = (last_term - first_term) // diff + 1
  ans = ((2*first_term+((no_of_terms - 1) * diff)) * no_of_terms) // 2
  print(ans % MOD)

# t=int(input())
# for _ in range(t):
#     n,k=map(int,input().split())
#     summation=0
#     last_term=k-1
#     common_difference=n-1
#     first_term=last_term%common_difference
#     if first_term==0:
#         first_term=common_difference
#     no_of_terms=(last_term-first_term)//common_difference + 1
#     #print(no_of_terms,first_term,last_term,common_difference)
#     summation=(((no_of_terms)*(first_term+last_term))//2)%1000000007
#     print(summation)
#
# import math
#
# MOD = 1000000007
# t = int(input())
# for _ in range(t):
#     n, k = map(int, input().split())
#     first = k - 1;
#     diff = n - 1;
#     t = (first + diff) // (diff)
#     # print(t)
#     y = (2 * (first) - (t - 1) * (diff))
#     if (y % 2 == 0):
#         y = y // 2;
#     else:
#         t = t // 2;
#
#     ans = y * t;
#     ans = ans % MOD
#     # print("n,k:"+str(n)+" "+str(k))
#     print(ans)
MOD = 1000000007
for _ in range(int(input())):
 n,k = map(int,input().split())
 if n==2:
  last_term = k-1
  first_term = 1
  no_terms = last_term
  ans = (last_term*(last_term+1))//2
  print(ans%MOD)
  
 else:
  print(1)

# cook your dish here
from decimal import Decimal
import math
t = int(input())
for x in range(t):
 n, k = map(int, input().split())
 tot = k - 1
 if(n < k):
  left = k - n
  extra = n - 1
  if(left <= extra):
   tot += left
  else:
   y = math.ceil(Decimal(left) / Decimal(extra))
   tot += y * left - (y * (y - 1) * (extra))//2
 print(tot % 1000000007)

# cook your dish here
import math
t = int(input())
for x in range(t):
 n, k = map(int, input().split())
 tot = k - 1
 if(n < k):
  left = k - n
  extra = n - 1
  if(left <= extra):
   tot += left
  else:
   y = math.ceil(left / extra)
   tot += y * left - (y * (y - 1) * (extra))//2
 print(tot % 1000000007)

# cook your dish here
import math
t = int(input())
for x in range(t):
 n, k = map(int, input().split())
 tot = k - 1
 if(n < k):
  left = k - n
  extra = n - 1
  if(left <= extra):
   tot += left
  else:
   y = math.ceil(left / extra)
   tot = (tot + (y * left - (y * (y - 1) * (extra))//2))
 print(tot % 1000000007)