Chef has a calculator which has two screens and two buttons. Initially, each screen shows the number zero. Pressing the first button increments the number on the first screen by 1, and each click of the first button consumes 1 unit of energy.
Pressing the second button increases the number on the second screen by the number which is currently appearing on the first screen. Each click of the second button consumes B units of energy.
Initially the calculator has N units of energy.
Now chef wonders what the maximum possible number is, that he gets on the second screen of the calculator, with the limited energy.

-----Input-----
The first line of the input contains an integer T denoting the number of test cases.
Each test case is described using a single line containing two integers, N and B.

-----Output-----
For each test case, output a single line containing the answer to this test case.

-----Constraints-----
- 1 ≤ T ≤ 10,000
- 1 ≤ N, B ≤ 1,000,000,000

-----Subtasks-----
- Subtask 1 (20 points): 1 ≤ N, B ≤ 1,000
- Subtask 2 (80 points): Original constraints

-----Example-----
Input:
3
10 2
8 5
6 1

Output:
12
3
9

-----Explanation-----
Example case 1. There are 10 units of energy available. Pressing second button takes 2 units of energy. Chef can achieve 12 on the second screen as follows.

- Press first button to get scores (1, 0). 9 units of energey is left.
- Press first button to get scores (2, 0). 8 units of energy remaining.
- Press first button to get scores (3, 0). 7 units of energy remaining.
- Press first button to get scores (4, 0). 6 units of energy remaining.
- Press second button to get scores (4, 4). 4 units of energy remaining.
- Press second button to get scores (4, 8). 2 units of energy remaining.
- Press second button to get scores (4, 12). 0 units of energy remaining.

Difficulty: interview

Starter code:

Solutions:
# cook your dish here
for i in range(int(input())):
 n,b=map(int,input().split())
 ans=round(n/(2*b))*(n-b*round((n/(2*b))));
 print(ans)

import math
n=int(input())
for i in range(n):
 a,b=list(map(int,input().split()))
 if a>b:
  a1=math.ceil(a/(2*b))
  b1=a-a1*b
  a2=math.floor(a/(2*b))
  b2=a-a2*b
  print(max(a1*b1,a2*b2))
 else:
  print(0)
  
 


n=int(input())
for i in range(n):
 a,b=list(map(int,input().split()))
 if a>b:
  t=a//b
  max1=1
  ans=0
  while(t>=t/2):
   ans=(a-b*t)*t
   max1=max(ans,max1)
   t-=1
  print(max1)
 else:
  print(0)
  
 


n=int(input())
for i in range(n):
 a,b=map(int,input().split())
 if a>b:
  t=a//b
  max1=1
  ans=0
  while(t>0):
   ans=(a-b*t)*t
   max1=max(ans,max1)
   t-=1
  print(max1)
 else:
  print(0)

# cook your dish here
t = int(input())
for i in range(t):
 # n for total energy, b for energy of second screen
 n,b = map(int,input().split(" "))
 num = n//b
 final = [i*(n-b*i) for i in range(num+1)]
 print(max(final))

def function(x,n):
 if x>n:
  return 0
 return x*(n-x*b)
for _ in range(int(input())):
 n,b=list(map(int,input().split()))
 #print(n//(2*b),n//(2*b)+1)
 print(max((function(n//(2*b),n),function(n//(2*b)+1,n))))
 
 


def closestNumber(n, m) : 
# Find the quotient 
 q = int(n / m) 
 
# 1st possible closest number 
 n1 = m * q 
 
# 2nd possible closest number 
 if((n * m) > 0) : 
  n2 = (m * (q + 1)) 
 else : 
  n2 = (m * (q - 1)) 
  
 # if true, then n1 is the required closest number 
 if (abs(n - n1) < abs(n - n2)) : 
  return n1 
  
 # else n2 is the required closest number  
 return n2 

T = int(input())
for j in range(1, T+1):
 N, B = input().split()
 N = int(N)
 B = int(B)
 p = N % B
 k = N
 fs = 0
 maxim = 0
 
 print(int((N-closestNumber(int(N/2), B))*(closestNumber(int(N/2), B))/B))
  
  


T = int(input())
for j in range(1, T+1):
 N, B = input().split()
 N = int(N)
 B = int(B)
 p = N % B
 k = N
 fs = 0
 maxim = 0
 for i in range(p, N-B+1, B):
  N = k
  fs = 0
  ss = 0
  fs = fs + i
  N = N-i
  while (N>=B):
   ss = ss + fs
   N = N-B
  if ss > maxim:
   maxim = ss
 print(maxim)
  
  


T = int(input())
for j in range(1, T+1):
 N, B = input().split()
 N = int(N)
 B = int(B)
 k = N
 fs = 0
 maxim = 0
 for i in range(1, N-B+1):
  N = k
  fs = 0
  ss = 0
  fs = fs + i
  N = N-i
  while (N>=B):
   ss = ss + fs
   N = N-B
  if ss > maxim:
   maxim = ss
 print(maxim)
  
  


T = int(input())
for j in range(1, T+1):
 N, B = input().split()
 N = int(N)
 B = int(B)
 k = N
 fs = 0
 maxim = 0
 for i in range(1, N+1):
  N = k
  fs = 0
  ss = 0
  fs = fs + i
  N = N-i
  while (N>=B):
   ss = ss + fs
   N = N-B
  if ss > maxim:
   maxim = ss
 print(maxim)
  
  


from math import *
for j in range(int(input())):
 n,b=list(map(int,input().split()))
 a=n/(2*b)
 a1=ceil(a)
 a2=floor(a)
 d=(n-a1*b)*a1
 e=(n-a2*b)*a2
 print(max(d,e))


import math
def ushijima(x):
 return (n-b*x)*x
t = int(input())
for i in range(t):
 (n,b) = (int(x) for x in input().split())
 y1 = math.floor((math.floor(n/2))/b)
 y2 = math.floor((math.ceil(n/2))/b)
 y3 = math.ceil((math.floor(n/2))/b)
 y4 = math.ceil((math.ceil(n/2))/b)
 if y1==0 and y2==0 and y3==0 and y4==0:
  print("0")

 else:
  print(max(ushijima(y1),ushijima(y2),ushijima(y3),ushijima(y4)))

from math import floor,ceil
for _ in range(int(input())):
 n,k=map(int,input().split())
 t1=ceil(ceil(n/2)/k)
 t2=ceil(floor(n/2)/k)
 t3=floor(ceil(n/2)/k)
 t4=floor(floor(n/2)/k)
 if not t1:t1=1
 if not t2:t2=1
 if not t3:t3=1
 if not t4:t4=1
 t1= int((n-k*t1)*t1)
 t2= int((n-k*t2)*t2)
 t3= int((n-k*t3)*t3)
 t4= int((n-k*t4)*t4)
 if t1<0 and t2<0 and t3<0 and t4<0:
  print(0)
 else:
  print(max(t1,t2,t3,t4))

for _ in range(int(input())):
 n,k=list(map(int,input().split()))
 t1=-(-(n/2)//k)
 t2=(n/2)//k
 if not t1:t1=1
 if not t2:t2=1
 t1= int((n-k*t1)*t1)
 t2= int((n-k*t2)*t2)
 if t1<0 and t2<0:
  print(0)
 else:
  print(max(t1,t2))