Given two numbers X and N, find the smallest value of (N*K) which is closest to X. Where K is any positive number greater than zero. If in case there are two numbers closer to N, then return the larger number.
 
Example 1:
Input: X = 9, N = 2
Output: 10
Expalantion: 8 and 10 both are multiple of 2 and 
closest to 9, in this case we return the larger 
number that is 10.
Example 2:
Input: X = 2855, N = 13
Output: 2860
Explanation: 2860 is multiple of 13 and 
closest to 13.
 
Your Task:
You don't need to read or print anything. Your task is to complete the function closestNo() which takes X and N as input parameter and return the number which is multiple of N and closest to X. In case of multiple numbers return the bigger one.
Expected Time Compelxity: O(1)
Expected Space Complexity: O(1)
Constraints:
1 <= X, N <= 1000000

Source: geeksforgeeks | Difficulty: EASY

Starter code: #User function Template for python3



class Solution:

	def closestNo(self, x, n):

		# Code here

Solutions:
class Solution:

	def closestNo(self, x, n):
		rem = x % n
		a = x - rem
		b = a + n
		if x - a < b - x and a != 0:
			return a
		else:
			return b


class Solution:

	def closestNo(self, x, n):
		import math
		k = x / n
		if k - int(k) >= 0.5 or int(k) * n == 0:
			return (int(k) + 1) * n
		elif k - int(k) < 0.5 and k - int(k) > 0:
			return int(k) * n
		else:
			return x


class Solution:

	def closestNo(self, x, n):
		if n > x:
			return n
		x = x + n // 2
		x = x - x % n
		return x


class Solution:

	def closestNo(self, x, n):
		if x <= n:
			return n
		else:
			prev = -1
			current = -1
			for i in range(1, 9999999):
				a = n * i
				if a <= x:
					prev = a
				else:
					current = a
					break
			b = abs(x - prev)
			c = abs(current - x)
			if b < c:
				return prev
			else:
				return current


class Solution:

	def closestNo(self, x, n):
		if x < n:
			return n
		d = x % n
		if n - d <= d:
			d = d - n
		return x - d
if __name__ == '__main__':
	T = int(input())
	for i in range(T):
		(x, n) = input().split()
		x = int(x)
		n = int(n)
		ob = Solution()
		ans = ob.closestNo(x, n)
		print(ans)


class Solution:

	def closestNo(self, x, n):
		if x <= n:
			return n
		else:
			prev = -1
			current = -1
			for i in range(1, 1000000):
				a = n * i
				if a <= x:
					prev = a
				else:
					current = a
					break
			b = abs(x - prev)
			c = abs(current - x)
			if b < c:
				return prev
			else:
				return current
if __name__ == '__main__':
	T = int(input())
	for i in range(T):
		(x, n) = input().split()
		x = int(x)
		n = int(n)
		ob = Solution()
		ans = ob.closestNo(x, n)
		print(ans)


class Solution:

	def closestNo(self, x, n):
		if n > x:
			return n
		a = x // n
		b = a * n
		c = (a + 1) * n
		if abs(x - b) < abs(x - c):
			return b
		return c