Chef wants to store some important numerical data on his personal computer. He is using a new data type that can store values only from 0 till N both inclusive. If this data type receives a value greater than N then it is cyclically converted to fit into the range 0 to N.
For example: 
Value N+1 will be stored as 0.
Value N+2 will be stored as 1. 

and so on...

Given X, the value chef wants to store in this new data type. Determine what will be the actual value in memory after storing X.

------ Input Format ------ 

- First line will contain T, number of testcases. Then the testcases follow.
- Each testcase contains a single line of input, two space separated integers N, X - the maximum value a data type can store and the value Chef wants to store in the data type respectively.

------ Output Format ------ 

For each testcase, output in a single line the value which will be actually stored in memory.

------ Constraints ------ 

$1 ≤ T ≤ 3000$
$1 ≤ N ≤ 50$
$0 ≤ X ≤ 50$

----- Sample Input 1 ------ 
5
15 0
15 10
11 12
27 37
50 49
----- Sample Output 1 ------ 
0
10
0
9
49
----- explanation 1 ------ 
Test Case $1$: The data type can store values from $0$ to $15$. If we try to put $0$ in this data type, then the stored value will be the same, that is $0$.

Test Case $2$: The data type can store values from $0$ to $15$. If we try to put $10$ in this data type, then the stored value will be the same, that is $10$.

Test Case $3$: The data type can store values from $0$ to $11$. If we try to put $12$ in this data type, then the stored value will cyclically come back to $0$. Hence the output is $0$.

Test Case $4$: The data type can store values from $0$ to $27$. If we try to put $37$ in this data type, then the stored value will cyclically convert to $9$. Hence the output is $9$.

Difficulty: EASY

Solutions:
t = int(input())
for distractions in range(t):
	(X, N) = map(int, input().split())
	print(N % (X + 1))


goals = int(input())
for distractions in range(goals):
	(wife, life) = map(int, input().split())
	print(life % (wife + 1))


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	print(x % (n + 1))


for i in range(int(input())):
	(a, b) = map(int, input().split())
	print(b % (a + 1))


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	if x <= n and x >= 0:
		print(x)
	elif x > n:
		if x - n - 1 > n:
			while x - n - 1 > n:
				x = x - n - 1
			print(x - n - 1)
		else:
			print(x - n - 1)


for i in range(int(input())):
	(n, x) = map(int, input().split())
	if n >= x:
		print(x)
	else:
		print(x % (n + 1))


for i in range(int(input())):
	(N, V) = map(int, input().split())
	print(V % (N + 1))


def ch(n, x):
	return x - n - 1
t = int(input())
for i in range(t):
	(n, x) = map(int, input().split())
	while x > n:
		k = ch(n, x)
		x = k
	print(x)


for i in range(int(input())):
	(N, X) = map(int, input().split())
	print(X % (N + 1))


t = int(input())
for tc in range(t):
	(n, x) = map(int, input().split())
	if x > n:
		print(x % (n + 1))
	else:
		print(x)


for _ in range(int(input())):
	(N, X) = map(int, input().split())
	print(X % (N + 1))


for t in range(int(input())):
	(n, x) = [int(_) for _ in input().split()]
	n += 1
	print(x % n)


s = int(input())
for i in range(s):
	(a, b) = map(int, input().split(' '))
	if b <= a:
		print(b)
	else:
		while b > a:
			b = b - a - 1
		print(b)


for t in range(int(input())):
	(n, x) = map(int, input().split())
	if n >= x:
		print(x)
	elif n < x:
		print(x % (n + 1))


T = int(input())
for _ in range(T):
	a = list(map(int, input().split()))
	if a[1] > a[0]:
		print(a[1] % (a[0] + 1))
	else:
		print(a[1])


t = int(input())
for i in range(t):
	(n, x) = map(int, input().split())
	print(x % (n + 1))


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	if x <= n:
		print(x)
	else:
		while x > n:
			x -= n + 1
		print(x)


for i in range(int(input())):
	a = [int(x) for x in input().split()]
	if a[0] < a[1]:
		print(a[1] % (a[0] + 1))
	else:
		print(a[1])


T = int(input())
x = range(T)
for i in x:
	(a, b) = map(int, input().split())
	if a >= b:
		print(b)
	else:
		print(b % (a + 1))


t = int(input())
for i in range(t):
	(n, x) = list(map(int, input().split()))
	if x <= n:
		print(x)
	else:
		m = x % (n + 1)
		print(m)


T = int(input())
for tc in range(T):
	(n, x) = map(int, input().split(' '))
	if n >= x:
		print(x)
	else:
		while x > n:
			x = x - n - 1
		print(x)


T = int(input())
for i in range(T):
	(N, X) = map(int, input().split())
	if N >= X:
		print(X)
	else:
		while X > N:
			X = X - N - 1
		print(X)


t = int(input())
while t:
	(x, y) = map(int, input().split())
	print(y % (x + 1))
	t -= 1


for i in range(int(input())):
	(n, x) = map(int, input().split())
	while True:
		if x > n:
			x = x - (n + 1)
		else:
			print(x)
			break


t = int(input())
while t > 0:
	(n, x) = map(int, input().split(' '))
	if n >= x:
		print(x)
	else:
		print(x % (n + 1))
	t = t - 1


for _ in range(int(input())):
	(A, B) = map(int, input().split())
	if B <= A:
		print(B)
	else:
		print(B % (A + 1))


for _ in range(int(input())):
	(x, y) = map(int, input().split())
	if y <= x:
		print(y)
	else:
		print(y % (x + 1))


n = int(input())
for _ in range(n):
	(a, b) = map(int, input().split())
	if b > a:
		t = b % (a + 1)
		print(t)
	else:
		print(b)


for i in range(int(input())):
	(N, X) = map(int, input().split())
	if X > N:
		Y = X % (N + 1)
		print(Y)
	else:
		print(X)


for __ in range(int(input())):
	(N, X) = map(int, input().split(' '))
	if X <= N:
		print(X)
	else:
		print(X % (N + 1))


t = int(input())
for i in range(t):
	(n, x) = [int(x) for x in input().split()]
	l = 0
	if x <= n:
		print(x)
	else:
		while n < x:
			x = x - n - 1
		print(x)