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$.

Difficulty: interview

Starter code:

Solutions:
# cook your dish here
T=int(input())
MOD=int(1e9+7)
for t in range(T):
    N,K=[int(a) for a in input().split()]
    M=K//2
    # ans= ((K%2)?( (N+M)*(N+M) + M ):( (N+M)*(N+M) - M) )
    ans=(N+M)*(N+M) -M
    if(K%2):
        ans+=2*M
    if(N==0):
        ans=K*(K-1)
    print(ans%MOD) 

# cook your dish here
t=int(input())
for _ in range(t):
    n,k=list(map(int,input().split()))
    M = 1000000007
    if(n==0):
        m=k-1
        total=(m*(m+1))
        print(total % M)
    else:
        if(k % 2==0):
            m=(k-2)//2 + n
            total=(m*(m+1)) + n
            print(total % M)
        else:
            m=(k)//2 + n
            total=(m*(m+1)) - n
            print(total % M)


mod = 10**9 + 7
for t in range(int(input())):
    n, k = map(int, input().split())
    if n == 0:
        if k == 1:
            print(0)
        else:
            print(int((k * (1 + k)) / 2) % mod)
        continue
    futile_moves = (n - 1)
    if k == 1:
        f_time = futile_moves * (1 + futile_moves)
        print((f_time + n) % mod)
        continue
    k -= 1
    futile_moves += 1
    if k % 2 == 0:
        futile_moves += (int(k / 2) - 1)
    else:
        futile_moves += int(k / 2)
    f_time = futile_moves * (1 + futile_moves)
    if k % 2 == 0:
        f_time += (futile_moves + 1) * 2 - n
    else:
        f_time += n
    f_time %= mod
    print(f_time)

# cook your dish here
"""
Created on Sat May 23 23:48:49 2020

@author: aurouS_EeRiE
"""


def solve(n, k):
    ans = 0
    if n == 0:
        if k == 1:
            return 0
        else:
            return ((k - 1) * (k)) % ((10 ** 9) + 7)
    if k == 1:
        return (n * n) % ((10 ** 9) + 7)
    if k % 2 == 0:
        ans = n * n + n * k + int(int((k - 1) / 2) * int((k - 1) / 2 + 1))
    if k % 2 != 0:
        ans = n * n + (2 * n) * (max(0, int((k - 1) / 2))) + int(int((k - 1) / 2) * int((k - 1) / 2 + 1))
    return ans % ((10 ** 9) + 7)

t = int(input())
for i in range(t):
    n, k=map(int, input().split())
    print(solve(n, k))

# cook your dish here
mod = 10**9 + 7

for k in range(int(input())):
	num, times = map(int, input().split())

	if num == 0:
		x = times - 1
		ans = (((x%mod)*(x%mod))%mod + x%mod)%mod
	else:
		if times%2 == 0:
			x = num + (times-1)//2
			ans = ((((x%mod)*(x+1)%mod) + x%mod) + num%mod - x%mod)%mod
		else:
			x = num + (times-1)//2
			ans = ((((x%mod)*(x+1)%mod) + x%mod) - num%mod - x%mod)%mod

	print(ans)

import math
mod=1000000007
T=int(input())
for _ in range(T):
    n,m=list(map(int,input().split()))
    if (n==0):
        print((m*(m-1))%mod)
        
    elif (m==1):
        print(((n*(n-1))+n)%mod)

    else:
        val=n-1+(math.ceil((m-1)/2))
        fv=(val*(val+1))%mod
        if ((m-1)%2==0):
            fv=(fv+(2*(val+1))-n)%mod
        else:
            fv=(fv+n)%mod

        print(fv%mod)


# cook your dish here
mod=10**9+7
for _ in range(int(input())):
    n,k=map(int,input().split())
    if n==0:
        print(k*(k-1))
    else:
        ans=0
        tmp=k//2
        if k&1:
            ans+=k-1
        ans+=(n+tmp)*(n+tmp)-tmp
        print(ans%mod)

# cook your dish here
"""
Created on Sat May 23 23:28:42 2020

Title: Walking Man

Contest: LockDown Test 4.0

@author: mr._white_hat_
"""

for _ in range(int(input())):
    n, k = map(int, input().split())
    if n==0:
        print((k*(k-1))% 1000000007)
        continue
    x = int((k - k % 2) / 2)
    ans = (n + x - 1)*(n + x) + n + 2*(k % 2)*(x) 
    print(ans % 1000000007)

