round-it-2

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.

Source: hackerearth | Difficulty: UNKNOWN_DIFFICULTY


Solutions:
def round():
	import math
	for _ in range(eval(input())):
		N, B = list(map(int, input().split()))
		x = N%B
		
		if x >= B/2.0:
			print(N + (B-x))
		else:
			print(N-x)

if __name__ == "__main__":
	round()


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

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
t=int(input())
while t>0:
	a,b=[int(x) for x in input().split()]
	a=a*1.0
	print((int(round(a/b))*b))
	t=t-1


for _ in range(int(input())):
	n, b = list(map(int, input().split()))
	low = (n / b) * b
	print(low if n - low < low + b - n  else low + b)
	


def r(n, b):
	m = n%b
	return n-m if m < (b/2 + b%2) else n+b-m
for i in range(eval(input())):
	a,b=list(map(int,input().split()))
	print(r(a, b))


for _ in range(eval(input())):
	N,B=list(map(int,input().split()))
	S=N
	T=N
	c1,c2=0,0
	while S%B!=0:
		S-=1
		c1+=1
	while T%B!=0:
		T+=1
		c2+=1
	if c2<=c1:
		print(T)
	else:
		print(S)



n=int(input())
for j in range(n):
	n,b=list(map(int,input().split()))
	if b==0 or n==0:
		print(0)
	elif b%n==0:
		print(b)
	elif n<b:
		if b-n>n:
			print(0)
		else:
			print(b)
	else:
		i=n/b
		if b*(i+1)-n<=n-b*i:
			print(b*(i+1))
		else:
			print(b*i)
			
			
			
	


t=int(input())
nlist=[]
blist=[]
for i in range(t):
	n,b=list(map(int,input().split()))
	m=n%b
	h=float(b)/2
	if(h==m):
		print((int(n+h)))
	elif(h>m):
		print((int(n-m)))
	else:
		print((n+(b-m)))
	


t=int(input())
while t:
	ans=[]
	a,b=list(map(int, input().split()))
	x=list(range(0,a,b))
	x.append(x[len(x)-1]+b)
	x.reverse()
	ans.append(abs(x[0]-a))
	ans.append(abs(x[1]-a))
	print(x[ans.index(min(ans))])
	t=t-1