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 = 'def closestNumber(n, m) : \n# Find the quotient \n q = int(n / m) \n \n# 1st possible closest number \n n1 = m * q \n \n# 2nd possible closest number \n if((n * m) > 0) : \n  n2 = (m * (q + 1)) \n else : \n  n2 = (m * (q - 1)) \n  \n # if true, then n1 is the required closest number \n if (abs(n - n1) < abs(n - n2)) : \n  return n1 \n  \n # else n2 is the required closest number  \n return n2 \n\nT = int(input())\nfor j in range(1, T+1):\n N, B = input().split()\n N = int(N)\n B = int(B)\n p = N % B\n k = N\n fs = 0\n maxim = 0\n \n print(int((N-closestNumber(int(N/2), B))*(closestNumber(int(N/2), B))/B))\n  \n  \n'
_co = compile(_CODE, USER_FILENAME, "exec")
exec(_co, ns, ns)

```

Measured memory_bytes: 13277