Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.

You are given two integers $N$ and $K$. You may perform the following operation any number of times (including zero): change $N$ to $N-K$, i.e. subtract $K$ from $N$. Find the smallest non-negative integer value of $N$ you can obtain this way.

------  Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first and only line of each test case contains two space-separated integers $N$ and $K$.

------  Output ------
For each test case, print a single line containing one integer — the smallest value you can get.

------  Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{9}$
$0 ≤ K ≤ 10^{9}$

------  Subtasks ------
Subtask #1 (100 points): original constraints

----- Sample Input 1 ------ 
3

5 2

4 4

2 5
----- Sample Output 1 ------ 
1

0

2
----- explanation 1 ------ 
Example case 1:
- First, we change $N = 5$ to $N - K = 5 - 2 = 3$.
- Then, we have $N = 3$ and we change it to $N - K = 3 - 2 = 1$.

Since $1 < K$, the process stops here and the smallest value is $1$.

Example case 2: We change $N = 4$ to $N - K = 4 - 4 = 0$. Since $0 < K$, the process stops here and the smallest value is $0$.

Example case 3: Since $2 < K$ initially, we should not perform any operations and the smallest value is $2$.

Difficulty: EASY

Solutions:
for i in range(int(input())):
	(n, k) = list(map(int, input().split()))
	if k == 0:
		print(n)
	else:
		print(n % k)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	if k == 1:
		print('0')
	elif k == 0:
		print(n)
	else:
		while n >= k:
			n = n - k
		print(n)


for _ in range(int(input())):
	(n, k) = tuple(map(int, input().split()))
	if k != 0:
		print(n % k)
	else:
		print(n)


testcases = int(input())
while testcases:
	(N, K) = map(int, input().split())
	if N < K or K == 0:
		print(N)
	else:
		rem = N % K
		print(rem)
	testcases -= 1


t = int(input())
while t > 0:
	(n, k) = map(int, input().split())
	if n >= k and k != 0:
		print(n % k)
	else:
		print(n)
	t = t - 1


t = int(input())
for i in range(0, t):
	(n, k) = map(int, input().split())
	if n >= k and k != 0:
		print(n % k)
	else:
		print(n)


for i in range(int(input())):
	(a, b) = map(int, input().split())
	if a < b or b == 0:
		print(a)
	else:
		print(a % b)


from sys import stdin, stdout
input = stdin.readline
r_int = lambda : int(input())
m_int = lambda : map(int, input().split())
l_int = lambda : list(map(int, input()).split())

def solve():
	(n, k) = m_int()
	if k:
		print(n % k)
	else:
		print(n)

def main():
	n_cases = r_int()
	for _ in range(n_cases):
		solve()
main()


t = int(input())
for ni in range(t):
	(n, k) = map(int, input().split())
	if k != 0:
		print(n % k)
	else:
		print(n)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	if k > n or k == 0:
		print(n)
	else:
		print(n % k)


t = int(input())
for _ in range(t):
	(v, m) = map(int, input().split())
	if m != 0:
		print(v % m)
	else:
		print(v)


for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	if n >= k and k != 0:
		print(n % k)
	else:
		print(n)


for _ in range(int(input())):
	(f, p) = map(int, input().split())
	if p == 0 or f < p:
		print(f)
	else:
		print(f % p)


for tc in range(int(input())):
	(n, k) = map(int, input().split())
	if k != 0:
		n = n % k
	print(n)


for _ in range(int(input())):
	(N, K) = map(int, input().split())
	if K > 0:
		print(N % K)
	else:
		print(N)


T = int(input())
x = range(T)
for i in x:
	(n, k) = map(int, input().split())
	if k == 0:
		print(n)
	else:
		print(n % k)


for i in range(int(input())):
	(X, Y) = map(int, input().split())
	if X >= Y and Y != 0:
		print(X % Y)
	else:
		print(X)


T = int(input())
for tc in range(T):
	(n, k) = map(int, input().split(' '))
	if k == 0:
		print(n)
	else:
		x = n // k
		ans = n - x * k
		print(ans)


a = int(input(''))
for i in range(a):
	(N, K) = [int(x) for x in input('').split()]
	if K == 0 or N < K:
		print(N)
	else:
		print(N % K)


tc = int(input())
for i in range(tc):
	arr = input().split(' ')
	n = int(arr[0])
	k = int(arr[1])
	if k == 0:
		print(n)
	else:
		print(n % k)


for _testcase in range(int(input())):
	(a, b) = map(int, input().split())
	if b == 0:
		print(a)
	else:
		print(a % b)


T = int(input())
for i in range(T):
	(N, K) = map(int, input().split())
	if K == 0 or N < K:
		print(N)
	else:
		print(N % K)


class A:

	def m1(self):
		for i in range(int(input())):
			(n, k) = [int(x) for x in input().split()]
			if n < k or k == 0:
				print(n)
			else:
				print(n % k)
a = A()
a.m1()


lop = int(input())
for i in range(lop):
	list_is = []
	num = input()
	for i in num.split():
		list_is.append(int(i))
	num1 = list_is[0]
	num2 = list_is[1]
	if num2 == 0:
		print(num1)
	else:
		print(num1 % num2)


T = int(input())
for index in range(T):
	(n, k) = map(int, input().split())
	if k == 0:
		print(n)
	else:
		r = n % k
		print(r)


n = int(input())
for i in range(n):
	x = list(map(int, input().split()))
	if x[1] == 0:
		print(x[0])
	else:
		print(x[0] % x[1])


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


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


n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	if b > 0:
		c = a % b
		print(c)
	else:
		print(a)


a = int(input())
for i in range(a):
	b = list(map(int, input().split()))
	if b[1] == 0:
		print(b[0])
	else:
		print(b[0] % b[1])