Chef is playing a game on the non-negative x-axis. It takes him $1$ second to reach from $i^{th}$ position to $(i-1)^{th}$ position or $(i+1)^{th}$ position. The chef never goes to the negative x-axis. Also, Chef doesn't stop at any moment of time.
The movement of chef can be described as follows.
- At the start he is standing at $x=0$ at time $0$.
- In 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$. 
- Generalizing, in the $k^{th}$ round, he moves from $x=0$ to $x=k$ and then returns back to $x=0$ at the end of the round. This goes on as the game progresses.
For Example, the path of Chef for $3^{rd}$ round is given below.
$0 - 1 - 2 - 3 - 2 - 1 - 0$ 
The overall path followed by Chef would look somewhat like this:
$0 - 1 - 0 - 1 - 2 - 1 - 0 - 1 - 2 - 3 - 2 - 1 - 0 - 1 - 2 - 3 - 4 - 3 - …$
You are given two non-negative integers $N$ and $K$. You have to tell the time at which Chef arrives at $x=N$ for the $K^{th}$ time. 
Note - Chef can not skip a position while visiting the positions.

-----Input:-----
- The first line contains $T$ the number of test cases. Then the test cases follow.
- Each test case contains a single line of two integers $N$ and $K$.

-----Output:-----
For each test case, print a single line containing one integer -- the time taken by the chef to arrive at $x=N$ for the $K^{th}$ time by modulo $1,000,000,007$.

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

-----Sample Input:-----
5
0 1
1 1
2 1
1 3
4 6

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

-----Explanation:-----
Test Case 1:

Chef 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 2:

Chef starts the journey from the $N = 0$ at time $t = 0$ then goes to $N = 1$ at $t = 1$ and it's the first time $(K = 1)$, he is here. So, the answer is $1$.
Test Case 4:

The path followed by Chef 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 = 't=int(input())\nfor hh in range(0,t):\n    n,k=[int(x) for x in input().split()]\n    # 2 3\n    m=1000000007\n    pos=n\n    if(n==0):\n        rem=k-1\n        cur=(rem*(rem+1))%m\n        print(cur)\n    elif(k==1):\n        prev=(pos*(pos-1))%m\n        curr=(prev+pos)%m\n        print(curr)\n    else:\n        # if(k%2==1):\n        #     p=k//2\n        #     # p=1\n        #     inipos=pos\n        #     pos=pos+p-1\n        #     prev=pos*(pos+1)\n        #     print(prev,pos)\n        #     curr=prev+inipos\n        #     print(curr)\n        # else:\n        #     p=k//2 -1 \n        #     inipos=pos\n        #     # pos=4 k = 6 p=2\n        #     pos=pos+p-1\n        #     prev=pos*(pos+1)\n        #     now=inipos+p\n        #     rem=now-inipos\n        #     print(prev,now,pos,p,rem)\n        #     curr=prev+now+rem\n        #     print(curr)\n        if(k%2==1):\n            k-=1\n            p=k//2\n            # p=1\n            ans=2*pos\n            inipos=pos\n            # pos=4 k = 6 p=2\n            pos=(pos+p-1)%m\n            prev=(pos*(pos+1))%m\n            now=(inipos+p)%m\n            rem=(now-inipos+m)%m\n            # print(prev,now,pos,p,rem)\n            curr=(prev+now+rem)%m\n            print(curr)\n        else:\n            k-=1\n            p=k//2\n            # p=1\n            # pos =4 k =6 k=5 p=2\n            inipos=pos\n            pos=(pos+p)%m\n            prev=(pos*(pos+1))%m\n            # print(prev,pos)\n            curr=(prev+inipos)%m\n            print(curr)'
_co = compile(_CODE, USER_FILENAME, "exec")
exec(_co, ns, ns)

```

Measured memory_bytes: 13291