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.

```python

USER_FILENAME = "<user_code>"
import sys, json, builtins
import math, heapq, bisect, itertools, functools, collections, statistics, fractions, decimal, operator, array, random, re, string, os, pathlib
try:
    import resource as _res
except Exception:
    _res = None
from collections import Counter, defaultdict, deque, OrderedDict
from functools import lru_cache, reduce
from itertools import accumulate, permutations, combinations, product
from math import gcd, ceil, floor, sqrt
from decimal import Decimal
try:
    from typing import *
except Exception:
    pass
try:
    sys.setrecursionlimit(1_000_000)
except Exception:
    pass
try:
    import site as _site
    try:
        _sys_sites = _site.getsitepackages() if hasattr(_site, "getsitepackages") else []
        for _p in _sys_sites:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
    try:
        _usp = _site.getusersitepackages()
        if isinstance(_usp, str):
            _usp = [_usp]
        for _p in _usp:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
except Exception:
    pass

ns = {"__name__": "__main__"}
for _k, _v in list(globals().items()):
    if not _k.startswith("_"):
        ns[_k] = _v
_CODE = 'from math import floor,ceil\nfor _ in range(int(input())):\n n,k=map(int,input().split())\n t1=ceil(ceil(n/2)/k)\n t2=ceil(floor(n/2)/k)\n t3=floor(ceil(n/2)/k)\n t4=floor(floor(n/2)/k)\n if not t1:t1=1\n if not t2:t2=1\n if not t3:t3=1\n if not t4:t4=1\n t1= int((n-k*t1)*t1)\n t2= int((n-k*t2)*t2)\n t3= int((n-k*t3)*t3)\n t4= int((n-k*t4)*t4)\n if t1<0 and t2<0 and t3<0 and t4<0:\n  print(0)\n else:\n  print(max(t1,t2,t3,t4))'
_co = compile(_CODE, USER_FILENAME, "exec")
exec(_co, ns, ns)

```

Measured memory_bytes: 13431