# cook your dish here
T=int(input())
MOD=int(1e9+7)
for t in range(T):
    N,K=[int(a) for a in input().split()]
    M=K//2
    ans=(N+M)*(N+M) -M
    if(K%2):
        ans+=2*M
    if(N==0):
        ans=K*(K-1)
    print(ans%MOD) 

# cook your dish here
t=int(input())
for _ in range(t):

    [n,k]=[int(x) for x in input().split()]
    if n==0:
        print(((k-1)*k)%1000000007)
        continue
    
    if k%2==0:
        x=int(k/2)-1
        print( ((n+x)*(n+x+1)+ n ) % 1000000007 )
    else:
        x=int((k-3)/2)
        print( ((n+x) * (n+x+1) + n+2*x+2 ) % 1000000007   )

import math
MOD = 1000000007

T = int(input())

# 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]}
for t in range(T):
    i,N = list(map(int, input().split()))
    if i == 0:
        N = N*2
    tmp = math.floor(N/2)
    tmp2 = math.floor((N-1)/2)
    ans = (i*i)%MOD + (tmp*2*i)%MOD + ( tmp2*(tmp2+1) )%MOD
    print(ans%MOD)


# cook your dish here
t=int(input())

for _ in range(0,t):
    n,k= map(int, input().split())
    if n!=0:
        fn=n+(k//2)
        if k%2==0:
            print((fn**2-fn+n)%1000000007)
        else:
            print((fn**2+fn-n)%1000000007)
    else:
        print((k*(k-1))%1000000007)

# import sys
# sys.stdin = open('input.txt','r')
# sys.stdout = open('output1.txt','w')
import math
from sys import stdin,stdout
from math import gcd,sqrt,ceil,floor,inf
from copy import deepcopy
ii1=lambda:int(stdin.readline().strip())
is1=lambda:stdin.readline().strip()
iia=lambda:list(map(int,stdin.readline().strip().split()))
isa=lambda:stdin.readline().strip().split()
mod=1000000007
# fib=[1,1]
# a=1
# b=1
# for i in range(100001):
#     a,b=b,a+b
#     fib.append(b%mod)
# print(fib[0:10])
for _ in range(ii1()):
    n,k=iia()
    new=k-1
    if n==0:
        if k==1:
            ans=0
        else:
            ans=(k-1)*(k)
    elif k==1:
        ans=n*(n+1)-n
    elif k%2==0:
        ans=(n+(new//2))*(n+(new//2)+1)+n
    else:
        ans=(n+(new//2))*(n+(new//2)+1)-n
    print(ans%mod)








t = int(input())
for i in range(t):
    n, k = [int(x) for x in input().split()]
    if n == 0:
        ans = (k - 1) * k
        print(ans % 1000000007)
        continue
    k -= 1
    if k == 0:
        ans = n * (n - 1) + n
        print(ans % 1000000007)
    elif k % 2 != 0:
        p = n + (k // 2)
        ans = p * (p + 1) + n
        print(ans % 1000000007)
    else:
        k -= 2
        p = n + (k // 2)
        ans = p * (p + 1) + (p + 1) + (p + 1 - n)
        print(ans % 1000000007)


t = int(input())
mod = 10**9 + 7
for _ in range(t):
    n, k = list(map(int, input().split()))
    if n==0:
        k-=1
        print(k**2+k)
        continue
    if k==1:
        l = n-1
        nz = l**2 + l
        print(nz+n)
        continue
    rem = k%2
    up = k//2
    l = up + n - 1
    nz = l**2 + l
    #print(nz)
    if rem==0:
        ans = nz + n
        print(ans%mod)
    else:
        ans = nz + 2*l + 2 - n
        print(ans%mod)


test=int(input())
for _ in range(test):
    n,k=map(int,input().split())
    ans=pow(n,2,1000000007)
    k=k-1
    i=0
    while(k!=0):
        ans+=(2*n)%1000000007
        if n!=0:
            k-=1
        if k==0:
            break
        ans+=(i+2)%1000000007
        k-=1
        
        i=i+2
    print(ans%1000000007)

#dt = {} for i in x: dt[i] = dt.get(i,0)+1
ipnl = lambda n: [int(input()) for _ in range(n)]
inp = lambda :int(input())
ip = lambda :[int(w) for w in input().split()]

M = 10**9+7
for _ in range(inp()):
    n,k = ip()
    if n == 0:
        t = k*(k-1)
        print(t%M)
        continue
    if k == 1:
        print(n*n)
        continue
    kk = k//2
    t = (n+kk)*(n+kk)
    if k%2:
        t += kk
    else:
        t -= kk
    print(t%M)

import sys
from random import choice,randint
inp=sys.stdin.readline
out=sys.stdout.write
flsh=sys.stdout.flush
 
sys.setrecursionlimit(10**9)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
 
def MI(): return map(int, inp().strip().split())
def LI(): return list(map(int, inp().strip().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines().strip()]
def LI_(): return [int(x)-1 for x in inp().strip().split()]
def LF(): return [float(x) for x in inp().strip().split()]
def LS(): return inp().strip().split()
def I(): return int(inp().strip())
def F(): return float(inp().strip())
def S(): return inp().strip()
def pf(s): return out(s+'\n')
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)

def main():
    from math import ceil
    t = I()
    l = []
    for _ in range(t):
        n,k=MI()
        if n==0:
            k-=1
            ans = ((k)*((k+1)))%mod
            l.append(ans)
        else:
            # if k==1:
            #     ans = ((((n)*((n-1)))%mod)+ n%mod)%mod
            #     l.append(ans)
            # else:
            #     k-=1
            #     lr = (n%mod+((ceil(k/2)%mod))%mod
            #     ans = ((lr*((lr-1))%mod
            #     if k%2!=0:
            #         ans= (ans%mod + n%mod)%mod
            #     else:
            #         ans = ((ans%mod)+((lr+n)%mod))%mod
            #     l.append(ans)
            if k%2!=0:
                lr = k//2
                l.append(((n*n)%mod+(lr*((2*n)%mod))%mod+(lr*(lr+1))%mod)%mod)
            else:
                lr = k//2
                l.append(((n*n)%mod + (lr*(2*n)%mod)%mod + (lr*(lr-1))%mod)%mod)

    for i in range(t):
        pf(str(l[i]))

def __starting_point():
    main()
__starting_point()

MOD = 10**9+7
for lo in range(int(input())):
    n, k = list(map(int,input().split()))
    if n==0:
        print(k*(k-1) % MOD)
        continue
    
    c = k//2
    x = 1
    if k%2==0:
        x = 0
    
    y = c+x+n
    
    if x==0:
        ans = (y*(y-1))+n
    else:
        ans = (y*(y-1))-n
    
    print(ans % MOD)


import math
t = int(input())
while t > 0:
	k = input()
	if len(k) == 0: continue;

	n, k = k.split()
	n = int(n)
	k = int(k)

	
	if n == 0 and  k == 1 : 
		print("0")
		t-=1
		continue
	elif n == 0:
		print((k*(k-1))%1000000007)
		t-=1
		continue
	
	level = n + math.ceil((k + 1)/2)
	time = (level - 1)*(level - 2)

	if k%2 == 0 : time = time + n;
	else : time = time + 2*(level-1) - n;
	print(time%1000000007)
	t-=1

'''
    leave a comment if you don't understand something :)
    thanks for choosing my code!! ~Srikar

'''

T=int(input())
mod=1000000007
for _ in range(T):
    n,k=list(map(int,input().split()))
    if n==0:
        k-=1
        print((k*(k+1))% mod )
    else:
        if k==1:
            print((n**2) % mod)
            
        
        else:
            if k%2==0:
                a=k//2 #even numbers
                b=a-1 #odd numbers
                
                ans=((n**2) % mod)+((a*((2*n)%mod))%mod)+((b*(b+1))%mod)
            else:
                k-=1
                a=k//2 #even numbers
                b=a #odd numbers
                
                ans=((n**2) % mod)+((a*((2*n)%mod))%mod)+((b*(b+1))%mod)
                
            print(ans%mod)
                
        
    
        


mod = 1000000007
for _ in range(int(input())):
        n,k = list(map(int, input().split()))
        if n == 0:
                k -= 1
                print(k*(k+1) % mod)
        else:
                if k==1:
                    print((n**2) % mod)
                else:
                    if k%2==0:
                        a=k // 2
                        b=a - 1
                        
                        ans=((n**2) % mod)+((a*((2*n)%mod))%mod)+((b*(b+1))%mod)
                    else:
                        k -= 1
                        a = k // 2
                        b = a
                        
                        ans = ((n**2) % mod)+((a*((2*n)%mod))%mod)+((b*(b+1))%mod)
                        
                    print(ans%mod)