Kabir Singh is playing a game on the non-negative side of  x-axis. It takes him $1 second$ to reach from Pth position to (P−1)th position or (P+1)th position. 
Kabir never goes to the negative side and also doesn't stop at any moment of time.
The movement can be defined as  : 
- At the beginning he is at $x=0$ , at time $0$
- During the first round, he moves towards $x=1$ and comes back to the $x=0$ position.
- In the second round, he moves towards the $x=2$ and comes back again to $x=0$.
- So , at $Kth$ round , he moves to $x=K$ and comes back to $x=0$
So in this way game goes ahead.
For Example, the path of Kabir for $3rd$ round is given below.
$0−1−2−3−2−1−0$
The overall path followed by Kabir would look somewhat like this:
$0−1−0−1−2−1−0−1−2−3−2−1−0−1−2−3−4−3−…$
Now the task is , You are given Two Non-Negative integers $N$ , $K$ .
You have to tell the time at which Kabir arrives at $x=N$ for the $Kth$ time.
Note - Kabir visits all the points , he can not skip or jump over one point.

-----Input:-----
- First line will contain $T$, number of testcases. Then the testcases follow. 
- Each testcase contains of a single line of input, two integers $N, K$. 

-----Output:-----
For each testcase, output in a single line answer i.e Time Taken by Kabir Singh modulo 1000000007.

-----Constraints-----
- $1 \leq T \leq 10^5$
- $0 \leq N \leq 10^9$
- $1 \leq K \leq 10^9$

-----Sample Input:-----
4

0 1
1 1
1 3
4 6

-----Sample Output:-----
0
1
5
46

-----EXPLANATION:-----
Test Case 1:
Kabir starts the journey from the $N=0$ at time $t=0$ and it's the first time$ (K=1)$, he is here. So, the answer is $0$.
Test Case 3:
The path followed by Kabir to reach 1 for the third time is given below.
$0−1−0−1−2−1$
He reaches $1$ for the third time at $ t=5$.

```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 = 'import math\r\nMOD = 1000000007\r\n\r\nT = int(input())\r\n\r\n# d = {0: [0, 2, 6, 12, 20, 30, 42, 56, 72], 1: [1, 3, 5, 7, 11, 13, 19, 21, 29, 31, 41, 43, 55, 57, 71, 73, 89], 2: [4, 8, 10, 14, 18, 22, 28, 32, 40, 44, 54, 58, 70, 74, 88], 3: [9, 15, 17, 23, 27, 33, 39, 45, 53, 59, 69, 75, 87], 4: [16, 24, 26, 34, 38, 46, 52, 60, 68, 76, 86], 5: [25, 35, 37, 47, 51, 61, 67, 77, 85], 6: [36, 48, 50, 62, 66, 78, 84], 7: [49, 63, 65, 79, 83], 8: [64, 80, 82], 9: [81]}\r\nfor t in range(T):\r\n    i,N = list(map(int, input().split()))\r\n    if i == 0:\r\n        N = N*2\r\n    tmp = math.floor(N/2)\r\n    tmp2 = math.floor((N-1)/2)\r\n    ans = (i*i)%MOD + (tmp*2*i)%MOD + ( tmp2*(tmp2+1) )%MOD\r\n    print(ans%MOD)\r\n'
_co = compile(_CODE, USER_FILENAME, "exec")
exec(_co, ns, ns)

```

Measured memory_bytes: 13113