To protect people from evil, 
a long and tall wall was constructed a few years ago. 
But just a wall is not safe, there should also be soldiers on it, 
always keeping vigil. 
The wall is very long and connects the left and the right towers. 
There are exactly N spots (numbered 1 to N) on the wall for soldiers. 
The K^th spot is K miles far from the left tower and (N+1-K) miles from the right tower.


Given a permutation of spots P of {1, 2, ..., N}, soldiers occupy the N spots in that order. 
The P[i]^th spot is occupied before the P[i+1]^th spot. 
When a soldier occupies a spot, he is connected to his nearest soldier already placed to his left. 
If there is no soldier to his left, he is connected to the left tower. The same is the case with right side. 
A connection between two spots requires a wire of length equal to the distance between the two.


The realm has already purchased a wire of M miles long from Nokia, 
possibly the wire will be cut into smaller length wires. 
As we can observe, the total length of the used wire depends on the permutation of the spots P. Help the realm in minimizing the length of the unused wire. If there is not enough wire, output -1.


Input
First line contains an integer T (number of test cases, 1 ≤ T ≤ 10 ). Each of the next T lines contains two integers N M, as explained in the problem statement (1 ≤ N ≤ 30 , 1 ≤ M ≤ 1000).


Output
For each test case, output the minimum length of the unused wire, or -1 if the the wire is not sufficient.


Example

Input:
4
3 8
3 9
2 4
5 25

Output:
0
0
-1
5


Explanation:
In the 1st case, for example, the permutation P = {2, 1, 3} will use the exact 8 miles wires in total.
In the 2nd case, for example, the permutation P = {1, 3, 2} will use the exact 9 miles wires in total.
To understand the first two cases, you can see the following figures:




In the 3rd case, the minimum length of wire required is 5, for any of the permutations {1,2} or {2,1}, so length 4 is not sufficient.
In the 4th case, for the permutation {1, 2, 3, 4, 5} we need the maximum length of the wire = 20. So minimum possible unused wire length = 25 - 20 = 5.
cache_max = {}
def cached_max(function):
    global cache_max
    def wrapper(*args):
        if args in cache_max:
            return cache_max[args]
        else:
            result = function(*args)
            cache_max[args] = result 
            return result

    return wrapper

cache_min = {}
def cached_min(function):
    global cache_min
    def wrapper(*args):
        if args in cache_min:
            return cache_min[args]
        else:
            result = function(*args)
            cache_min[args] = result 
            return result

    return wrapper
# def get_wire_len(inp, i, n):
# 	flag=0
# 	for k in range(i+1):
# 		if(inp[i-k]==1):
# 			flag=1
# 			left_len=k
# 			break;
# 	if(flag==0):
# 		left_len=i+1

# 	flag=0
# 	for k in range(n-i):
# 		if(inp[i+k]==1):
# 			flag=1
# 			right_len=k
# 			break;
# 	if(flag==0):
# 		right_len=n-i	

# 	return left_len, right_len



# def get_wire(m, inp, n):
# 	global store
# 	indices=[i for i, e in enumerate(inp) if e == 0]
	
# 	if (len(indices)==0):
# 		return 0
	
# 	if(m<=0 and len(indices)!=0):
# 		return -1500000
# 	val=[]	
# 	for i in indices:
# 		#print i+1
# 		ky=marshal.dumps(tuple((inp, i, n)))
# 		if(ky not in store):
# 			store[ky]=get_wire_len(inp, i, n)
# 			left_wire_len, right_wire_len=store[ky]
# 		else:
# 			left_wire_len, right_wire_len=store[ky]
				
		
# 		if(left_wire_len+right_wire_len>m):
# 			continue
# 		#print left_wire_len, right_wire_len
# 		new_inp=inp[0:i]+[1]+inp[i+1:]
# 		key=marshal.dumps([m-(left_wire_len+right_wire_len)]+new_inp) 
# 		if(key not in store): 
# 			temp=get_wire(m-(left_wire_len+right_wire_len), new_inp, n)
# 			store[key]=temp
# 		else:
# 			temp=store[key]
# 		val.append(left_wire_len+right_wire_len+temp)

# 	if(len(val)==0):
# 		return -1500000	
# 	return(max(val))


# @cached
# def get_wire(m, a, b):
# 	# print m, a, b
# 	if(m<0):
# 		return -92233720	
# 	if(a==b):
# 		return 0	
# 	val=[(i+1-a)+(b-i)+get_wire(m-(i+1-a)-(b-i),a, i)+get_wire(m-(i+1-a)-(b-i), i+1, b) for i in range(a,b)]
# 	# val=[(i+1-a)+(b-i)+get_wire(m, a, i)+get_wire(m, i+1, b) for i in range(a,b)]
# 	# for j in range(0,len(val)):
# 	# 	if(val[j]>m):
# 	# 		val[j]=- 9223372036854775807

# 	# print val
# 	return(max(val))

@cached_max
def get_wire_max(a, b):
	# print m, a, b
	# if(m<0):
	# 	return -92233720	
	if(a==b):
		return 0	
	val=[(i+1-a)+(b-i)+get_wire_max(a, i)+get_wire_max(i+1, b) for i in range(a,b)]
	# val=[(i+1-a)+(b-i)+get_wire(m, a, i)+get_wire(m, i+1, b) for i in range(a,b)]
	# for j in range(0,len(val)):
	# 	if(val[j]>m):
	# 		val[j]=- 9223372036854775807

	# print val
	return(max(val))

@cached_min
def get_wire_min(a, b):
	# print m, a, b
	# if(m<0):
	# 	return -92233720	
	if(a==b):
		return 0	
	val=[(i+1-a)+(b-i)+get_wire_min(a, i)+get_wire_min(i+1, b) for i in range(a,b)]
	# val=[(i+1-a)+(b-i)+get_wire(m, a, i)+get_wire(m, i+1, b) for i in range(a,b)]
	# for j in range(0,len(val)):
	# 	if(val[j]>m):
	# 		val[j]=- 9223372036854775807

	# print val
	return(min(val))





t=int(raw_input())
for i in range(t):
    nm=raw_input()
    nm=nm.strip()
    nm=nm.split()
    n=int(nm[0])
    m=int(nm[1])
    # inp=[0]*n
    # wire=get_wire(m, 0, n)
    min_wire=get_wire_min(0, n)
    max_wire=get_wire_max(0, n)
    # print min_wire, max_wire
    if(min_wire>m):
    	# print 
		print -1
    elif(min_wire<=m and m<=max_wire):
		print 0
    else:
    	# print 
		print m-max_wire
    # store.clear()
    # cache.clear()