rounding-of
Source: hackerearth
Difficulty: UNKNOWN_DIFFICULTY

Most of the time when rounding a given number, it is customary to round to some multiple of a power of 10. However, there is no reason why we cannot use another multiple to do our rounding to. For example, you could round to the nearest multiple of 7, or the nearest multiple of 3.
Given an integer N and an integer B, round N to the nearest value which is a multiple of B. If N is exactly halfway between two multiples of B, return the larger value.

Input:- First line contains number of test cases and each test case two interger values N and B.

Ouput:- Print the desired output.

SAMPLE INPUT
3
5 10
4 10
100 3

SAMPLE OUTPUT
10
0
99

Explanation

Testcase 3:-100 is closer to 99 than 102.


'''
# Read input from stdin and provide input before running code

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
q = int(eval(input()))

for i in range(0,q):
	(n,b) = (int(x) for x in input().split())
	k = n % b
	t = 0
	if k >= 1.0 * b / 2:
		t = n - k + b
	else:
		t = n - k
	print('%d' % t)	
		


if __name__=='__main__':
	T = int(input())
	for _ in range(T):
		num,m=list(map(int,input().split()))
		if num%m==0:
			print(num)
		else:
			k = num
			cnt1 = 0
			while True:
				if k%m==0:
					ans1 = k
					break
				cnt1 += 1
				k -= 1
			k = num
			cnt2 = 0
			while True:
				if k%m==0:
					ans2 = k
					break
				cnt2 += 1
				k += 1
			if cnt1<cnt2:
				print(ans1)
			else:
				print(ans2)


t = int(input())
for i in range(t) :
	n,b = list(map(int,input().split()))
	d = n/b
	#print d,
	if(  (d+1)*b - n  <=  n-d*b ) :
		print((d+1)*b)
	else :
		print(d*b)


def print_min(n1,n2,n):
	if n-n1==n2-n:
		print(n2)
	else:
		if n-n1<n2-n:
			print(n1)
		else:
			print(n2)
n=eval(input())
for i in range(n):
	n,b=list(map(int,input().split()))
	if n>b:
		near=n/b
		n1=near*b
		n2=(near+1)*b
		print_min(n1,n2,n)
	else:
		print_min(0,b,n)


import math

t = int(input())
for _ in range(t):
	z = list(map(int , input().split()))
	a = z[0]
	b = z[1]
	if b == a*2 or a == b*2 or b % a == 0 or a % b == 0:
		print(b if b > a else a)
	else:
		if b > a :
			if b-a == 1:
				print(b)
			else:
				print("0")
		elif a > b:
			if a - b == 1:
				print(b)
			else:
				temp = int(math.floor(a/b))
				if a - (b*temp) < (b*(temp+1)) - a:
					print((b*temp))
				else:
					print((b*(temp+1)))
				


noOfTestCases = int(input())

def round(no, roundTo):
	no = int(no)
	roundTo = int(roundTo)
	
	lowerLimit = (no / roundTo) * roundTo
	upperLimit = ((no / roundTo) + 1) * roundTo
	
	if((no - lowerLimit) ==  (upperLimit - no)):
		return upperLimit
	elif((no - lowerLimit) < (upperLimit - no)):
		return lowerLimit
	else:
		return upperLimit
		

for i in range(1, noOfTestCases + 1):
	no , roundTo = input().split(" ")
	print(round(no, roundTo))
	


if __name__=='__main__':
	T = int(input())
	for _ in range(T):
		num,m=list(map(int,input().split()))
		if num%m==0:
			print(num)
		else:
			k = num
			cnt1 = 0
			while True:
				if k%m==0:
					ans1 = k
					break
				cnt1 += 1
				k -= 1
			k = num
			cnt2 = 0
			while True:
				if k%m==0:
					ans2 = k
					break
				cnt2 += 1
				k += 1
			if cnt1<cnt2:
				print(ans1)
			else:
				print(ans2)
				


t = int(eval(input()))

while t:

	a , b = list(map(int,input().split()))

	m , n = a , a
	
	cnt_m , cnt_n = 0 , 0
	
	while m % b != 0:
		m -= 1
		cnt_m += 1

	while n % b != 0:
		n+=1
		cnt_n += 1

	if cnt_m > cnt_n :
		print(n)
	elif cnt_m < cnt_n :
		print(m)
	else :
		print((max(m,n)))

	t -= 1