Santa has $n$ candies and he wants to gift them to $k$ kids. He wants to divide as many candies as possible between all $k$ kids. Santa can't divide one candy into parts but he is allowed to not use some candies at all.

Suppose the kid who recieves the minimum number of candies has $a$ candies and the kid who recieves the maximum number of candies has $b$ candies. Then Santa will be satisfied, if the both conditions are met at the same time:

  $b - a \le 1$ (it means $b = a$ or $b = a + 1$);  the number of kids who has $a+1$ candies (note that $a+1$ not necessarily equals $b$) does not exceed $\lfloor\frac{k}{2}\rfloor$ (less than or equal to $\lfloor\frac{k}{2}\rfloor$). 

$\lfloor\frac{k}{2}\rfloor$ is $k$ divided by $2$ and rounded down to the nearest integer. For example, if $k=5$ then $\lfloor\frac{k}{2}\rfloor=\lfloor\frac{5}{2}\rfloor=2$.

Your task is to find the maximum number of candies Santa can give to kids so that he will be satisfied.

You have to answer $t$ independent test cases.


-----Input-----

The first line of the input contains one integer $t$ ($1 \le t \le 5 \cdot 10^4$) — the number of test cases.

The next $t$ lines describe test cases. The $i$-th test case contains two integers $n$ and $k$ ($1 \le n, k \le 10^9$) — the number of candies and the number of kids.


-----Output-----

For each test case print the answer on it — the maximum number of candies Santa can give to kids so that he will be satisfied.


-----Example-----
Input
5
5 2
19 4
12 7
6 2
100000 50010

Output
5
18
10
6
75015



-----Note-----

In the first test case, Santa can give $3$ and $2$ candies to kids. There $a=2, b=3,a+1=3$.

In the second test case, Santa can give $5, 5, 4$ and $4$ candies. There $a=4,b=5,a+1=5$. The answer cannot be greater because then the number of kids with $5$ candies will be $3$.

In the third test case, Santa can distribute candies in the following way: $[1, 2, 2, 1, 1, 2, 1]$. There $a=1,b=2,a+1=2$. He cannot distribute two remaining candies in a way to be satisfied.

In the fourth test case, Santa can distribute candies in the following way: $[3, 3]$. There $a=3, b=3, a+1=4$. Santa distributed all $6$ candies.

Source: codeforces | Difficulty: EASY
Tags: Mathematics


Solutions:
for t in range(int(input())):
	(n, k) = map(int, input().split())
	print(min(n, n // k * k + k // 2))


N = int(input())
for _ in range(N):
	(n, k) = map(int, input().split())
	t = n // k
	ans = min(n, t * k + k // 2)
	print(ans)


import sys

def main():
	from math import ceil
	for tc in range(int(input())):
		(n, k) = get_ints()
		p = n // k
		y = p * k
		if y == n:
			print(n)
			continue
		ans = ceil(k / 2) * p + k // 2 * (p + 1)
		print(min(n, ans))
get_array = lambda : list(map(int, sys.stdin.readline().split()))
get_ints = lambda : map(int, sys.stdin.readline().split())
input = lambda : sys.stdin.readline().strip()
main()


import math as m
for _ in range(int(input())):
	(n, k) = [int(i) for i in input().split()]
	if n == k:
		print(n)
	elif n < k:
		if n > k // 2:
			print(k // 2)
		else:
			print(n)
	else:
		k1 = n % k
		n -= k1
		if k1 <= k // 2:
			print(n + k1)
		else:
			k1 = k // 2
			print(n + k1)


t = int(input())
for i in range(t):
	(n, k) = input().split()
	n = int(n)
	k = int(k)
	total = n // k * k
	rest = n - total
	total += rest if rest <= k // 2 else k // 2
	print(total)


n = int(input())
lst = []
for i in range(n):
	lst.append(list(map(int, input().split())))
for i in lst:
	if i[0] % i[1] > i[1] // 2:
		print(i[0] // i[1] * i[1] + i[1] // 2)
	else:
		print(i[0] // i[1] * i[1] + i[0] % i[1])


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	r = n % k
	if r <= k // 2:
		print(n)
	else:
		print(n // k * k + k // 2)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	ans = n // k * k
	val = n % k
	x = k // 2
	if val < x:
		ans += val
	else:
		ans += x
	print(ans)


n = int(input())
for i in range(n):
	(m, k) = map(int, input().split())
	t = m // k
	y = m % k
	r = k // 2
	q = m - t * k
	if q >= r:
		print(t * k + r)
	else:
		print(t * k + q)


n = int(input())
for i in range(n):
	(n, k) = [int(x) for x in input().split()]
	s = n // k
	r = n % k
	if r <= k // 2:
		print(n)
	else:
		print(s * k + k // 2)


from collections import deque
import sys
import math
input = sys.stdin.buffer.readline
q = int(input())
for _ in range(q):
	(n, k) = map(int, input().split())
	k2 = k // 2
	r = n % k
	n2 = n - r
	print(n2 + min(r, k2))


def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().split())

def li():
	return list(mi())
import math
for i in range(ii()):
	(n, k) = mi()
	a = n // k
	b = n / k
	if a != b:
		a += 0.5
	ans = math.floor(k * a)
	print(min(ans, n))


q = int(input())
for x in range(q):
	(n, k) = map(int, input().split())
	if n % k > k // 2:
		print(k * (n // k) + k // 2)
	else:
		print(n)


q = int(input())
for loop in range(q):
	(n, k) = map(int, input().split())
	print(min(n, n // k * k + k // 2))


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	each = n // k
	rem = n - k * each
	if rem <= k // 2:
		print(n)
	else:
		print(k // 2 + k * each)


from math import ceil
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	ans = n - n % k
	ans += min(n % k, k // 2)
	print(ans)


t = int(input())
for i in range(t):
	(k, n) = list(map(int, input().split()))
	ezaf = k % n
	x = n // 2
	if ezaf <= x:
		print(k)
	else:
		print(k - ezaf + x)


for test in range(int(input())):
	(sweet, n) = map(int, input().split())
	if sweet == 1 and n == 1:
		print(1)
	elif sweet >= n:
		count = sweet // n
		sweet -= count * n
		if sweet <= n // 2:
			print(count * n + sweet)
		elif sweet > n // 2:
			print(count * n + n // 2)
	elif sweet <= n // 2:
		print(sweet)
	else:
		print(n // 2)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	print(n - max(0, n % k - k // 2))


import math
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	g = n // k * k
	ans = g + min(n - g, 1 * math.floor(k / 2))
	print(ans)


from fractions import gcd
from heapq import *
import math
from collections import defaultdict, Counter, deque
from bisect import *
import itertools
import fractions
MOD = 10 ** 9 + 7

def main():
	t = int(input())
	for i in range(t):
		(n, k) = map(int, input().split())
		if n % k == 0:
			print(n)
		else:
			print(n // k * k + min(k // 2, n - n // k * k))
main()


n = int(input())
for _ in range(n):
	(n, k) = [int(n) for n in input().split()]
	print(n // k * k + min(k // 2, n % k))


from math import floor
import sys
input = sys.stdin.readline
ans = ''
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	ans += str(min(n, n - n % k + int(floor(k / 2)))) + '\n'
print(ans)


t = int(input())
while t > 0:
	(n, k) = map(int, input().split())
	print(k * (n // k) + min(n % k, k // 2))
	t -= 1


for i in range(int(input())):
	a = list(input().split())
	a = [int(i) for i in a]
	b = a[0] % a[1]
	d = a[1] // 2
	if b > d:
		print(a[0] - (b - d))
	else:
		print(a[0])


t = int(input())
for q in range(t):
	(n, k) = [int(i) for i in input().split()]
	if n % k == 0:
		print(n)
		continue
	print(n // k * k + min(n % k, k // 2))


t = int(input())
for i in range(t):
	(n, k) = map(int, input().strip().split())
	a = n // k
	b = n % k
	if b > k // 2:
		b = k // 2
	print(a * k + b)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	q = a % b
	o = a - q
	y = b // 2
	if q > y:
		print(o + y)
	else:
		print(o + q)


for _ in range(int(input())):
	(X, Y) = map(int, input().split())
	n = X // Y
	if X % Y == 0:
		print(X)
	else:
		r = X % Y
		if r >= Y // 2:
			print(X - (r - Y // 2))
		else:
			print(X)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	count = n // k * k
	z = n % k
	if z > k // 2:
		count += k // 2
	else:
		count += z
	print(count)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n % k == 0:
		s = n // k
		cnt = k * s
		print(cnt)
	else:
		x = k // 2
		s = n // k
		cnt = k * s
		n = n - cnt
		u = min(x, n)
		cnt = cnt + u
		print(cnt)


for i in range(int(input())):
	(n, k) = map(int, input().split())
	d = n / k
	if d <= int(d) + 0.5:
		print(n)
	else:
		d = int(d) + 0.5
		print(int(d * k))


tc = int(input())
for _ in range(tc):
	(n, k) = list(map(int, input().split(' ')))
	mini = n // k
	rem = n % k
	have = k // 2
	print(n - max(0, rem - have))


t = int(input())
for i in range(t):
	(n, k) = [int(x) for x in input().split()]
	a = n // k
	r = n - a * k
	if r >= k // 2:
		r = k // 2
	print(a * k + r)


import math
from collections import defaultdict, Counter, deque
INF = float('inf')

def gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return a

def primeFactor(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i ** 2 <= n:
		if n % i == 0:
			return i
		i += 1
	return n

def main():
	(n, k) = map(int, input().split())
	c = n // k * k
	c += min(n % k, k // 2)
	print(c)
t = int(input())
for _ in range(t):
	main()


t = int(input())
A = [list(map(int, input().split())) for _ in range(t)]
res = []
for a in A:
	n = a[0]
	k = a[1]
	x = n % k
	ans = n // k * k
	if x <= k // 2:
		ans += x
	else:
		ans += k // 2
	res.append(ans)
for r in res:
	print(r)


from math import floor
t = int(input())
for i in range(t):
	(n, k) = [int(f) for f in input().split()]
	count = n // k * k
	remain = n % k
	if remain > floor(k / 2):
		print(count + floor(k / 2))
	else:
		print(count + remain)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n % k > k // 2:
		print(n - n % k + k // 2)
	else:
		print(n)


n = int(input())
for cn in range(1, n + 1):
	(a, b) = map(int, input().split())
	c = int(a / b)
	d = c * b + min(a % b, int(b / 2))
	print(d)


import sys

def minp():
	return sys.stdin.readline().strip()

def mint():
	return int(minp())

def mints():
	return list(map(int, minp().split()))

def solve():
	(n, k) = mints()
	x = n // k
	r = n % k
	if r > k // 2:
		print(n - (r - k // 2))
	else:
		print(n)
for i in range(mint()):
	solve()


t = int(input())
for _ in range(t):
	(h, m) = map(int, input().split())
	a = h // m
	if h % m != 0:
		b = h // m + 1
	else:
		b = a
	s = b * (m // 2) + a * (m - m // 2)
	s = min(s, h)
	print(s)


import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue
from decimal import *

class Scanner:

	@staticmethod
	def int():
		return int(sys.stdin.readline().rstrip())

	@staticmethod
	def string():
		return sys.stdin.readline().rstrip()

	@staticmethod
	def map_int():
		return [int(x) for x in Scanner.string().split()]

	@staticmethod
	def string_list(n):
		return [Scanner.string() for i in range(n)]

	@staticmethod
	def int_list_list(n):
		return [Scanner.map_int() for i in range(n)]

	@staticmethod
	def int_cols_list(n):
		return [Scanner.int() for i in range(n)]

class Math:

	@staticmethod
	def gcd(a, b):
		if b == 0:
			return a
		return Math.gcd(b, a % b)

	@staticmethod
	def lcm(a, b):
		return a * b // Math.gcd(a, b)

	@staticmethod
	def divisor(n):
		res = []
		i = 1
		for i in range(1, int(n ** 0.5) + 1):
			if n % i == 0:
				res.append(i)
				if i != n // i:
					res.append(n // i)
		return res

	@staticmethod
	def round_up(a, b):
		return -(-a // b)

	@staticmethod
	def is_prime(n):
		if n < 2:
			return False
		if n == 2:
			return True
		if n % 2 == 0:
			return False
		d = int(n ** 0.5) + 1
		for i in range(3, d + 1, 2):
			if n % i == 0:
				return False
		return True

def pop_count(x):
	x = x - (x >> 1 & 6148914691236517205)
	x = (x & 3689348814741910323) + (x >> 2 & 3689348814741910323)
	x = x + (x >> 4) & 1085102592571150095
	x = x + (x >> 8)
	x = x + (x >> 16)
	x = x + (x >> 32)
	return x & 127
MOD = int(1000000000.0) + 7
INF = int(1000000000000000.0)

def solve():
	(n, k) = Scanner.map_int()
	a = n // k
	ans = min(n, a * k + k // 2)
	print(ans)

def main():
	T = Scanner.int()
	for _ in range(T):
		solve()
main()


def santa(n, k):
	if n % k == 0:
		return n
	else:
		count = n - n % k
		if n % k > k // 2:
			return count + k // 2
		else:
			return count + n % k
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	print(santa(n, k))


tc = int(input())
for _ in range(tc):
	(a, b) = map(int, input().split())
	num = a // b * b
	remain = a - num
	if b // 2 >= remain:
		num += remain
	else:
		num += b // 2
	print(num)


T = int(input().strip())
for t in range(T):
	(n, k) = map(int, input().split())
	allSame = n // k
	left = n - k * allSame
	if left > k // 2:
		print(k * allSame + k // 2)
	else:
		print(k * allSame + left)


f = lambda n, k: k * (n // k) + min(n % k, k // 2)
for i in range(int(input())):
	(n, k) = map(int, input().split())
	print(f(n, k))


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	a = n // k * k
	remain = n - a
	if remain >= k // 2:
		x = a + k // 2
	else:
		x = a + remain
	print(x)


n = int(input())
for a in range(n):
	values = input().split()
	kids = int(values[1])
	candies = int(values[0])
	each = candies // kids
	if candies % kids <= kids // 2:
		print(candies)
	else:
		print(kids * each + kids // 2)


t = int(input(''))
mat = []
for i in range(t):
	mat.append(list(map(int, input().split())))
for i in range(t):
	n = mat[i][0]
	k = mat[i][1]
	a = int(n / k)
	if n % k == 0:
		print(n)
	else:
		ex = n - k * a
		if ex >= int(k / 2):
			print(k * a + int(k / 2))
		else:
			print(k * a + ex)


t = int(input())

def solve():
	n = list(map(int, input().split()))
	p = n[0] // n[1]
	if n[0] % n[1] >= n[1] // 2:
		print(n[0] - (n[0] % n[1] - n[1] // 2))
	else:
		print(n[0])
for x in range(t):
	solve()


import sys
import collections
from collections import Counter
import itertools
import math
import timeit

def sieve(n):
	if n < 2:
		return list()
	prime = [True for _ in range(n + 1)]
	p = 3
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 2
	r = [2]
	for p in range(3, n + 1, 2):
		if prime[p]:
			r.append(p)
	return r

def divs(n, start=1):
	divisors = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				divisors.append(i)
			else:
				divisors.extend([i, n // i])
	return divisors

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t

def flin(d, x, default=-1):
	left = right = -1
	for i in range(len(d)):
		if d[i] == x:
			if left == -1:
				left = i
			right = i
	if left == -1:
		return (default, default)
	else:
		return (left, right)

def ceil(n, k):
	return n // k + (n % k != 0)

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(map(int, input().split()))

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def prr(a, sep=' '):
	print(sep.join(map(str, a)))

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)
t = ii()
for _ in range(t):
	(n, k) = mi()
	q = n // k
	print(min(n, q * k + k // 2))


for tt in range(int(input())):
	(n, k) = map(int, input().split())
	ans = n // k * k
	n %= k
	ans += min(n, k // 2)
	print(ans)


t = int(input())
for i in range(t):
	case = input()
	n = int(case[:case.find(' ')])
	k = int(case[case.find(' ') + 1:])
	kadech = n - n % k
	if n % k <= k // 2:
		kadech = kadech + n % k
	else:
		kadech = kadech + k // 2
	print(kadech)


from math import floor
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	m = floor(k / 2)
	if n % k <= m:
		print(n)
	else:
		print(n - (n % k - m))


import math
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	(low, high) = (n // k, int(math.ceil(n / k)))
	print(min(n, k * low + k // 2))


t = int(input())
for q in range(0, t):
	(n, m) = map(int, input().split())
	l = n // m
	count1 = l * m
	count2 = 0
	n = n - l * m
	l = m // 2
	if l <= n:
		count2 = l
	else:
		count2 = n
	print(count1 + count2)


t = int(input())
for _ in range(t):
	(n, m) = [int(i) for i in input().split()]
	d = n // m
	f = n - d * m
	print(d * m + min(m // 2, f))


for nt in range(int(input())):
	(n, k) = map(int, input().split())
	c = n // k
	print(c * k + min(k // 2, n - c * k))


import sys

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def input():
	return sys.stdin.readline().strip()
T = int(input())
while T:
	(candies, child) = get_ints()
	ans = candies // child * child + min(candies % child, child // 2)
	print(ans)
	T -= 1


T = int(input())
for n in range(T):
	(n, k) = map(int, input().split())
	print(n - max(0, n % k - k // 2))


t = int(input())
for _ in range(0, t):
	(n, k) = map(int, input().strip().split(' '))
	diff = n / k - n // k
	if diff > 0.5:
		a = n / k - diff + 0.5
		n = k * a
	print(int(n))


t = int(input())
for i in range(t):
	a = list(map(int, input().split()))
	s = a[0]
	a[0] = a[0] // a[1] * a[1]
	a[0] += min(s - a[0], a[1] // 2)
	print(a[0])


for i in range(int(input())):
	ar = list(map(int, input().split(' ')))
	x = ar[0] - ar[0] % ar[1]
	x += min(ar[0] % ar[1], ar[1] // 2)
	print(x)


for i in range(int(input())):
	(n, k) = map(int, input().split())
	x = k // 2
	so_keo_1nguoi = n // k
	conlai = n - so_keo_1nguoi * k
	congthem = x if x <= conlai else conlai
	print(so_keo_1nguoi * k + congthem)


for _ in range(int(input())):
	(m, n) = map(int, input().split())
	if m % n == 0:
		print(m)
	elif m % n >= n // 2:
		print(m - m % n + n // 2)
	else:
		print(m)


t = int(input())
while t:
	t += -1
	(n, k) = map(int, input().split())
	t1 = n // k
	t2 = n % k
	t3 = k // 2
	t4 = t2 - min(t3, t2)
	ans = n - t4
	print(ans)


num = int(input())
while num > 0:
	arr = list(map(int, input().split()))
	n = arr[0]
	k = arr[1]
	stop = int(k / 2)
	val = int(n / k)
	equal = val * k
	n = n - equal
	if n == 0:
		print(equal)
	elif n < stop:
		print(arr[0])
	else:
		print(equal + stop)
	num -= 1


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	r = n % k
	if r != 0:
		h = k // 2
		d = r - h
		if d > 0:
			l = n - d
		else:
			l = n
		print(l)
	else:
		print(n)


x = int(input())
for i in range(x):
	z = 0
	a = input().split()
	n = int(a[0])
	k = int(a[1])
	ost = n % k
	if ost > k // 2:
		z = ost - k // 2
	s = n - z
	print(s)


t = int(input())
for i in range(0, t):
	(n, k) = map(int, input().split())
	d = 0
	d = d + n // k * k
	d = d + min(k // 2, n % k)
	print(d)


import math

def task():
	f = input().split()
	n = int(f[0])
	p = int(f[1])
	if n % p != 0:
		ans = p * math.floor(n / p) + math.floor(p * 0.5)
		if ans > n:
			print(int(n))
		else:
			print(int(ans))
	else:
		print(n)
t = int(input())
while t > 0:
	task()
	t -= 1


for t in range(int(input())):
	(n, k) = map(int, input().split())
	q = n // k
	res = q * k + k // 2
	if res > n:
		res = n
	print(res)


n = int(input())
for i in range(n):
	(n, k) = map(int, input().split(' '))
	d = n % k
	print(n) if d <= k // 2 else print(n - (d - k // 2))


for t in range(int(input())):
	(n, k) = [int(x) for x in input().split()]
	ans = int(n / k) * k
	if n % k > int(k / 2):
		ans += int(k / 2)
	else:
		ans += n % k
	print(ans)


for _ in range(int(input())):
	vals = list(map(int, input().split()))
	n = vals[0]
	k = vals[1]
	x = int(n / k)
	y = int(k / 2)
	eq = x * k
	all = eq + min(y, n - eq)
	print(all)


t = int(input())
for c in range(t):
	(n, k) = map(int, input().split())
	mn = min(n % k, k // 2)
	a = n // k
	b = a
	if n % k:
		b += 1
	print(b * mn + a * (k - mn))


for _ in range(int(input())):
	(candies, kids) = map(int, input().split())
	ans = candies // kids * kids
	candies -= ans
	k2 = kids // 2
	ans += min(candies, k2)
	print(ans)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	s = n % k - k // 2
	if s > 0:
		n -= s
	print(n)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	ans = int(n // k) * k
	left = n % k
	if left >= int(k // 2):
		ans += int(k // 2)
	else:
		ans += left
	print(ans)


cases = int(input())
for case in range(cases):
	arr = [int(num) for num in input().split()]
	tot = arr[0] // arr[1] * arr[1] + arr[1] // 2
	if tot > arr[0]:
		print(arr[0])
	else:
		print(tot)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	c = b // 2
	z = a // b
	l = a - z * b
	ans = z * b
	ans += min(l, c)
	print(ans)


t = int(input())
for _ in range(t):
	ans = 0
	(n, k) = list(map(int, input().split()))
	ans += n // k * k
	ans += min(k // 2, n % k)
	print(ans)


T = int(input())
while T:
	(n, k) = map(int, input().split())
	num = n % k
	if num <= k // 2:
		print(n)
	else:
		print(n - num + k // 2)
	T -= 1


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a % b == 0:
		print(a)
	else:
		print(b * (a // b) + min(a % b, b // 2))


import math
n = int(input())
for _ in range(n):
	(n, k) = map(int, input().split(' '))
	x = math.floor(n / k) * k
	last = n - x
	x += min(last, math.floor(k / 2))
	print(x)


test = int(input())
for i in range(test):
	(n, k) = input().split()
	n = int(n)
	k = int(k)
	candy = n - n % k
	if n % k == 0:
		print(candy)
	elif n % k >= k // 2:
		print(candy + k // 2)
	elif n % k < k // 2:
		print(n)


n = int(input())
for i in range(n):
	(c, k) = tuple(map(lambda x: int(x), input().split()))
	a = c // k
	left = c - k * a
	result = c - (left - min(k // 2, left))
	print(result)


from sys import stdin
import math

def inp():
	return stdin.readline().strip()
t = int(inp())
for _ in range(t):
	(n, k) = [int(x) for x in inp().split()]
	used = n // k * k
	n -= used
	if k // 2 > n:
		used += n
	else:
		used += k // 2
	print(used)


for _ in [0] * int(input()):
	(n, k) = map(int, input().split())
	print(n // k * k + min(k // 2, n % k))


t = int(input())
while t:
	t = t - 1
	(n, k) = map(int, input().split())
	div = n // k
	rem = n % k
	if rem > k // 2:
		rem = k // 2
	print(div * k + rem)


t = int(input())
for i in range(t):
	ch = input()
	L = [int(i) for i in ch.split()]
	x = L[0]
	y = L[1]
	nb = 0
	nb += y * (x // y)
	nb += y // 2
	print(min(nb, x))


x = int(input())
while x:
	y = [int(i) for i in input().split()]
	if y[0] >= y[1]:
		g = y[0] % y[1]
		j = y[0] - g
		if g >= int(y[1] / 2):
			j += int(y[1] / 2)
		else:
			j += g
		print(j)
	else:
		print(min(y[0], int(y[1] / 2)))
	x -= 1


t = int(input())
while t != 0:
	(n, k) = input().split()
	n = int(n)
	k = int(k)
	x = n - n // k * k - k // 2
	if x <= 0:
		print(n)
	else:
		print(n - x)
	t -= 1


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	y = k // 2
	x = k - y
	a = n // (x + y)
	ans1 = x * a + y * a
	tmp = n - ans1
	print(ans1 + min(tmp, y))


n = int(input())
for _ in range(n):
	(a, b) = map(int, input().split())
	s = b * (a // b)
	print(min(a, s + b // 2))


def f(a, b):
	return a // b * b + min(b // 2, a % b)
n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	print(f(a, b))


def solve():
	(n, k) = map(int, input().split())
	rest = n % k
	rest -= min(rest, k // 2)
	print(n - rest)
test = 1
test = int(input())
for i in range(test):
	solve()


import sys
input = lambda : sys.stdin.readline().rstrip('\r\n')
for T in range(int(input())):
	(n, k) = [int(i) for i in input().split()]
	base = k * (n // k) + min(n % k, k // 2)
	print(base)


t = int(input())
for _ in range(t):
	(n, k) = tuple(map(int, input().split()))
	base = n // k * k
	print(base + min(k // 2, n - base))


t = int(input())
for i in range(t):
	(n, k) = list(map(int, input().split()))
	a = n // k
	print(min(n, a * k + k // 2))


import sys
from random import choice, randint
inp = sys.stdin.readline
out = sys.stdout.write
flsh = sys.stdout.flush
sys.setrecursionlimit(10 ** 9)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def MI():
	return map(int, inp().strip().split())

def LI():
	return list(map(int, inp().strip().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines().strip()]

def LI_():
	return [int(x) - 1 for x in inp().strip().split()]

def LF():
	return [float(x) for x in inp().strip().split()]

def LS():
	return inp().strip().split()

def I():
	return int(inp().strip())

def F():
	return float(inp().strip())

def S():
	return inp().strip()

def pf(s):
	return out(s + '\n')

def JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))

def main():
	t = I()
	for _ in range(t):
		(n, k) = MI()
		x = k // 2
		a = n // k
		b = a + 1
		ans = x * b + (k - x) * a
		if ans > n:
			ans = n
		print(ans)
main()


for z in range(int(input())):
	(n, k) = map(int, input().split())
	each = n // k
	rest = n - each * k
	total = 0
	if rest >= k // 2:
		total = each * k + k // 2
	else:
		total = each * k + rest
	print(total)


t = int(input())
ans = []
for i in range(t):
	case = list(map(int, input().split()))
	n = case[0]
	k = case[1]
	left = n % k
	if left <= int(k / 2):
		ans.append(n)
	else:
		ans.append(k * int(n / k) + int(k / 2))
for elem in ans:
	print(int(elem))


def solve(n, k, ans):
	candies = k * (n // k)
	candies += min(n % k, k // 2)
	ans.append(candies)

def main():
	t = int(input())
	ans = []
	for i in range(t):
		(n, k) = map(int, input().split())
		solve(n, k, ans)
	for i in ans:
		print(i)
main()


n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	ans = 0
	c = a // b
	a -= c * b
	ans += c * b
	kids = min(b // 2, a)
	ans += kids
	print(ans)


t = input()
for _ in range(int(t)):
	(n, k) = map(int, input().split())
	if n % k == 0:
		ans = n
	else:
		rem = n % k
		ans = k * (n // k)
		if rem > k // 2:
			rem = k // 2
		ans += rem
	print(ans)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	max = n // k + 1
	max_kids = k // 2
	max_c = max * max_kids
	rem_c = n - max_c
	rem_k = k - max_kids
	a = max - 1
	last = rem_k * a
	final = max_c + last
	if final > n:
		print(n)
	else:
		print(final)


t = int(input())
for i in range(t):
	(a, b) = input().strip().split(' ')
	(a, b) = [int(a), int(b)]
	f = a // b
	f1 = f * b
	a = a - f1
	f1 += min(a, b // 2)
	print(f1)


def ri():
	return int(input())

def rl():
	return list(map(int, input().split()))

def solve():
	(n, k) = rl()
	max_eq = n // k * k
	max_eq += k // 2
	print(min(max_eq, n))
t = ri()
for i in range(t):
	solve()


for i in range(int(input())):
	(n, m) = map(int, input().split())
	if n % m <= m // 2:
		print(n)
	else:
		print(n - (n % m - m // 2))


def main():
	(a, b) = list(map(int, input().split()))
	k = b // 2
	print(min(a - (a % b - k), a))
c = int(input())
for i in range(c):
	main()


q = int(input())
import math
for _ in range(q):
	(n, k) = map(int, input().split())
	d = math.floor(k / 2)
	if n % k > d:
		print(n - n % k + d)
	else:
		print(n)


for i in range(int(input())):
	(n, k) = map(int, input().split())
	if n % k == 0:
		print(n)
	else:
		q = n // k
		res1 = q * k
		if n - res1 > k // 2:
			res2 = k // 2
			print(res1 + res2)
		else:
			print(res1 + (n - res1))


q = int(input())
for i in range(q):
	inp = input().split()
	(candy_in, kids) = (int(inp[0]), int(inp[1]))
	remainder = candy_in - int(candy_in / kids) * kids
	candy_out = candy_in - remainder
	if remainder > 0:
		candy_out += min(remainder, kids // 2)
	print(candy_out)


def main():
	cases = int(input())
	for case in range(cases):
		(n, k) = [int(x) for x in input().split(' ')]
		print(n - max(0, n - n // k * k - k // 2))
main()


t = int(input())
ans = []
for i in range(t):
	candykid = list(map(int, input().split()))
	(candy, kid) = candykid
	half = int(kid // 2)
	if candy % kid > half:
		candy -= candy % kid - half
	ans.append(candy)
for i in ans:
	print(i)


from sys import stdin, stdout
from os import path
if path.exists('input.txt'):
	stdin = open('input.txt', 'r')
for _ in range(int(stdin.readline())):
	(x, y) = map(int, stdin.readline().strip().split())
	rem = x % y
	if rem > y // 2:
		rem -= y // 2
	elif rem <= y // 2:
		rem = 0
	print(x - rem)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().rstrip().split())
	div = n // k
	min_s = div * k
	s = min(n - min_s, k // 2)
	print(min_s + s)


for _ in range(int(input())):
	(t, c) = map(int, input().split())
	ans = t // c * c
	t = max(0, t - ans)
	print(ans + min(t, c // 2))


import math
t = int(input())
for q in range(t):
	nk = input().split()
	n = int(nk[0])
	n2 = n
	k = int(nk[1])
	g = n // k * k
	n = n % k
	maxextra = math.floor(k / 2)
	if n >= maxextra:
		print(g + maxextra)
	elif n < maxextra:
		print(g + n)


for nt in range(int(input())):
	(n, k) = map(int, input().split())
	a = n % k
	if a > k // 2:
		print(n - (a - k // 2))
	else:
		print(n)


from sys import stdin
q = int(stdin.readline().rstrip())
while q > 0:
	(n, k) = map(int, stdin.readline().split())
	ans = n // k * k
	n = n % k
	ans += min(n, k // 2)
	print(ans)
	q -= 1


for i in range(int(input())):
	(n, k) = map(int, input().split())
	z = n - n % k
	z = z + min(n % k, k // 2)
	print(z)


for i in range(int(input())):
	(a, b) = map(int, input().split())
	md = a % b
	k = b // 2
	if md <= k:
		print(a)
	else:
		print(int(a - md + k))


tc = int(input())
for ittt in range(tc):
	kk = input()
	arr = kk.split()
	candy = int(arr[0])
	kid = int(arr[1])
	rem = candy % kid
	if rem == 0:
		print(candy)
		continue
	extrakid = kid // 2
	equal = candy // kid
	given = equal * kid
	left = candy - given
	given += min(left, extrakid)
	print(given)


t = int(input())
for query in range(t):
	nk = input().split()
	n = int(nk[0])
	k = int(nk[1])
	x = n % k
	y = n - x
	if x > int(k / 2):
		x = int(k / 2)
	print(x + y)


from sys import stdin, stdout
for _ in range(int(stdin.readline())):
	(n, k) = list(map(int, stdin.readline().split()))
	each = n // k
	rem = n - each * k
	print(each * k + min(rem, k // 2))


for _ in range(int(input())):
	(c, k) = map(int, input().split())
	d = c // k
	r = min(c % k, k // 2)
	print(d * k + r)


for tin in range(int(input())):
	(a, b) = map(int, input().split())
	x = a // b * b
	y = a - x
	if y < b // 2:
		print(x + y)
	else:
		print(x + b // 2)


import sys
input = sys.stdin.readline
t = int(input())
for test in range(t):
	(n, k) = map(int, input().split())
	if n % k > k // 2:
		n -= n % k - k // 2
	print(n)


q = int(input())
while q:
	(n, k) = list(map(int, input().split(' ')))
	a = n % k
	if n % k == 0:
		print(n)
	elif k >= n:
		if k - n > k // 2:
			print(n)
		else:
			print(k // 2)
	else:
		c = k // 2
		num = n // k
		fin = num * k
		if a <= c:
			fina = n
		else:
			fina = fin + c
		print(fina)
	q = q - 1


for _ in range(int(input())):
	(x, y) = map(int, input().split())
	n = x // y
	if x % y == 0:
		print(x)
	else:
		r = x % y
		if r >= y // 2:
			print(x - (r - y // 2))
		else:
			print(x)


import sys

def main():
	I = int(sys.stdin.readline())
	for _ in range(I):
		(n, k) = (int(x) for x in sys.stdin.readline().split())
		d = k * (n // k)
		if n % k > k // 2:
			d += k // 2
		else:
			d += n % k
		sys.stdout.write(f'{d}\n')
main()


for _ in range(int(input())):
	x = input().split()
	(n, k) = (int(x[0]), int(x[1]))
	ans = n // k * k
	n -= ans
	ans += min(k // 2, n)
	print(ans)


cases = int(input())
for _ in range(cases):
	info = list(map(int, input().split()))
	(full, split) = divmod(info[0], info[1])
	extra = min(info[1] // 2, split)
	print(full * info[1] + extra)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = n // k
	maxi = a * k
	n = n - maxi
	if n <= k // 2:
		maxi += n
	else:
		maxi += k // 2
	print(maxi)


def calc(n, k):
	a = n // k
	rm = n - a * k
	lim = k // 2
	return a * k + (lim if lim <= rm else rm)
t = int(input())
cases = [map(int, input().split()) for _ in range(t)]
for (n, k) in cases:
	print(calc(n, k))


from sys import stdin, stdout
cin = stdin.readline
cout = stdout.write
mp = lambda : list(map(int, cin().split()))

def chars():
	s = cin()
	return list(s[:len(s) - 1])

def pl(a):
	for val in a:
		cout(val)
(t,) = mp()
for _ in range(t):
	(n, k) = mp()
	ans = k * (n // k) + min(n % k, k // 2)
	cout(str(ans) + '\n')


t = int(input())
for i in range(t):
	(n, k) = list(map(int, input().split()))
	if n % k == 0 or (n % k != 0 and k // 2 > n % k):
		print(n)
		continue
	else:
		print(n - n % k + k // 2)


size = int(input())
i = 0
while i < size:
	i += 1
	inp = input().split()
	n = int(inp[0])
	k = int(inp[1])
	maxn = 0
	if k == 1:
		maxn = n
	else:
		if n >= k:
			maxn += n // k * k
			n -= maxn
		if n % k:
			if n <= k // 2:
				maxn += n
			else:
				maxn += k // 2
	print(maxn)


a = int(input())
for i in range(a):
	(n, k) = map(int, input().split())
	sum = n // k * k
	if n % k > k // 2:
		sum += k // 2
	else:
		sum += n % k
	print(sum)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	c = n // k * k
	d = n % k
	h = k // 2
	if d >= h:
		d = h
	print(c + d)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	res = n // k * k
	rem = n - n // k * k
	if rem > 0 and rem >= k // 2:
		res = res + k // 2
	elif rem > 0 and rem < k // 2:
		res = res + rem
	print(res)


t = int(input())
res = ''
for i in range(t):
	(n, k) = [int(x) for x in input().split()]
	if n % k > k // 2:
		res = res + str(n - n % k + k // 2) + '\n'
	else:
		res = res + str(n) + '\n'
print(res)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	if n % k == 0:
		print(n)
	else:
		a = n // k
		res = a * k + k // 2
		if res >= n:
			print(n)
		else:
			print(res)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	if n % k == 0:
		print(n)
	else:
		m = int(k / 2)
		lp = k - m
		avg = int(n / k)
		s1 = avg * lp
		s2 = (avg + 1) * m
		s = s1 + s2
		if s <= n:
			print(s)
		else:
			print(n)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	a = n % k
	ans = n - a
	if ans == n:
		print(ans)
	else:
		b = k // 2
		c = min(a, b)
		print(ans + c)


from sys import stdin, stdout
from collections import Counter
from itertools import permutations
import bisect
import math
I = lambda : map(int, stdin.readline().split())
I1 = lambda : stdin.readline()
for _ in range(int(I1())):
	(n, k) = I()
	x = n // k
	ans = x * k
	ans = min(ans + 1 * (k // 2), n)
	print(ans)


import math
t = int(input())
for _ in range(t):
	(n, k) = [int(i) for i in input().split()]
	k1 = math.floor(k / 2)
	n1 = n % k
	if n1 > k1:
		print(n - n1 + k1)
	else:
		print(n)


from math import floor

def solve(n, k):
	left = n % k
	k2 = k // 2
	if left <= k2:
		print(n)
	else:
		print(n // k * k + k2)
tc = int(input())
for i in range(tc):
	(n, k) = [int(x) for x in input().split()]
	solve(n, k)


def main():
	answer = ''
	for test in range(int(input())):
		(n, k) = list(map(int, input().split(' ')))
		give = n // k * k + min([n - n // k * k, k // 2])
		answer += str(give) + '\n'
	print(answer)
main()


t = int(input())
for _ in range(t):
	l = input().split(' ')
	candies = int(l[0])
	kids = int(l[1])
	if candies < kids:
		if candies <= kids // 2:
			print(candies)
		else:
			print(kids // 2)
		continue
	q = candies // kids
	r = candies % kids
	ans = 0
	if r > 0:
		ans = min(kids // 2, r)
	ans = q * kids + ans
	print(ans)


a = int(input())
for i in range(a):
	(n, k) = map(int, input().split())
	x = k // 2
	minimum = n // k
	if n % k >= x:
		print(k * minimum + x)
	else:
		print(k * minimum + n % k)


for i in range(int(input())):
	(n, k) = map(int, input().split())
	if n % k == 0:
		print(n)
	else:
		s = n // k
		ans = s * k
		ans += min(k // 2, n - s * k)
		print(ans)


import sys
sys.setrecursionlimit(10 ** 5 + 1)
inf = int(10 ** 20)
max_val = inf
min_val = -inf
RW = lambda : sys.stdin.readline().strip()
RI = lambda : int(RW())
RMI = lambda : [int(x) for x in sys.stdin.readline().strip().split()]
RWI = lambda : [x for x in sys.stdin.readline().strip().split()]
for _ in [0] * RI():
	(nb_candles, nb_kids) = RMI()
	(divs, mods) = divmod(nb_candles, nb_kids)
	max_give = divs * nb_kids + min(mods, nb_kids // 2)
	print(max_give)


import sys
import math
import itertools
import functools
import collections

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(map(int, input().split()))

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def wr(arr):
	return ' '.join(map(str, arr))

def revn(n):
	return str(n)[::-1]

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)

def sieve(n):
	if n < 2:
		return list()
	prime = [True for _ in range(n + 1)]
	p = 3
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 2
	r = [2]
	for p in range(3, n + 1, 2):
		if prime[p]:
			r.append(p)
	return r

def divs(n, start=1):
	r = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				r.append(i)
			else:
				r.extend([i, n // i])
	return r

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True

def convn(number, base):
	newnumber = 0
	while number > 0:
		newnumber += number % base
		number //= base
	return newnumber

def cdiv(n, k):
	return n // k + (n % k != 0)
t = ii()
for _ in range(t):
	(n, k) = mi()
	print(min(n, n // k * k + k // 2))


def fun(c, k):
	ans = c // k * k
	ans += min(k // 2, c - ans)
	return ans
t = int(input())
while t:
	(h, m) = map(int, input().split())
	print(fun(h, m))
	t -= 1


t = int(input())
for i in range(0, t, 1):
	(n, k) = map(int, input().split())
	if n % k > k // 2:
		print(n // k * k + k // 2)
	else:
		print(n)


def candy(n, k):
	mini = n - n % k
	return mini + min(n % k, k // 2)

def io():
	T = int(input())
	for i in range(T):
		(n, k) = map(int, input().split())
		print(candy(n, k))
io()


t = int(input())
ans = []
for _ in range(t):
	(n, k) = map(int, input().split())
	if n % k == 0:
		ans.append(n)
	else:
		temp = n // k
		z = n - n // k * k
		if z > k // 2:
			ans.append(temp * k + k // 2)
		else:
			ans.append(n)
for i in ans:
	print(i)


from math import *
t = int(input())
for numbers in range(t):
	(n, k) = map(int, input().split())
	a = ceil(n / k)
	b = floor(n / k)
	z = n % k
	if z > floor(k / 2):
		print(a * floor(k / 2) + b * (k - floor(k / 2)))
	else:
		print(a * z + b * (k - z))


t = int(input())
for i in range(t):
	(n, k) = input().split()
	n = int(n)
	k = int(k)
	can = k // 2
	if n % k == 0:
		print(n)
	elif can > n % k:
		print(n // k * k + n % k)
	else:
		print(n // k * k + can)


def main():
	(n, k) = map(int, input().split())
	ans = n - max(n % k - k // 2, 0)
	print(ans)
	return

def test():
	t = int(input())
	while t:
		main()
		t -= 1
test()


for case in range(int(input())):
	(n, k) = map(int, input().split())
	each = n // k
	restMax = k // 2
	rest = n % k
	print(each * k + min(rest, restMax))


n = int(input())
for i in range(n):
	(a, b) = input().split()
	a = int(a)
	b = int(b)
	c = a // b
	d = c * b + b // 2
	if d >= a:
		d = a
	print(d)


from sys import stdin
from collections import defaultdict
t = int(stdin.readline().strip())
for _ in range(t):
	(n, k) = list(map(int, stdin.readline().split()))
	r = n % k
	if r > k // 2:
		print(n - (r - k // 2))
	else:
		print(n)


for t in range(int(input())):
	(x, y) = map(int, input().split())
	if x % y <= y // 2:
		print(x)
	else:
		print(x // y * y + y // 2)


t = int(input())
res = []
for i in range(t):
	l = list(map(int, input().split(' ')))
	l1 = l[0]
	l2 = l[1]
	rest_div = l1 % l2
	if rest_div >= l2 // 2:
		res.append(l1 // l2 * l2 + l2 // 2)
	else:
		res.append(l1)
for x in res:
	print(x)


t = int(input())
for _ in range(t):
	(c, k) = map(int, input().split())
	a = c // k
	c = c % k
	print(a * k + min(c, k // 2))


t = int(input())
while t:
	(n, k) = input().split()
	n = int(n)
	k = int(k)
	rem = n % k
	num = k // 2
	out = n - rem + min(rem, num)
	print(out)
	t = t - 1


t = int(input())
for _ in range(t):
	(n, k) = list(map(int, input().split()))
	x = n // k
	y = x * k
	n = n - y
	if n >= 1:
		if n <= k // 2:
			print(y + n)
		else:
			print(k // 2 + y)
	else:
		print(y)


from sys import stdin as s
for i in range(int(s.readline())):
	(n, k) = (int(j) for j in s.readline().split())
	c = n - n % k
	c += min(n % k, k // 2)
	print(c)


from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time

def I():
	return int(input())

def MI():
	return map(int, input().split())

def S():
	return input()

def MS():
	return map(str, input().split())

def LI():
	return [int(i) for i in input().split()]

def LI_():
	return [int(i) - 1 for i in input().split()]

def StoI():
	return [ord(i) - 97 for i in input()]

def ItoS(nn):
	return chr(nn + 97)

def input():
	return sys.stdin.readline().rstrip()

def show(*inp, end='\n'):
	if show_flg:
		print(*inp, end=end)
YN = {False: 'No', True: 'Yes'}
MOD = 10 ** 9 + 7
inf = float('inf')
IINF = 10 ** 10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
show_flg = False

def solve(T):
	(n, k) = MI()
	if n >= k:
		c = n // k
		remain = n % k
		if k // 2 >= remain:
			print(k * c + remain)
		else:
			print(k * c + k // 2)
	else:
		remain = n % k
		if k // 2 >= remain:
			print(remain)
		else:
			print(k // 2)

def main():
	T = I()
	for i in range(T):
		solve(T)
main()


from sys import stdin
t = int(stdin.readline().rstrip())
while t > 0:
	(n, k) = map(int, stdin.readline().split())
	ans = 0
	if n > k:
		ans += n // k * k
	mod = n % k
	ans += min(mod, k // 2)
	if n == k:
		ans = n
	print(ans)
	t -= 1


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	d = n % k
	half = k // 2
	d1 = n // k
	sum = k * d1
	if d < half:
		print(sum + d)
	else:
		print(sum + half)


def f(n, k):
	if n % k > k // 2:
		return n - n % k + k // 2
	else:
		return n
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	print(f(n, k))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	totalcandies = n // k * k
	remainingcandies = n % k
	kby2 = k // 2
	if remainingcandies <= kby2:
		print(totalcandies + remainingcandies)
	else:
		print(totalcandies + kby2)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	total = n // k * k
	rem = n - total
	ab = min(k // 2, rem)
	print(total + ab)


import math
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	x = int(n / k)
	if n - k * x <= math.floor(k / 2):
		print(n)
	else:
		x = n % k - math.floor(k / 2)
		print(n - x)


t = int(input())
for i in range(0, t):
	(n, k) = map(int, input().split())
	s = 0
	e = 0
	r = n // k
	h = k // 2
	s = r * k
	e = n - s
	s = s + min(h, e)
	print(int(s))


def minutes():
	for _ in range(t):
		(n, k) = [int(x) for x in input().split()]
		remainder = n % k
		maxRemain = k // 2
		res = n // k
		if remainder == 0:
			yield n
		elif maxRemain >= remainder:
			yield n
		else:
			yield (k * res + maxRemain)
t = int(input())
ans = minutes()
print(*ans, sep='\n')


t = int(input())
n = 0
k = 0
for i in range(t):
	(n, k) = map(int, input().split())
	q = int(n / k) * k
	if n - q > int(k / 2):
		ans = q + int(k / 2)
	else:
		ans = n
	print(ans)


t = int(input())
a = []
for i in range(t):
	(n, k) = map(int, input().split())
	a.append((n, k))
for (n, k) in a:
	if n % k == 0:
		print(n)
		continue
	su = 0
	z = n % k
	su = n - z
	if z > k // 2:
		su += k // 2
	else:
		su += z
	print(su)


import sys
import math

def alele():
	return list(map(int, sys.stdin.readline().strip().split()))

def ilele():
	return map(int, sys.stdin.readline().strip().split())

def input():
	return sys.stdin.readline().strip()
for _ in range(int(input())):
	(n, k) = ilele()
	(a, b) = divmod(n, k)
	if b >= k // 2:
		print(a * k + k // 2)
	else:
		print(n)


n = int(input())
while n > 0:
	(a, b) = map(int, input().split())
	cnt = 0
	if a % b > b // 2:
		cnt = b // 2
	else:
		cnt = a % b
	print(a - a % b + cnt)
	n -= 1


for io in range(int(input())):
	(n, s) = map(int, input().split())
	remain = n % s
	if remain > s // 2:
		print(n - (remain - s // 2))
	else:
		print(n)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split(' '))
	if n % k != 0:
		res = k * (n // k) + min(k // 2, n % k)
	else:
		res = n
	print(res)


N = int(input())
for i in range(N):
	(n, k) = map(int, input().split())
	numCandies = n - n % k
	numCandies += min(n % k, k // 2)
	print(numCandies)


t = int(input())

def solve(n, k):
	if n % k == 0:
		return n
	else:
		answer = 0
		least_candy = n // k
		max_lucky_kids = k // 2
		answer = k * least_candy
		amari = n - answer
		answer += min(max_lucky_kids, amari)
		return answer
for i in range(t):
	(n, k) = map(int, input().split())
	print(solve(n, k))


for i in range(int(input())):
	(a, b) = map(int, input().split())
	n = a % b
	m = int(b / 2)
	if n > m and a % b != 0:
		a = a - n + m
	print(a)


t = int(input())
for i in range(t):
	ent = input().split()
	(doce, kid) = (int(ent[0]), int(ent[1]))
	cont = kid // 2
	total = doce // kid
	mult = total * kid
	doce -= mult
	if doce >= cont:
		mult += cont
	else:
		mult += doce
	print(mult)


n = int(input())
for x in range(n):
	(a, b) = list(map(int, input().split()))
	actual = int(a // b)
	difference = actual * b
	difference = a - difference
	possible = int(b // 2)
	if difference <= possible:
		print(a)
	else:
		print(actual * b + possible)


t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	n = a // b * b
	z = a - n
	r = b // 2
	if r > z:
		r = z
	print(r + n)


def candies(n, k):
	sum = 0
	if n % k <= k // 2:
		sum = n // k * k + n % k
	else:
		sum = n // k * k + k // 2
	return sum
t = int(input())
i = 0
while i < t:
	(n, k) = input().split()
	print(candies(int(n), int(k)))
	i += 1


kl = int(input())
for l in range(kl):
	(n, k) = [int(i) for i in input().split()]
	if n % k > k // 2:
		print(n // k * k + k // 2)
	else:
		print(n)


s = []
T = int(input())
for i in range(T):
	(n, k) = map(int, input().split())
	a = n // k
	Total = a * k
	Total += min(k // 2, n % k)
	s.append(Total)
for i in s:
	print(i)


t = int(input())
for i in range(t):
	(n, k) = [int(x) for x in input().split()]
	r = n // k
	print(min(r * k + k // 2, n))


t = int(input())
oszt = 0
for i in range(t):
	oszt = 0
	(c, gy) = input().split(' ')
	c = int(c)
	gy = int(gy)
	oszt += int(c / gy) * gy
	c -= oszt
	oszt += min(c, int(gy / 2))
	print(str(oszt))


t = int(input())
for i in range(t):
	(n, k) = [int(i) for i in input().split()]
	each = n // k
	rem = n - each * k
	if rem == 0:
		print(n)
	elif rem <= k // 2:
		print(n)
	else:
		print(each * k + k // 2)


T = int(input(''))
for i in range(0, T):
	(n, k) = map(int, input().split())
	q = n // k
	r = n % k
	j = k // 2
	if r >= j:
		print(q * k + j)
	else:
		print(q * k + r)


t = int(input())
for _ in range(t):
	(c, k) = [int(x) for x in input().split()]
	r = c % k
	ans = c - r
	if r != 0:
		ans += min(k // 2, r)
	print(ans)


t = int(input())
for i in range(t):
	(a, b) = [int(s) for s in input().split()]
	rem = a % b
	div = a // b
	maxi = b // 2
	sum = a - rem
	sum += maxi
	print(min(sum, a))


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	x = n % k
	q = k // 2
	if x == 0:
		print(n)
	elif x >= q:
		y = n - x
		y = y + q
		print(y)
	else:
		print(n)


for _ in range(int(input())):
	l = list(map(int, input().split()))
	n = l[0]
	k = l[1]
	if n % k == 0:
		print(n)
		continue
	a = n // k
	b = n // k + 1
	na = k - n % k
	nb = n % k
	if nb > k // 2:
		na = na + nb - k // 2
		nb = k // 2
	print(nb * b + na * a)


t = input()
for i in range(int(t)):
	inp = input().split()
	n = int(inp[0])
	k = int(inp[1])
	full = n - n % k
	full += min(n % k, k / 2)
	print(int(full))


for i in range(0, int(input())):
	(n, k) = list(map(int, input().split()))
	u = n // k * k
	print(u + min(n - u, k // 2))


a = input()
for i in range(int(a)):
	b = input()
	q = b.split(' ')
	n = int(q[0])
	k = int(q[1])
	rem = n % k
	t = 0
	if rem >= int(k / 2):
		t = rem - int(k / 2)
	print(n - t)


import math
for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	if n % k <= math.floor(k / 2):
		ans = n
	else:
		ans = n // k * k + math.floor(k / 2) % (n - n // k * k)
	print(ans)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	if n % k == 0:
		print(n)
	else:
		x = n // k * k
		print(min(n, x + k // 2))


num = int(input())
list1 = []
ans = 0
rest = 0
for i in range(num):
	list1.append(input().split())
	ans = int(list1[i][0]) // int(list1[i][1]) * int(list1[i][1])
	rest = int(list1[i][0]) - ans
	if rest <= int(list1[i][1]) // 2:
		ans += rest
	else:
		ans += int(list1[i][1]) // 2
	print(ans)


import math
I = input
pr = print
for _ in ' ' * int(I()):
	(n, m) = map(int, I().split())
	print(min(n % m, m // 2) + m * (n // m))


a = int(input())
for i in range(a):
	(x, y) = map(int, input().split())
	u = x // y
	o = x % y
	print(u * y + min(o, y // 2))


N = int(input())
for _ in range(N):
	(n, k) = [int(x) for x in input().split()]
	one = n // k
	n -= k * one
	ans = k * one + min(k // 2, n)
	print(ans)


import sys
t = 1
t = int(input())
for i in range(t):
	(n, m) = list(map(int, sys.stdin.readline().strip().split()))
	x = n // m
	n
	print(x * m + min(n - x * m, m // 2))


n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	m = a // b
	ba = a - m * b
	ba = max(ba - b // 2, 0)
	print(a - ba)


t = int(input().strip())
for _ in range(t):
	(n, k) = map(int, input().strip().split())
	remain = n % k
	print(n if remain <= k // 2 else n // k * k + k // 2)


import sys
t = int(sys.stdin.readline())
for _ in range(t):
	(n, k) = map(int, sys.stdin.readline().split())
	if n / k == n // k:
		print(n)
	else:
		arr = n // k * k
		dis = n - arr
		limit = k // 2
		if dis > limit:
			arr += limit
		else:
			arr += dis
		print(arr)


t = int(input())
while t:
	inp = list(map(lambda x: int(x), input().split()))
	(n, k) = (inp[0], inp[1])
	temp = n % k
	if temp <= k // 2:
		print(n)
	else:
		print(n - (temp - k // 2))
	t -= 1


t = int(input())
for i in range(t):
	(n, k) = list(map(int, input().split()))
	m = n // k
	n = n - m * k
	if n > k // 2:
		print(k * m + k // 2)
	else:
		print(n + m * k)


arr = []
test_cases = int(input(''))
for x in range(test_cases):
	a = []
	a = list(map(int, input().split()))
	arr.append(a)
for i in range(test_cases):
	k = arr[i][1]
	n = arr[i][0]
	p = int(n / k)
	q = int(k / 2)
	resultt = p * k + q
	if n - p * k <= q:
		print(n)
	else:
		print(resultt)


t = int(input())
while t:
	(m, n) = map(int, input().split())
	print(m // n * n + min(n // 2, m % n))
	t -= 1


import math
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	s = math.floor(k / 2)
	p = n // k
	q = p * k
	print(q + min(s, n % k))


t = int(input())
for _ in range(t):
	l = list(map(int, input().split()))
	(n, k) = (l[0], l[1])
	if n % k == 0:
		print(n)
	else:
		if k % 2 == 1:
			p = min(n, k // 2 * (n // k + 1) + (k // 2 + 1) * (n // k))
		else:
			p = min(n, k // 2 * (n // k + 1) + k // 2 * (n // k))
		print(p)


for _ in range(int(input())):
	(h, m) = tuple(map(int, input().split()))
	if h % m <= m // 2:
		print(h)
	else:
		print(h // m * m + m // 2)


from sys import stdout

def solution(t):
	out = []
	for i in range(t):
		(p, q) = map(int, input().split())
		s = p - p % q
		r = min(p % q, q // 2)
		out.append(s + r)
	stdout.write('\n'.join(map(str, out)))

def main():
	t = int(input())
	solution(t)
main()


tests = int(input())
for t in range(tests):
	bufferSplited = input().split()
	n = int(bufferSplited[0])
	k = int(bufferSplited[1])
	kPerN = n // k * k
	restOfK = n - kPerN
	if restOfK >= k // 2:
		print(kPerN + k // 2)
	else:
		print(kPerN + restOfK)


for i in range(int(input())):
	a = list(map(int, input().strip().split()))[:2]
	c = int(a[0] / a[1])
	d = int(a[1] / 2)
	e = (c + 1) * d + c * (a[1] - d)
	if e > a[0]:
		e = a[0]
	print(e)


n = int(input())
for _ in range(n):
	(a, b) = map(int, input().split())
	q = a // b
	r = a % b
	print(q * b + min(r, b // 2))


import sys
from sys import stdin, stdout
import bisect
import math
import heapq

def modinv(n, p):
	return pow(n, p - 2, p)

def cin():
	return map(int, sin().split())

def ain():
	return list(map(int, sin().split()))

def sin():
	return input()

def inin():
	return int(input())
import math

def Divisors(n):
	l = []
	for i in range(1, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n // i == i:
				l.append(i)
			else:
				l.append(i)
				l.append(n // i)
	return l

def main():
	t = inin()
	for _ in range(t):
		(x, y) = cin()
		z = x // y
		l = x % y
		if l >= y // 2:
			print(y * z + y // 2)
		else:
			print(x)
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			self.write = lambda s: self.buffer.write(s.encode('ascii'))
			self.read = lambda : self.buffer.read().decode('ascii')
			self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import sys

class ostream:

	def __lshift__(self, a):
		sys.stdout.write(str(a))
		return self
cout = ostream()
endl = '\n'

def readnumbers(zero=0):
	conv = ord if py2 else lambda x: x
	A = []
	numb = zero
	sign = 1
	i = 0
	s = sys.stdin.buffer.read()
	try:
		while True:
			if s[i] >= b'0'[0]:
				numb = 10 * numb + conv(s[i]) - 48
			elif s[i] == b'-'[0]:
				sign = -1
			elif s[i] != b'\r'[0]:
				A.append(sign * numb)
				numb = zero
				sign = 1
			i += 1
	except:
		pass
	if s and s[-1] >= b'0'[0]:
		A.append(sign * numb)
	return A
main()


t = int(input())
while t > 0:
	t = t - 1
	(n, k) = input().split()
	n = int(n)
	N = n
	k = int(k)
	k_floor = int(k / 2)
	if k == 2:
		print(n)
		continue
	x = n - n % k
	x = x + min(n % k, k_floor)
	print(x)


t = int(input())
l2 = []
for i1 in range(t):
	(h, m) = map(int, input().split())
	a = h % m
	if a <= int(m / 2):
		c = h
	else:
		c = int(h / m) * m + int(m / 2)
	l2.append(c)
for i in range(t):
	print(l2[i])


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = n // k
	b = a + 1
	print(min(b * (k // 2) + a * (k - k // 2), n))


def main():
	N = int(input())
	for i in range(N):
		(n, k) = map(int, input().split())
		sum_tmp = n // k * k
		n -= n // k * k
		print(sum_tmp + min(n, k // 2))
main()


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


for t in range(int(input())):
	(n, k) = tuple([int(x) for x in input().split(' ')])
	print(n // k * k + min(n - n // k * k, k // 2))


t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	ans = b * (a // b)
	r = a % b
	if r >= b // 2:
		ans = ans + b // 2
	else:
		ans = ans + r
	print(ans)


for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	count = n // k * k
	x = n % k
	if x <= k // 2:
		count += x
	else:
		count += k // 2
	print(count)


a = int(input())
candy = []
for i in range(a):
	k = input()
	k = k.split()
	candy.append([int(k[0]), int(k[1])])
for i in range(len(candy)):
	num = candy[i][0] - candy[i][0] % candy[i][1] + min(candy[i][0] % candy[i][1], int(candy[i][1] / 2))
	print(num)


test = int(input())
for j in range(test):
	ans = 0
	(n, k) = list(map(int, input().split()))
	temp1 = int(n / k)
	ans += temp1 * k
	if n % k == 0:
		print(ans)
	else:
		temp2 = n % k
		temp3 = int(k / 2)
		if temp2 <= temp3:
			ans += temp2
		elif temp2 > temp3:
			ans += temp3
		print(ans)


t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	if a % b == 0:
		print(a)
	else:
		x = a // b
		if a % b > b // 2:
			r = x * b + b // 2
		else:
			r = x * b + a % b
		print(r)


for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	d = k // 2
	c = k - d
	a = n // k
	print(min(n, a * c + (a + 1) * d))


from math import floor

def q():
	inputs = input().split(' ')
	n = int(inputs[0])
	k = int(inputs[1])
	if n % k <= int(floor(k / 2)):
		print(n)
	else:
		print(n - n % k + floor(k / 2))
t = int(input())
for i in range(t):
	q()


import math
import os
import random
import re
import sys

def function(row):
	equal = row[0] // row[1]
	extra = row[0] - equal * row[1]
	distribute = row[1] // 2
	if distribute >= extra:
		print(row[0])
	else:
		print(row[1] * equal + distribute)
m = int(input())
matrix = []
for _ in range(m):
	row = list(map(int, input().split()))
	function(row)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	mn = n // k
	till = k // 2
	total = 0
	term = 0
	total += (k - till) * mn
	remain = n - total
	while till:
		if remain // (mn + 1) >= till:
			total += till * (mn + 1)
			till = 0
		else:
			add = remain % till
			total += (till - add) * mn
			remain = n - total
			till -= till - add
	print(total)


for i in range(int(input())):
	(n, k) = map(int, input().split())
	var = k // 2
	ans = n - k * (n // k)
	if ans > var:
		print(n - (ans - var))
	else:
		print(n)


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	ans1 = n // m
	if ans1 * m == n:
		print(n)
	elif n - ans1 * m <= m // 2:
		print(n)
	else:
		print(ans1 * m + m // 2)


import sys
input = sys.stdin.readline
tc = int(input())
for _ in range(tc):
	(n, k) = map(int, input().split())
	ans = 0
	if n % k == 0:
		ans = n
	elif n % k <= k // 2:
		ans = n // k * k + n % k
	else:
		ans = n // k * k + k // 2
	print(ans)


test = int(input())
while test > 0:
	test -= 1
	(n, k) = map(int, input().split())
	a = n // k
	c = n / k
	b = 0
	if a == c:
		b = a
	else:
		b = a + 1
	c1 = n - a * k
	if c1 >= k // 2:
		b = b * (k // 2)
		a = a * (k - k // 2)
	else:
		b = b * c1
		a = a * (k - c1)
	print(a + b)


def weirdPedolife(kidsAndCandies):
	(candies, kids) = (kidsAndCandies[0], kidsAndCandies[1])
	iloraz = candies / kids
	if iloraz - int(iloraz) > 0.5:
		return int((int(iloraz) + 0.5) * kids)
	return candies
textCases = int(input())
kidsAndCandies = []
for n in range(textCases):
	kidsAndCandies.append(input().split())
kidsAndCandies = [list(map(int, a)) for a in kidsAndCandies]
for a in kidsAndCandies:
	print(weirdPedolife(a))


n = int(input())
while n:
	n -= 1
	(c, k) = map(int, input().split(' '))
	a = c // k
	print(a * k + min(c - a * k, k // 2))


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	s = n // k
	z = k // 2
	if n - k * s >= z:
		print(k * s + z)
	else:
		print(k * s + n - k * s)


import math
t = int(input())
for _ in range(t):
	(k, d) = (int(i) for i in input().split())
	a = k // d
	print(min(a * d + math.floor(d / 2), k))


nTests = int(input())
candiesKids = [-1, -1]
maxCandiesDist = -1
for test in range(nTests):
	candiesKids = [int(k) for k in input().split()]
	candies = candiesKids[0]
	kids = candiesKids[1]
	maxCandiesDist = candies // kids * kids
	maxCandiesDist += min(candies % kids, kids // 2)
	print(maxCandiesDist)


for i in range(int(input())):
	(a, b) = map(int, input().split())
	d = a
	ctr = a // b
	s = 0
	s += ctr * b
	c = b // 2
	s += c
	if s >= d:
		print(d)
	else:
		print(s)


t = int(input())
while t:
	(n, k) = map(int, input().split())
	ans = n // k * k + k // 2
	if ans > n:
		ans = n
	print(ans)
	t -= 1


T = int(input())
for i in range(T):
	(a, b) = [int(x) for x in input().split()]
	ans = a // b
	c = a % b
	print(min(c, b >> 1) + ans * b)


t = int(input())
ans = []
for kk in range(t):
	(c, k) = [int(i) for i in input().split()]
	t = c // k * k
	c = c % k
	if c < k / 2:
		t += c
	else:
		t += k // 2
	ans.append(t)
for i in ans:
	print(i)


for _ in [0] * int(input()):
	(a, b) = map(int, input().split())
	print(a - max(0, a % b - b // 2))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	m = n // k
	l = k // 2
	print(min(n, m * k + l))


def solve(n, k):
	return k * (n // k) + min(n % k, k // 2)

def main():
	for _ in range(int(input())):
		(n, k) = list(map(int, input().split()))
		print(solve(n, k))
main()


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	k2 = k // 2
	avg = n // k
	ans = k * avg
	n -= ans
	ans += min(k2, n)
	print(ans)


t = int(input())
for o in range(t):
	(n, k) = map(int, input().strip().split())
	a = n // k
	remainder = n % k
	half = k // 2
	print(n - max(remainder - half, 0))


for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	a = n // k
	b = n % k
	m = k // 2
	if m < b:
		print(a * k + m)
	else:
		print(a * k + b)


t = int(input())
for i in range(t):
	(n, k) = [int(n) for n in input().split()]
	a = n // k
	d = n % k
	c = k // 2
	if d > c:
		print(a * k + c)
	else:
		print(a * k + d)


import sys, math
input = sys.stdin.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	c = n // k * k
	mod = n % k
	c += min(k >> 1, mod)
	print(c)


import math
n = int(input())
while n > 0:
	m = [int(x) for x in input().split()]
	k = math.ceil(m[0] / m[1]) * m[1]
	if k == m[0]:
		print(str(k))
	else:
		k = k - math.ceil(m[1] / 2)
		if m[0] > k:
			print(k)
		else:
			print(m[0])
	n -= 1


t = int(input())
L = [0] * t

def MaxNumberOfCandies(k, n):
	if n % k <= k // 2:
		return n
	return n - n % k + k // 2
for i in range(t):
	X = input()
	L[i] = X.split()
	print(MaxNumberOfCandies(int(L[i][1]), int(L[i][0])))


n = int(input())
for i in range(n):
	(m, k) = map(int, input().split())
	if m % k == 0:
		print(m)
	else:
		minimo = min(k // 2, m % k)
		a = m // k
		b = a + 1
		res = a * (k - minimo) + b * minimo
		print(res)


for x in range(int(input())):
	(a, b) = map(int, input().split())
	if a % b == 0:
		print(a)
	elif a % b >= b // 2:
		print(a - a % b + b // 2)
	else:
		print(a)


import math as m
t = int(input())
for ii in range(0, t, 1):
	(n, k) = input().split()
	n = int(n)
	k = int(k)
	d = n - k * m.floor(n / k)
	if n % k == 0:
		print(n)
	elif n % k != 0 and d > m.floor(k / 2):
		l = d - m.floor(k / 2)
		print(n - l)
	else:
		print(n)


for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	a = (n - k // 2) // k
	print(n // k * k + min(k // 2 * (n % k != 0), n % k))


from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def main():
	t = int(input())
	for _ in range(t):
		(n, k) = map(int, input().split())
		print(n // k * k + min(k // 2, n - n // k * k))
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


t = int(input())
for queries in range(t):
	(n, k) = list(map(int, input().split()))
	ans = 0
	ans += n // k * k
	if n - n // k * k > k // 2:
		ans += k // 2
	else:
		ans += n - n // k * k
	print(ans)


def rint():
	return int(input())

def rints():
	return list(map(int, input().split()))
t = rint()
for _ in range(t):
	(n, k) = rints()
	print(min(n, n // k * k + k // 2))


e = int(input())
p = []
for ee in range(e):
	(n, k) = map(int, input().split())
	kk = k // 2
	t = k * (n // k)
	if kk <= n - t:
		t = t + kk
	else:
		t = t + (n - t)
	p.append(t)
for i in range(len(p)):
	print(p[i])


for j in range(int(input())):
	(n, k) = list(map(int, input().split()))
	a = n % k
	b = n // k
	if a == 0:
		print(n)
	elif a >= k // 2:
		print(k * b + k // 2)
	else:
		print(n)


from sys import stdin, stdout
import math
from itertools import permutations, combinations
from collections import defaultdict

def L():
	return list(map(int, stdin.readline().split()))

def In():
	return map(int, stdin.readline().split())

def I():
	return int(stdin.readline())
P = 1000000007

def pin(l, a):
	mi = min(l)
	pos = 0
	while l[pos] != mi:
		pos += 1
	return [mi, pos]

def main():
	try:
		for _ in range(I()):
			(a, b) = In()
			temp = a - a % b
			print(temp + min(a % b, b // 2))
	except:
		pass
main()


for t in range(int(input())):
	(n, k) = map(int, input().split())
	x = k // 2
	res1 = n - n % k
	y = min(x, n % k)
	print(res1 + y)


from sys import stdin, stdout
tt = int(stdin.readline().strip())
for t in range(tt):
	(n, k) = map(int, stdin.readline().strip().split())
	x = n // k
	y = n - x * k
	ans = x * k + min(k // 2, y)
	print(ans)


n = int(input())
l = []
for i in range(n):
	(c, k) = map(int, input().split())
	lft = c % k
	k2 = int(k / 2)
	a = int(c / k)
	if lft > k2:
		lft = k2
	l.append(a * k + lft)
print(*l, sep='\n')


from sys import stdin
input = stdin.readline
from heapq import heapify, heappush, heappop, heappushpop
from collections import defaultdict as dd, deque as dq, Counter as C
from math import factorial as f, ceil, gcd, sqrt, log
from bisect import bisect_left as bl, bisect_right as br
from itertools import combinations as c, permutations as p
from math import factorial as f, ceil, gcd, sqrt, log
mp = lambda : map(int, input().split())
it = lambda : int(input())
ls = lambda : list(input().strip().split())
mt = lambda r: [list(mp()) for _ in range(r)]
lcm = lambda a, b: a * b // gcd(a, b)

def fibo_n(n):
	return ((1 + sqrt(5)) / 2) ** n / sqrt(5)
mod = 1000000007
for _ in range(it()):
	(a, b) = mp()
	al = a // b * b
	al += min(b // 2, a % b)
	print(al)


t = int(input())
while t:
	read = input().split()
	n = int(read[0])
	k = int(read[1])
	use = n // k * k
	rem = n - use
	print(use + min(rem, k // 2))
	t -= 1


for i in range(int(input())):
	(n, k) = [int(x) for x in input().split()]
	d = n % k
	print(n - max(0, d - k // 2))


import math
tc = int(input())
while tc:
	(n, k) = map(int, input().split(' '))
	print(n - max(0, n % k - k // 2))
	tc = tc - 1


def santa(candies, children):
	result = candies // children
	answer = result * children
	if result * children != candies:
		ost = candies - answer
		if ost <= children // 2:
			answer = candies
		else:
			answer += children // 2
	return answer
for _ in range(int(input())):
	(h, m) = [int(i) for i in input().split()]
	print(santa(h, m))


for _ in range(int(input())):
	(h, s) = map(int, input().split())
	t = h // s * s
	r = h % s
	req = s // 2
	t = t + min(r, req)
	print(t)


def clucu(n, k):
	b = n // k
	rem = n % k
	if rem == 0:
		return n
	elif rem > k // 2:
		return b * k + k // 2
	if rem <= k // 2:
		return b * k + rem
num = int(input())
output = []
for i in range(num):
	(a, b) = map(int, input().split())
	output.append(clucu(a, b))
for i in output:
	print(i)


n = int(input())
for i in range(n):
	(x, y) = map(int, input().split())
	f = x - x % y
	f += min(x % y, y / 2)
	print(int(f))


from math import floor
t = int(input())
answer = [0] * t
for x in range(t):
	(n, k) = [int(i) for i in input().split()]
	a = int(n / k)
	init_candy = a * k
	rem_candy = n - init_candy
	stupid_formula = floor(k / 2)
	more_candy = min(rem_candy, stupid_formula)
	answer[x] = init_candy + more_candy
print(*answer, sep='\n')


q = int(input())
for _ in range(q):
	(n, k) = map(int, input().split())
	full = n - n % k
	full += min(n % k, k // 2)
	print(full)


n = int(input())
for _ in range(n):
	(cds, kds) = map(int, input().split(' '))
	cds0 = kds * (cds // kds)
	print(cds0 + min(cds - cds0, kds // 2))


Q = int(input())
for q in range(Q):
	(n, k) = [int(x) for x in input().split()]
	maximum = n // k * k + k // 2
	print(min([maximum, n]))


from math import *
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	m = n // k * k
	if n % k != 0:
		q = n - n // k * k
		s = floor(k / 2)
		m += min(q, s)
	print(m)


import math
t = int(input())
for _ in range(t):
	(h, m) = map(int, input().split())
	ans = 0
	ans += h // m * m
	if h % m > m // 2:
		ans = ans + m // 2
	else:
		ans = ans + h % m
	print(ans)


for i in range(int(input())):
	(n, k) = map(int, input().split())
	x = n % k
	if x == 0 or x <= k // 2:
		print(n)
	else:
		x = x - k // 2
		print(n - x)


T = int(input())
for i in range(T):
	(N, K) = map(int, input().split(' '))
	A = N // K * K
	B = N - A
	print(A + K // 2) if B > K // 2 else print(A + B)


test = int(input())
while test != 0:
	lists = input().split(' ')
	candy = int(lists[0])
	kids = int(lists[1])
	vagfol = int(candy / kids)
	extraCandy = candy - vagfol * kids
	limitation = int(kids / 2)
	satisfaction = vagfol * kids + min(limitation, extraCandy)
	print(satisfaction)
	test -= 1


t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	print(a // b * b + min(a % b, b // 2))


for i in range(int(input())):
	(n, k) = map(int, input().split())
	s = n // k * k
	v = s + k // 2
	print(min(v, n))


t = int(input())
for _ in range(t):
	v = list(map(int, input().split()))
	a = v[0] // v[1]
	b = v[0] % v[1]
	if b > v[1] // 2:
		b = v[1] // 2
	print(a * v[1] + b)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = n // k
	r = min(n, (a + 1) * (k // 2) + a * (k - k // 2))
	print(r)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	num = 0
	temp = n % k
	num += n - temp
	if temp <= k // 2:
		num += temp
	else:
		num += k // 2
	print(num)


import math
casos = input()
for i in range(int(casos)):
	(n, k) = [int(x) for x in input().split(' ')]
	maxi = math.ceil(n / k)
	mini = math.floor(n / k)
	dulces = math.ceil(k / 2) * mini + math.floor(k / 2) * maxi
	print(min(dulces, n))


t = int(input())
for tc in range(t):
	line = input().split()
	(n, k) = (int(line[0]), int(line[1]))
	half = k // 2
	x = n % k
	if x <= half:
		print(n)
	elif x > half:
		print(n - x + half)


import sys

def main():
	(n, k) = [int(i) for i in sys.stdin.readline()[:-1].split()]
	answer = n // k * k
	answer += n % k if n % k < k // 2 else k // 2
	sys.stdout.write(f'{answer}\n')
T = int(sys.stdin.readline())
for t in range(T):
	main()


import math
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n % k == 0:
		print(n)
		continue
	r = n % k
	ans = n // k * k
	if math.floor(k / 2) <= r:
		ans += math.floor(k / 2)
	elif math.floor(k / 2) > r:
		ans += r
	print(ans)


from collections import defaultdict, Counter
import heapq
import math
import sys
import os
di = {}
arr = []
dd = defaultdict(list)

def solve():
	(N, K) = [int(i) for i in input().split(' ')]
	print(N - max(0, N % K - K // 2))
T = int(input())
for i in range(T):
	solve()


for t in range(int(input())):
	nk = list(map(int, input().split()))
	print(nk[0] // nk[1] * nk[1] + min(nk[1] // 2, nk[0] % nk[1]))


import math
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	kolvo = n - n % k
	kolvo += min(n % k, math.floor(k / 2))
	print(kolvo)


from operator import itemgetter
t = int(input())
while t > 0:
	t = t - 1
	(n, k) = input().strip().split()
	n = int(n)
	k = int(k)
	x = n % k
	y = n - x
	if x < k // 2:
		print(y + x)
	else:
		print(y + k // 2)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	ans = m * (n // m)
	n -= ans
	ans += min(m // 2, n)
	print(ans)


from collections import defaultdict as dd
import sys
input = sys.stdin.readline
t = int(input())
while t:
	(n, m) = map(int, input().split())
	ans = n // m * m
	rem = n % m
	if rem <= m // 2:
		ans += rem
	else:
		ans += m // 2
	print(ans)
	t -= 1


cases = int(input())
for _ in range(cases):
	(n, k) = map(int, input().split())
	ans = n // k * k
	ans += min(n - ans, k // 2)
	print(ans)


t = int(input())
for i in range(t):
	(n, k) = input().split()
	n = int(n)
	k = int(k)
	c = n - n // k * k
	if c == 0:
		print(n)
	else:
		c -= k // 2
		if c <= 0:
			print(n)
		else:
			print(n - c)


t = int(input())
for i in range(t):
	s = list(map(int, input().split()))
	n = s[0]
	k = s[1]
	x = k // 2
	y = n // k
	print(min(y * k + x, n))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	q = n // k
	r = n % k if n % k < k // 2 else k // 2
	can = q * k + r
	print(can)


for t in range(int(input())):
	(h, m) = map(int, input().split())
	div = h // m
	rem = h % m
	print(div * m + min(rem, m // 2))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	d = n // k
	r = n % k
	ch = k // 2
	res = d * k
	if r > 0:
		res += min(r, ch)
	print(res)


cc = int(input())
for i in range(0, cc):
	(n, k) = map(int, input().split(' '))
	answ = n // k * k
	answ = n // k * k
	n = n - answ
	s = k // 2
	if n <= s:
		answ += n
	else:
		answ += s
	print(answ)


import math
t = int(input())
for i in range(0, t):
	(a, b) = input().split()
	(n, k) = (int(a), int(b))
	kk = math.floor(k / 2)
	exx = n % k
	mm = n - exx
	ans = 0
	if exx <= kk:
		ans = mm + exx
	else:
		ans = mm + kk
	print(ans)


t = int(input())
a = list()
for i in range(t):
	s = input().split()
	(n, k) = (int(s[0]), int(s[1]))
	if n % k > k // 2:
		print(n // k * k + k // 2)
	else:
		print(n)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	m = k // 2
	res = k * (n // k)
	n -= res
	res += min(n, m)
	print(res)


t = int(input())
liste = [0] * t
for i in range(t):
	inp = input()
	liste[i] = inp.split()
for i in range(t):
	n = int(liste[i][0])
	k = int(liste[i][1])
	if n % k <= k // 2:
		nd = n
	else:
		nd = n - n % k + k // 2
	print(nd)


t = int(input())
for i in range(t):
	(n, k) = [int(n) for n in input().split()]
	ans = n
	n %= k
	print(ans // k * k + min(n, k // 2))


def main():
	t = int(input())
	for _ in range(t):
		(n, k) = map(int, input().split())
		b = k // 2
		if n % k > b:
			print(n // k * k + b)
		else:
			print(n // k * k + n % k)
main()


for _ in range(int(input())):
	(n, k) = map(int, input().rstrip().split())
	if n % k == 0:
		print(n)
	elif n % k > k // 2:
		print(n - n % k + k // 2)
	else:
		print(n)


def solve():
	(n, m) = map(int, input().split())
	mod = n % m
	mx = m // 2
	if mod > mx:
		print(n - mod + mx)
	else:
		print(n)
t = int(input())
for _ in range(t):
	solve()


t = int(input())
while t > 0:
	(c, k) = list(map(int, input().split()))
	(d, rem) = divmod(c, k)
	if rem > k // 2:
		print(d * k + k // 2)
	else:
		print(d * k + rem)
	t -= 1


import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
write = sys.stdout.write

def ii():
	return int(readline())

def mi():
	return map(int, readline().rstrip().split())

def li():
	return list(readline().rstrip())

def lmi():
	return list(map(int, readline().rstrip().split()))

def end(*arg):
	print(*arg)
	sys.exit()

def main():
	t = ii()
	for _ in range(t):
		(n, k) = mi()
		a = n // k
		if n - a * k <= k // 2:
			print(n)
		else:
			print(a * k + k // 2)
	return
main()


t = int(input())
i = 0
a = [0] * t
for i in range(t):
	p = 0
	(n, k) = list(map(int, input().split()))
	q = n // k
	o = n % k
	if o > k // 2:
		p = k // 2
	else:
		p = o
	a[i] = k * q + p
i = 0
for i in range(t):
	print(a[i])


try:
	for _ in range(int(input())):
		(ncand, nkid) = map(int, input().split())
		res = ncand // nkid * nkid
		ncand -= res
		res += min(ncand, nkid // 2)
		print(res)
except Exception as e:
	print(e)


from sys import stdin
input = stdin.readline
t = int(input())
while t:
	t -= 1
	(n, k) = map(int, input().split())
	a = n // k
	n -= k * a
	res = k * a + min(n, k // 2)
	print(res)


for p in range(int(input())):
	(k, n) = map(int, input().split())
	temp = k // n
	print(temp * n + int(n / 2) if k % n > int(n / 2) else k)


k = int(input())
for i in range(k):
	(a, b) = input().split()
	a = int(a)
	b = int(b)
	mod = a % b
	k = b // 2
	if mod == 0:
		print(a)
	elif mod > k:
		mod -= k
		print(a - mod)
	elif mod <= k:
		print(a)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	ans = 0
	ans += n // k * k
	mod = n % k
	if mod != 0:
		if mod > k // 2:
			mod = k // 2
	ans += mod
	print(ans)


from sys import stdin
inp = stdin.readline
t = int(inp())
for i in range(t):
	(n, k) = [int(x) for x in inp().split()]
	print(n // k * k + min(k // 2, n - n // k * k))


for _ in range(int(input())):
	(x, y) = map(int, input().split())
	if x % y == 0:
		print(x)
	elif x > y:
		t = x - x % y
		print(t + x % y if x % y <= y // 2 else t + y // 2)
	else:
		print(x if x <= y // 2 else y // 2)


def pklk(n, k):
	s1 = n // k
	o = n % k
	if k // 2 <= o:
		o = k // 2
	print(o + s1 * k)
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	pklk(n, k)


def main():

	def solve():
		(n, k) = map(int, input().split())
		a = n // k
		kb = n % k
		if kb <= k // 2:
			print(n)
		else:
			print(a * k + k // 2)
	q = int(input())
	for _ in range(q):
		solve()
main()


import sys
reader = (line.rstrip() for line in sys.stdin)
input = reader.__next__
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	res = n % k
	if res > k >> 1:
		print(n - res + (k >> 1))
	else:
		print(n)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	cnt = n - n % k
	x = min(n % k, int(k / 2))
	cnt += x
	print(cnt)


import math
mat = []
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	num1 = n % k
	num2 = n - num1
	num3 = n - num2
	if num3 <= math.floor(k / 2):
		result = num2 + num3
	else:
		result = num2 + k / 2
	mat.append(int(result))
for this in range(len(mat)):
	print(mat[this])


T = int(input())
out = []
for i in range(0, T):
	(n, k) = map(int, input().split())
	extra = n % k
	temp = n + k / 2 - extra
	if temp >= n:
		output = n
	else:
		output = int(temp)
	out.append(output)
for i in range(0, T):
	print(out[i])


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split(' '))
	q = n // k
	rem = n % k
	if rem < k // 2:
		print(q * k + rem)
	else:
		print(q * k + k // 2)


from math import ceil
cases = int(input())
for _ in range(cases):
	(n, k) = map(int, input().split())
	r = k * (n // k)
	rem = n - r
	r += min(n % k, k // 2)
	print(r)


import os, sys, math
import collections
if os.path.exists('testing'):
	name = os.path.basename(__file__)
	if name.endswith('.py'):
		name = name[:-3]
	src = open(name + '.txt', encoding='utf8')
	input = src.readline

def solve():
	a = n // k
	m = n - a * k
	m = min(m, k // 2)
	return a * k + m

def integers():
	return map(int, input().strip().split())

def array_of_integers(q):
	return [tuple(map(int, input().strip().split())) for _ in range(q)]
(t,) = integers()
for _ in range(t):
	(n, k) = integers()
	res = solve()
	print(res)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	r = n % k
	d = int(k / 2)
	ans = 0
	if r > d:
		ans = d
	else:
		ans = r
	print(k * int(n / k) + ans)
1


from sys import *
t = int(stdin.readline())
for _ in range(t):
	(n, m) = map(int, stdin.readline().split())
	y = n % m
	y = max(0, y - m // 2)
	print(n - y)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	if n < k:
		print(min(n, int(k / 2)))
	elif n == k:
		print(n)
	else:
		print(int(n / k) * k + min(n % k, int(k / 2)))


from math import floor
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	tot = n - n % k
	tot += min(n % k, floor(k / 2))
	print(tot)


a = int(input())
temp = []
for j in range(a):
	(n, k) = map(int, input().split())
	d = n // k
	nn = n - d * k
	if nn <= k // 2:
		temp.append(n)
	elif nn <= k:
		temp.append(d * k + k // 2)
print('\n'.join(map(str, temp)))


import math
q = int(input())
for _ in range(q):
	s = input().split()
	n = int(s[0])
	k = int(s[1])
	a = n // k
	sex = a * k + k // 2
	fuck = a * k
	if n > sex:
		print(sex)
	else:
		print(n)


import sys
n = int(input())
ans = []
for _ in range(n):
	x = sys.stdin.readline()
	y = list(map(int, x.split()))
	n = y[0]
	k = y[1]
	ans.append(int(n / k) * k + min(n % k, int(k / 2)))
for i in ans:
	print(i)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	p = a // b
	a = a - p * b
	x = p * b
	b = b // 2
	if b > a:
		x += a
	else:
		x += b
	print(x)


import sys
import math
input = sys.stdin.readline
t = int(input().strip())
while t > 0:
	(n, k) = map(int, input().split())
	ans = 0
	ans += math.floor(n / k) * k
	if n % k >= math.floor(k / 2):
		ans += math.floor(k / 2)
	else:
		ans += n % k
	print(ans)
	t -= 1


def solve(n, k):
	res = int(n / k) * k
	res += min(n - res, int(k / 2))
	print(res)
n = int(input())
for i in range(n):
	(n, k) = map(int, input().split())
	solve(n, k)


n = int(input())
for i in range(n):
	(n, k) = map(int, input().split())
	q = int(n / k)
	res1 = q * k
	rem = n % k
	if rem == 0:
		result = res1
	elif rem >= int(k / 2):
		result = res1 + int(k / 2)
	else:
		result = res1 + rem
	print(result)


for _ in range(int(input())):
	(n, k) = input().split(' ')
	(n, k) = (int(n), int(k))
	x = int(k / 2)
	a = int(n / k)
	r = n % k
	if r >= x:
		print(n - r + x)
	else:
		print(n)


import math
t = int(input())
ans_arr = []
for x in range(t):
	[n, k] = [int(i) for i in input().split()]
	ans = n // k * k + min(n % k, k // 2)
	ans_arr.append(str(ans))
print('\n'.join(ans_arr))


def asd(n, k):
	s = n
	n %= k
	if n >= k // 2:
		n -= k // 2
	else:
		n = 0
	return s - n
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	print(asd(n, k))


def main():
	for _ in range(int(input())):
		(n, k) = list(map(int, input().split()))
		a = n // k
		x = n - a * k
		x = x if x <= k // 2 else k // 2
		one = a * k + x
		two = a * k
		print(max(one, two))
main()


import math
for i in range(int(input())):
	(n, k) = map(int, input().split(' '))
	x = n // k * k + min(math.floor(k // 2), n % k)
	print(x)


import math
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	ans = 0
	if n % k == 0:
		print(n)
	else:
		a = math.floor(k / 2)
		b = k - a
		while True:
			if n < a:
				ans += n
				break
			ans += a
			n -= a
			if n < b:
				break
			else:
				ans += b
				n -= b
		print(ans)


testcase = int(input())
for i in range(testcase):
	(a, b) = list(map(int, input().split()))
	prothome_dimu = a // b * b
	baki = a - prothome_dimu
	half = b // 2
	if baki >= half:
		total = prothome_dimu + half
		print(total)
	else:
		print(prothome_dimu + baki)


count = int(input())
for item in range(count):
	readline = input().split()
	n = int(readline[0])
	k = int(readline[1])
	if n % k == 0:
		result = n
	elif n % k > k // 2:
		result = n // k * k + k // 2
	else:
		result = n
	print(result)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if k <= n:
		if n % k == 0:
			ans = n
		else:
			r = n % k
			q = n // k
			if r <= k // 2:
				ans = q * k + r
			else:
				ans = q * k + k // 2
	elif n <= k // 2:
		ans = n
	else:
		ans = k // 2
	print(ans)


import math
t = int(input())
for i in range(t):
	(n, k) = [int(i) for i in input().split(' ')]
	count = math.ceil(n / k) * (k // 2) + min(n - math.ceil(n / k) * (k // 2), (k - k // 2) * math.floor(n / k))
	print(count)


n = int(input())
k = []
d = []
r = []
m = []
dk = []
h = 0
z = []
for i in range(n):
	a = list(map(int, input().split()))
	k.append(a[0])
	d.append(a[1])
	r.append(a[0] // a[1])
	h += r[i] * a[1]
	m.append(a[0] - a[0] // a[1] * a[1])
	if a[1] // 2 == m[i]:
		h += m[i]
	elif a[1] // 2 < m[i]:
		h += a[1] // 2
	elif a[1] // 2 > m[i]:
		h += m[i]
	z.append(h)
	h = 0
for i in range(n):
	print(z[i])


def main():
	t = int(input())
	for i in range(t):
		d = input().split(' ')
		(n, k) = (int(d[0]), int(d[1]))
		diff = 0
		c = 0
		if n % k == 0:
			print(k * (n // k))
		else:
			c = k * (n // k)
			n = n % k
			i = 0
			l = k // 2
			if n >= l:
				c += l
			elif n < l:
				c += n
			print(c)
main()


for _ in range(int(input())):
	(h, m) = map(int, input().split())
	a = int(h / m)
	b = h - a * m
	if h % m == 0:
		print(h)
	elif b <= int(m / 2):
		print(h)
	else:
		print(a * m + int(m / 2))


t = int(input())
for hbfv in range(t):
	(a, b) = [int(i) for i in input().split(' ')]
	p = a % b
	if p != 0 and p > int(b / 2):
		print(a - p + int(b / 2))
	elif p != 0 and p <= int(b / 2):
		print(a)
	else:
		print(a)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	c = k // 2
	a = n // k
	b = n - a * k
	d = b - c
	if b <= c:
		print(a * k + b)
	else:
		print(a * k + c)


import sys
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	ans = n // k * k
	res = n - n // k * k
	if res > 0:
		res = min(res, k // 2)
	print(ans + res)


import sys
LI = lambda : list(map(int, sys.stdin.readline().strip('\n').split()))
MI = lambda : map(int, sys.stdin.readline().strip('\n').split())
SI = lambda : sys.stdin.readline().strip('\n')
II = lambda : int(sys.stdin.readline().strip('\n'))
for _ in range(II()):
	(n, k) = MI()
	r = n % k
	if r == 0:
		print(n)
	else:
		print(n // k * k + min(r, k // 2))


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	cpp = n // k
	ex = n - k * cpp
	if ex > k // 2:
		b = k // 2
		a = k - k // 2
	else:
		b = ex
		a = k - ex
	candiesd = a * cpp + b * (cpp + 1)
	print(candiesd)


for x in range(int(input())):
	(n, k) = map(int, input().split())
	a = n // k
	b = k // 2
	print(a * k + min(n - a * k, b))


import math
test = int(input())
for tes in range(test):
	(n, k) = list(map(int, input().split()))
	all = n // k
	n = n - k * all
	left = min(n, k // 2)
	print(k * all + left)


t = int(input())
for _ in range(t):
	(h, m) = [int(i) for i in input().split()]
	a = int(h / m)
	print(min(h, a * m + int(m / 2)))


t = int(input())
for i in range(t):
	s = str(input()).split()
	n = int(s[0])
	k = int(s[1])
	m = n // k
	z = n - m * k
	if z > k / 2:
		print(m * k + k // 2)
	else:
		print(n)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	if n % k == 0:
		print(n)
		continue
	else:
		sum = int(n / k) * k
		r = n % k
		if r < int(k / 2):
			sum = sum + r
		else:
			sum = sum + int(k / 2)
		print(sum)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	equal = n // k
	rem = n - equal * k
	student = k // 2
	temp = student if rem >= student else rem
	print(equal * k + temp)


import sys

def fastio():
	from io import StringIO
	from atexit import register
	global input
	sys.stdin = StringIO(sys.stdin.read())
	input = lambda : sys.stdin.readline().rstrip('\r\n')
	sys.stdout = StringIO()
	register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()

def debug(*var, sep=' ', end='\n'):
	print(*var, file=sys.stderr, end=end, sep=sep)
INF = 10 ** 20
MOD = 10 ** 9 + 7
I = lambda : list(map(int, input().split()))
from math import gcd
from math import ceil
from collections import defaultdict as dd, Counter
from bisect import bisect_left as bl, bisect_right as br
(t,) = I()
while t:
	t -= 1
	(n, k) = I()
	ok = n // k * k
	n -= ok
	if n <= k // 2:
		print(ok + n)
	else:
		print(ok + k // 2)


for i in range(int(input())):
	(n, k) = map(int, input().split())
	if n % k == 0:
		print(n)
	else:
		res = n // k
		xtra = n % k
		if xtra > k // 2:
			print(res * k + k // 2)
		else:
			print(res * k + xtra)


def solve_test():
	n = int(input())
	for i in range(n):
		(m, k) = map(int, input().split())
		p = m - m % k
		p += min(m % k, k // 2)
		print(p)

def main():
	solve_test()
main()


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	t = 0
	t = n // k * k
	l = n - t
	b = k // 2
	if l < b:
		t = t + l
	else:
		t = t + b
	print(t)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	m = k // 2
	v = min(n % k, m)
	g = n // k
	print(g * k + v)


T = int(input())
for i in range(T):
	(n, k) = map(int, input().split())
	b = n // k * k
	if n % k:
		b = b + k // 2
	if b >= n:
		print(n)
	else:
		print(b)


import math
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = math.floor(n / k)
	b = math.ceil(n / k)
	n_b = min(n % k, k // 2)
	n_a = k - n_b
	print(a * n_a + b * n_b)


import json
t = int(input())
for i in range(t):
	lst = input().split()
	lst = list(map(lambda x: int(x) if x.isdigit() else 0, lst))
	a = lst[0]
	b = lst[1]
	k = a % b
	print(a - k + min(int(b / 2), k))


def solve():
	(n, k) = map(int, input().split())
	b = n // k
	n -= b * k
	x = min(k // 2, n)
	return b * k + x

def main():
	t = int(input())
	for _ in range(t):
		print(solve())
main()


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	nb = k // 2
	a = n // k
	if nb <= n - a * k:
		b = a + 1
	else:
		b = a
	number = nb * (a + 1) + a * (k - nb)
	if number <= n:
		print(number)
	else:
		print(n)


x = int(input())
for i in range(0, x):
	(n, m) = [int(a) for a in input().split()]
	if n % m == 0:
		print(n)
	else:
		f = n // m * m
		g = n % m
		if g <= m // 2:
			print(f + g)
		else:
			print(f + m // 2)


from math import *
import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	print(n - max(0, n % k - k // 2))


from math import ceil
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	s = k // 2
	p = s * ceil(n / k) + (k - s) * (n // k)
	if p > n:
		p = n
	print(p)


for i in range(int(input())):
	(a, b) = [int(x) for x in input().split()]
	metade = b // 2
	res = a % b
	ans = a
	if res > metade:
		ans -= res - metade
	print(ans)


n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	answer = a // b * b
	a -= answer
	answer += min(a, b // 2)
	print(answer)


t = int(input(''))
for v in range(t):
	a = input('').split(' ')
	n = int(a[0])
	k = int(a[1])
	q = n // k
	r = n % k
	if r <= k // 2:
		ans = q * k + r
	else:
		ans = q * k + k // 2
	print(ans)


x = int(input())
for i in range(x):
	(n, k) = [int(x) for x in input().split(' ')]
	m = int(n / k)
	if n % k <= int(k / 2):
		z = n % k
	else:
		z = int(k / 2)
	print(z + m * k)


from sys import stdin
for _ in range(int(stdin.readline())):
	(n, k) = map(int, stdin.readline().split())
	if n % k <= k // 2:
		print(n)
	else:
		m = n // k
		print(k // 2 * (m + 1) + m * (k - k // 2))


import sys
Input = sys.stdin.readline
for i in range(int(Input())):
	(a, b) = map(int, Input().split())
	x = a // b
	tmp = min(b // 2, a % b)
	print(b * x + tmp)


import sys, math, bisect
from heapq import *
inf = float('inf')
mod = 10 ** 9 + 7

def lcm(a, b):
	return int(a / math.gcd(a, b) * b)

def gcd(a, b):
	return int(math.gcd(a, b))

def tobinary(n):
	return bin(n)[2:]

def binarySearch(a, x):
	i = bisect.bisect_left(a, x)
	if i != len(a) and a[i] == x:
		return i
	else:
		return -1

def lowerBound(a, x):
	i = bisect.bisect_left(a, x)
	if i:
		return i - 1
	else:
		return -1

def upperBound(a, x):
	i = bisect.bisect_right(a, x)
	if i != len(a) + 1 and a[i - 1] == x:
		return i - 1
	else:
		return -1

def SieveOfEratosthenes(n):
	ans = []
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	for p in range(2, n + 1):
		if prime[p]:
			ans.append(p)
	return ans
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	print(min(k * (n // k) + k // 2, n))


n = int(input())
for i in range(n):
	info = input().split(' ')
	n_candies = int(info[0])
	n_kids = int(info[1])
	if n_candies % n_kids <= n_kids // 2:
		print(n_candies)
	else:
		print(n_candies - n_candies % n_kids + n_kids // 2)


test = int(input())
for t in range(test):
	(n, k) = [int(x) for x in input().split(' ')]
	x = n % k
	if x == 0 or x <= k // 2:
		print(n)
		continue
	elif x > k // 2:
		print(n - x + k // 2)


T = int(input())
for t in range(T):
	(n, k) = map(int, input().split())
	remain = n % k
	giveFur = min(k // 2, remain)
	remain = remain - giveFur
	print(n - remain)


import math
for _ in range(int(input())):
	ans = 0
	(n, k) = map(int, input().split())
	i = n // k
	r = n % k
	r = min(r, k // 2)
	ans += i * k
	if n % k == 0:
		print(n)
	else:
		ans += r
		print(ans)


import math
import collections
import functools
import sys
input = sys.stdin.read
readInts = lambda : list(map(int, input().split()))

def readChar():
	c = input(1)
	while c == '\n' or c == '\r' or c == ' ':
		c = input(1)
	return c

def readStr():
	c = input(1)
	while c == '\n' or c == '\r' or c == ' ':
		c = input(1)
	s = str()
	while c != '\n' and c != '\r' and (c != ' '):
		s += c
		c = input(1)
	return s

def readInt():
	c = input(1)
	while c != '-' and (not c.isdigit()):
		c = input(1)
	d: int = -1
	x: int = 0
	if c.isdigit():
		d = 1
	else:
		c = input(1)
	while c.isdigit():
		x = x * 10 + ord(c) - ord('0')
		c = input(1)
	return d * x

def gcd(a, b):
	while b > 0:
		(a, b) = (b, a % b)
	return a

def lcm(a, b):
	return a * b // gcd(a, b)
eps = 10 ** (-9)
inf = 10 ** 18
mod = 10 ** 9 + 7

def solution():
	n = readInt()
	k = readInt()
	m = n // k
	n -= m * k
	print(min(n, k // 2) + m * k)
tests = 1
tests = readInt()
while tests > 0:
	solution()
	tests -= 1


for _ in range(int(input())):
	A = input().split()
	n = int(A[0])
	k = int(A[1])
	print(n // k * k + min(n % k, k // 2))


testcases = int(input())
for i in range(testcases):
	(candies, kids) = map(int, input().split())
	candie_with_each_kid = candies // kids
	candies_left = candies - candie_with_each_kid * kids
	if candies_left != 0:
		candies_left -= kids // 2
	if candies_left <= 0:
		candies_left = 0
	print(candies - candies_left)


for _ in range(int(input())):
	(a, b) = input().split()
	a = int(a)
	b = int(b)
	rem = a % b
	if rem == 0:
		print(a)
	elif rem <= b // 2:
		print(a)
	else:
		print(a // b * b + b // 2)


from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations
import sys
import bisect
import string
import math
import time
import random

def I():
	return int(input())

def MI():
	return map(int, input().split())

def LI():
	return [int(i) for i in input().split()]

def LI_():
	return [int(i) - 1 for i in input().split()]

def StoI():
	return [ord(i) - 97 for i in input()]

def ItoS(nn):
	return chr(nn + 97)

def GI(V, E, Directed=False, index=0):
	org_inp = []
	g = [[] for i in range(n)]
	for i in range(E):
		inp = LI()
		org_inp.append(inp)
		if index == 0:
			inp[0] -= 1
			inp[1] -= 1
		if len(inp) == 2:
			(a, b) = inp
			g[a].append(b)
			if not Directed:
				g[b].append(a)
		elif len(inp) == 3:
			(a, b, c) = inp
			aa = (inp[0], inp[2])
			bb = (inp[1], inp[2])
			g[a].append(bb)
			if not Directed:
				g[b].append(aa)
	return (g, org_inp)

def bit_combination(k, n=2):
	rt = []
	for tb in range(n ** k):
		s = [tb // n ** bit % n for bit in range(k)]
		rt += [s]
	return rt

def show(*inp, end='\n'):
	if show_flg:
		print(*inp, end=end)
YN = ['Yes', 'No']
mo = 10 ** 9 + 7
inf = float('inf')
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
input = lambda : sys.stdin.readline().rstrip()

def ran_input():
	import random
	n = random.randint(4, 16)
	(rmin, rmax) = (1, 10)
	a = [random.randint(rmin, rmax) for _ in range(n)]
	return (n, a)
show_flg = False
show_flg = True
ans = 0
t = I()
for _ in range(t):
	(n, k) = LI()
	r = n - n // k * k
	ans = n // k * k + min(r, k // 2)
	print(ans)


for tt in range(int(input())):
	(n, k) = map(int, input().split())
	if n % k == 0:
		ans = n // k * k
	else:
		ans = n // k * k
		if n % k > k // 2:
			ans += k // 2
		if n % k < k // 2:
			ans += n % k
		if n % k == k // 2:
			ans += n % k
	print(ans)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	ans = n // k * k
	if n % k >= k // 2:
		ans += k // 2
	elif n % k < k // 2:
		ans += n % k
	print(ans)


R = lambda : map(int, input().split())
(t,) = R()
for _ in range(t):
	(n, k) = R()
	print(n - max(0, n % k - k // 2))


import math
cases = int(input())
returnValue = []
for i in range(cases):
	inList = input().split(' ')
	candies = int(inList[0])
	kids = int(inList[1])
	leftOver = candies % kids
	if leftOver == 0:
		returnValue.append(candies)
	else:
		leftOver -= math.floor(kids / 2)
		if leftOver <= 0:
			returnValue.append(candies)
		else:
			returnValue.append(candies - leftOver)
for i in returnValue:
	print(i)


MOD = 1000000007
MOD2 = 998244353
ii = lambda : int(input())
si = lambda : input()
dgl = lambda : list(map(int, input()))
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
ls = lambda : list(input())
for _ in range(ii()):
	(n, k) = f()
	if n % k > k // 2:
		print(n // k * k + k // 2)
	else:
		print(n)


T = int(input())
for t in range(T):
	(n, k) = list(map(int, input().split()))
	total = n
	n -= n // k * k
	n -= k // 2
	n = max(0, n)
	print(total - n)


T = int(input())
for t in range(T):
	(n, k) = map(int, input().split())
	m = n // k
	r = n % k
	r = min(k // 2, r)
	ans = k * m + r
	print(ans)


from fractions import gcd
from itertools import combinations, permutations, accumulate, product
from collections import deque, defaultdict, Counter
import decimal
import re
import math
import sys
sys.setrecursionlimit(10000000)
mod = 998244353

def readInts():
	return list(map(int, input().split()))

def I():
	return int(input())
for _ in range(I()):
	(n, k) = readInts()
	if n < k:
		if k // 2 >= n:
			print(n)
			continue
		else:
			print(k // 2)
			continue
	if n % k == 0:
		print(n)
		continue
	else:
		ok = int(math.floor(k / 2))
		l = n // k
		print(min(n, l * k + ok))
		continue


def solve(n, k):
	residual = n - n // k * k
	exceed = max(0, residual - k // 2)
	return n - exceed
t = int(input())
for i in range(t):
	(n, k) = input().strip().split(' ')
	n = int(n)
	k = int(k)
	print(solve(n, k))


t = int(input())
for case in range(t):
	(n, k) = [int(x) for x in input().split(' ')]
	ans = k * (n // k) + min(n % k, k // 2)
	print(ans)


def cand_div(candy, kids):
	a = candy // kids
	total = a * kids
	if candy % kids is not 0:
		b = a + 1
		extra = candy % kids
		if extra < kids // 2:
			total = total + extra
		else:
			total = total + kids // 2
	print(total)
b = []
t = int(input(''))
for i in range(t):
	b.append(list(map(int, input('').split())))
for i in range(len(b)):
	cand_div(b[i][0], b[i][1])


def case():
	(n, k) = map(int, input().split())
	ans = n - n % k
	if n % k > k // 2:
		ans += k // 2
	else:
		ans += n % k
	print(ans)
for _ in range(int(input())):
	case()


t = int(input())
for i in range(t):
	(n, k) = input().split()
	n = int(n)
	k = int(k)
	result = k * (n // k)
	if result < n:
		result += k // 2
	if result > n:
		result = n
	print(result)


x = int(input())
for _ in range(x):
	(a, b) = map(int, input().split())
	c = a // b * b
	a -= c
	c += min(b // 2, a)
	print(c)


t = int(input())
for i in range(t):
	l = []
	(n, k) = [int(x) for x in input().split()]
	d = int(n % k)
	y = n - d
	l.append(d)
	c = int(k / 2)
	l.append(c)
	s = min(l)
	total = y + s
	print(total)


T = int(input())
for _ in range(T):
	(N, K) = map(int, input().split(' '))
	multipler = N // K
	remainder = N % K
	if remainder <= K // 2:
		print(multipler * K + remainder)
	else:
		print(multipler * K + K // 2)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	p = n // k * k
	g = n - p
	if g == 0:
		print(n)
	else:
		d = k // 2
		h = p + d
		if h <= n:
			print(h)
		else:
			print(n)


t = int(input())
for z in range(t):
	line = input()
	(n, k) = (int(s) for s in line.split())
	nb = n - n % k
	n %= k
	if n > k / 2:
		nb += int(k / 2)
	else:
		nb += n
	print(nb)


for i in range(int(input())):
	(n, k) = [int(a) for a in input().split()]
	s = n - n % k
	print(min(n, s + k // 2))


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


query = int(input())
for _ in range(query):
	(n, k) = map(int, input().split())
	p = n // k
	p *= k
	d = n - p
	if d <= k // 2:
		p += d
	else:
		p += k // 2
	print(p)


t = int(input())
while t > 0:
	t = t - 1
	(n, k) = map(int, input().split())
	s = n // k * k
	n = n - s
	if n > 0:
		if n > k // 2:
			s += k // 2
		else:
			s += n
	print(s)


test = int(input())
while test > 0:
	(n, k) = map(int, input().split())
	if n % k <= k // 2:
		res = n // k * k + n % k
	else:
		res = n // k * k + k // 2
	print(res)
	test = test - 1


t = int(input())
for x in range(0, t):
	strng = input()
	l1 = strng.split(' ')
	n = int(l1[0])
	k = int(l1[1])
	if n % k == 0:
		print(n)
		continue
	else:
		lft = n % k
		dist = k * int(n / k)
		if lft > int(k / 2):
			dist = dist + int(k / 2)
		else:
			dist = dist + lft
	print(dist)


q = int(input())
for i in range(q):
	(n, k) = map(int, input().split())
	y = n % k
	print(n // k * k + min(y, k // 2))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	q = n // k
	c = q * k
	if n % k == 0:
		print(c)
	else:
		extra = int(0.5 * k)
		r = n % k
		if r > extra:
			c += extra
		else:
			c += r
		print(c)


t = int(input())
n = list()
k = list()
konf = list()
for i in range(t):
	st = input()
	n.append(int(st[:st.find(' ')]))
	k.append(int(st[st.find(' '):]))
	konf.append(n[i] - n[i] % k[i])
	konf[i] += min(k[i] // 2, n[i] % k[i])
for i in range(t):
	print(konf[i])


t = int(input())
for _ in range(t):
	(n, k) = (int(i) for i in input().split())
	ans = 0
	ans = ans + n // k * k
	r = n % k
	if r > 0:
		ans = ans + min(r, k // 2)
	print(ans)


(_, *s) = open(0)
for s in s:
	(n, k) = map(int, s.split())
	print(n // k * k + min(k // 2, n % k))


T = int(input())
for _ in range(T):
	(n, k) = list(map(int, input().split()))
	print(n // k * k + min(n % k, int(k / 2)))


num = int(input())
ans = []
for i in range(num):
	(candies, kids) = input().split()
	c = int(candies)
	t = c
	k = int(kids)
	a = c // k
	b = a + 1
	d = k // 2
	c = c - k * a
	if c >= d:
		c = c - d
	else:
		c = 0
	ans.append(t - c)
for i in range(num):
	print(ans[i])


t = int(input())
while t > 0:
	st = input().split()
	n = int(st[0])
	k = int(st[1])
	if n % k == 0:
		print(n)
	else:
		q = int(n // k)
		r = n % k
		ck = int(k // 2)
		m1 = q * k
		if r >= ck:
			print(m1 + ck)
		else:
			print(m1 + r)
	t -= 1


t = int(input())
while t:
	t -= 1
	(n, k) = map(int, input().split())
	ans = n // k * k
	left = n % k
	ans += min(left, k // 2)
	print(min(ans, n))


import sys, math
MOD = 998244353
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	ans = k * (n // k) + min(k // 2, n % k)
	print(ans)


T = int(input())
for t in range(T):
	(n, k) = map(int, input().split())
	a = n // k
	r = n % k
	if r <= k // 2:
		print(n)
	else:
		print(n - r + k // 2)


z = int(input())
for zz in range(z):
	(n, k) = map(int, input().split())
	ans = n // k * k
	n -= n // k * k
	ans += min(k // 2, n)
	print(ans)


import sys
input = sys.stdin.readline
result = ''
for i in range(int(input())):
	(n, k) = map(int, input().split())
	thr = min(k // 2, n % k)
	ans = n if n % k == 0 else n // k * k + thr
	result += str(ans) + '\n'
print(result)


tests = int(input())
for te in range(tests):
	(n, k) = list(map(int, input().split()))
	a = n // k
	b = n % k
	ans = 0
	ans = a * k
	if b < k // 2:
		ans += b
	else:
		ans += k // 2
	print(ans)


import sys
import math

def main():
	T = int(sys.stdin.readline())
	for _ in range(T):
		(N, K) = (int(x) for x in sys.stdin.readline().split())
		Q = N // K
		R = N % K
		if R > K // 2:
			R = K // 2
		sys.stdout.write(f'{Q * K + R}\n')
main()


def test(n, k):
	a = n // k
	n %= k
	print(min(n, k // 2) + a * k)
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	test(n, k)


from math import floor, ceil
t = int(input())
for i in range(t):
	(n, k) = list(map(int, input().split()))
	dist = n - n % k
	dist += min(n % k, k // 2)
	print(dist)


try:
	t = int(input())
	while t:
		t -= 1
		(n, k) = map(int, input().split())
		print(n // k * k + min(k // 2, n % k))
except:
	pass


import math
t = int(input())
for _ in range(t):
	(a, b) = [int(x) for x in input().split()]
	c = math.floor(a / b)
	print(min(a, b * c + math.floor(b / 2)))


for _ in range(int(input())):
	(x, y) = map(int, input().split())
	print(y * (x // y) + min(y // 2, x % y))


import sys
T = int(sys.stdin.readline().strip())
for _ in range(T):
	(N, K) = [int(i) for i in sys.stdin.readline().strip().split(' ')]
	each = N // K
	tot = each * K
	tot += min(N - tot, K // 2)
	print(tot)


import itertools
import math
import sys
import heapq
from collections import Counter
from collections import deque
from fractions import gcd
from functools import reduce
INF = 1 << 60
sys.setrecursionlimit(10 ** 6)
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	ans = n // k * k
	n %= k
	ans += min(k // 2, n)
	print(ans)


t = int(input())
while t > 0:
	(n, k) = [int(i) for i in input().split()]
	d = n // k
	r = n % k
	d = d * k
	k = k // 2
	if r >= k:
		d += k
	else:
		d += r
	print(d)
	t -= 1


import sys
from bisect import bisect_left as bl, bisect_right as br, bisect
import math
from itertools import zip_longest as zl
from itertools import groupby as gb
from itertools import combinations as comb
from itertools import combinations_with_replacement as cwr
from collections import defaultdict as dd
from collections import deque as dq
from collections import Counter as c
mod = pow(10, 9) + 7
mod2 = 998244353

def data():
	return input()

def l():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [[val for i in range(n)] for j in range(m)]
for _ in range(int(data())):
	(n, k) = sp()
	ans = n // k * k
	n = n % k
	temp = k // 2
	if n <= temp:
		ans += n
	else:
		ans += temp
	print(ans)


testcases = int(input())
for i in range(testcases):
	inval = input()
	nk = inval.split(' ')
	n = int(nk[0])
	k = int(nk[1])
	first_distribution = n // k
	remaining_n = n - k * first_distribution
	if remaining_n > k // 2:
		second_distribution = k // 2
	else:
		second_distribution = remaining_n
	print(k * first_distribution + second_distribution)


t = input()
for _ in range(int(t)):
	s = input().split(' ')
	c = int(s[0])
	k = int(s[1])
	m = int(c / k)
	total = m * k
	left = c - total
	more = min(int(k / 2), left)
	total += more
	print(total)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	p = n // m
	r = n % m
	c = min(r, int(m / 2))
	print(p * m + c)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	ans = n
	a = n % k
	ans -= max(0, a - k // 2)
	print(ans)


t = int(input())
for i in range(t):
	(a, b) = map(int, input().strip().split())
	n = a - a % b + min(a % b, int(b / 2))
	print(n)


k = int(input())
for i in range(k):
	(n, k) = map(int, input().split())
	r = n // k * k
	m = n % k
	r += min(m, k // 2)
	print(r)


import sys
t = int(sys.stdin.readline())
for _ in range(t):
	(n, k) = map(int, sys.stdin.readline().split())
	divd = n // k
	n -= divd * k
	answ = divd * k + min(n, k // 2)
	print(answ)


t = int(input())
while t:
	t = t - 1
	(a, b) = map(int, input().split())
	c = 0
	k = 0
	k = a % b
	c = a - k
	l = 0
	if k >= b // 2:
		c = c + b // 2
	else:
		c = c + k
	print(c)


t = int(input())
for i in range(t):
	(n, k) = input().split()
	n = int(n)
	k = int(k)
	p = n - n // k * k
	if p <= k // 2:
		print(n)
	else:
		print(n // k * k + k // 2)


import sys
import bisect

def ri():
	return int(input())

def rl():
	return list(map(int, input().split()))
t = ri()
for _ in range(t):
	(n, k) = rl()
	ans = 0
	a = n // k
	r = n % k
	if r == 0:
		ans = n
	else:
		l = min(r, k // 2)
		ans = l * (a + 1) + a * (k - l)
	print(ans)


from sys import stdin, stdout

def main():
	r = stdin.readline
	w = stdout.write
	for i in range(int(input())):
		(n, k) = map(int, r().split())
		half = k // 2
		a1 = n // k + 1
		ans = a1 * half
		ans = min(n, ans + (k - half) * (a1 - 1))
		w('%d\n' % ans)
main()


import sys
t = int(sys.stdin.readline().rstrip())

def main():
	for _ in range(t):
		(n, k) = map(int, sys.stdin.readline().split())
		(q, r) = divmod(n, k)
		ans = q * k + min(r, k // 2)
		yield ans
ans = main()
print(*ans, sep='\n')


q = int(input())
for i in range(q):
	(w, e) = map(int, input().split())
	m = w % e
	b = w - m
	a = e // 2
	if a < m:
		print(a + b)
	elif a > m:
		print(b + m)
	else:
		print(a + b)


t = int(input())
for T in range(t):
	(n, k) = [int(x) for x in input().split()]
	val = n // k * k
	n -= val
	if n > 0:
		val += min(k // 2, n)
	print(val)


def solve():
	(n, k) = map(int, input().split())
	ans = n // k * k + min(n % k, k // 2)
	print(ans)
t = int(input())
for _ in range(t):
	solve()


t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	min = a // b
	if a % b == 0:
		print(a)
	else:
		max = min + 1
		if b % 2 != 0:
			lip = max * (b // 2) + min * (b // 2 + 1)
		else:
			lip = max * (b // 2) + min * (b // 2)
		if lip > a:
			print(a)
		else:
			print(lip)


n = int(input())
l = []
for i in range(n):
	(a, b) = input().split()
	c = int(a)
	k = int(b)
	r = c % k
	if r <= k / 2:
		l.append(c)
	else:
		l.append(c - r + k / 2)
for i in l:
	print(int(i))


for i in range(int(input())):
	(c, k) = map(int, input().split())
	total = c // k * k + min(c % k, k // 2)
	print(total)


tc = input()
for i in range(int(tc)):
	(n, k) = [int(x) for x in input().split(' ')]
	a = n // k
	rem = n - a * k
	rem = rem - k // 2
	if rem > 0:
		print(n - rem)
	else:
		print(n)


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import *
from copy import *
from collections import deque
from collections import Counter as counter
from itertools import combinations as comb
from itertools import permutations as permutate
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func
mod = 1000000007

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for p in range(t):
		solve()

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def solve():
	(n, k) = sep()
	t1 = n // k
	t2 = n % k
	print(t1 * k + min(k // 2, t2))
testcase(int(inp()))


q = int(input())
for i in range(q):
	(k, n) = [int(i) for i in input().split()]
	m = k // n
	print(min(m * n + n // 2, k))


import math
from decimal import Decimal
import heapq
from collections import deque

def na():
	n = int(input())
	b = [int(x) for x in input().split()]
	return (n, b)

def nab():
	n = int(input())
	b = [int(x) for x in input().split()]
	c = [int(x) for x in input().split()]
	return (n, b, c)

def dv():
	(n, m) = list(map(int, input().split()))
	return (n, m)

def da():
	(n, m) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	return (n, m, a)

def dva():
	(n, m) = list(map(int, input().split()))
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	return (n, m, b)

def eratosthenes(n):
	sieve = list(range(n + 1))
	for i in sieve:
		if i > 1:
			for j in range(i + i, len(sieve), i):
				sieve[j] = 0
	return sorted(set(sieve))

def lol(lst, k):
	k = k % len(lst)
	ret = [0] * len(lst)
	for i in range(len(lst)):
		if i + k < len(lst) and i + k >= 0:
			ret[i] = lst[i + k]
		if i + k >= len(lst):
			ret[i] = lst[i + k - len(lst)]
		if i + k < 0:
			ret[i] = lst[i + k + len(lst)]
	return ret

def nm():
	n = int(input())
	b = [int(x) for x in input().split()]
	m = int(input())
	c = [int(x) for x in input().split()]
	return (n, b, m, c)

def dvs():
	n = int(input())
	m = int(input())
	return (n, m)

def fact(a, b):
	c = []
	ans = 0
	f = int(math.sqrt(a))
	for i in range(1, f + 1):
		if a % i == 0:
			c.append(i)
	l = len(c)
	for i in range(l):
		c.append(a // c[i])
	for i in range(len(c)):
		if c[i] <= b:
			ans += 1
	if a / f == f and b >= f:
		return ans - 1
	return ans
import math
from decimal import Decimal
import heapq
from collections import deque

def na():
	n = int(input())
	b = [int(x) for x in input().split()]
	return (n, b)

def nab():
	n = int(input())
	b = [int(x) for x in input().split()]
	c = [int(x) for x in input().split()]
	return (n, b, c)

def dv():
	(n, m) = list(map(int, input().split()))
	return (n, m)

def da():
	(n, m) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	return (n, m, a)

def dva():
	(n, m) = list(map(int, input().split()))
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	return (n, m, b)

def eratosthenes(n):
	sieve = list(range(n + 1))
	for i in sieve:
		if i > 1:
			for j in range(i + i, len(sieve), i):
				sieve[j] = 0
	return sorted(set(sieve))

def lol(lst, k):
	k = k % len(lst)
	ret = [0] * len(lst)
	for i in range(len(lst)):
		if i + k < len(lst) and i + k >= 0:
			ret[i] = lst[i + k]
		if i + k >= len(lst):
			ret[i] = lst[i + k - len(lst)]
		if i + k < 0:
			ret[i] = lst[i + k + len(lst)]
	return ret

def nm():
	n = int(input())
	b = [int(x) for x in input().split()]
	m = int(input())
	c = [int(x) for x in input().split()]
	return (n, b, m, c)

def dvs():
	n = int(input())
	m = int(input())
	return (n, m)

def fact(a, b):
	c = []
	ans = 0
	f = int(math.sqrt(a))
	for i in range(1, f + 1):
		if a % i == 0:
			c.append(i)
	l = len(c)
	for i in range(l):
		c.append(a // c[i])
	for i in range(len(c)):
		if c[i] <= b:
			ans += 1
	if a / f == f and b >= f:
		return ans - 1
	return ans
for i in range(int(input())):
	(n, k) = list(map(int, input().split()))
	d = n // k
	n -= d * k
	ans = d * k + min(k // 2, n)
	print(ans)


q = int(input())
answers = []
for q in range(q):
	ints = list(map(int, input().split()))
	(n, k) = (ints[0], ints[1])
	ans = n // k * k
	remainder = n - ans
	ans += min(k // 2, remainder)
	answers.append(ans)
for a in answers:
	print(a)


for _ in range(int(input())):
	data = input()
	da = data.split()
	n = int(da[0])
	k = int(da[1])
	ans = k * (n // k)
	if ans < n:
		ans = ans + k // 2
	if ans > n:
		print(n)
	else:
		print(ans)


n_cases = int(input().strip())
results = []
for _ in range(n_cases):
	(n, k) = list(map(int, input().strip().split()))
	if n % k == 0:
		result = n
	else:
		base = n // k
		c = n - base * k
		if c > k // 2:
			result = base * k + k // 2
		else:
			result = base * k + c
	results.append(result)
print('\n'.join(map(str, results)))


m = int(input())
for i in range(m):
	(n, k) = map(int, input().split())
	a = int(n / k)
	b = n % k
	c = int(k / 2)
	if b >= c:
		summ = a * k + c
	else:
		summ = a * k + b
	print(summ)


def program():
	(n, k) = input().split()
	n = int(n)
	k = int(k)
	if n % k <= k // 2:
		print(n)
	else:
		print(n // k * k + k // 2)
t = int(input())
for i in range(t):
	program()


n = int(input())
soln = []
for i in range(0, n):
	a = []
	(x, y) = map(int, input().split())
	div = x // y
	limit = y // 2
	lol = x - max(0, x % y - y // 2)
	soln.append(lol)
for i in range(0, len(soln)):
	print(soln[i], '\r')


q = int(input())
for iwer in range(q):
	(c, kids) = map(int, input().split())
	dystr = c // kids * kids
	cc = c
	c -= dystr
	poz = max(0, c - kids // 2)
	print(cc - poz)


t = int(input())
for k in range(t):
	entrada = list(map(int, input().split(' ')))
	candies = int(entrada[0])
	kids = int(entrada[1])
	p = candies // kids
	remain = candies - kids * p
	if remain >= kids // 2:
		print(kids * p + kids // 2)
	else:
		print(remain + p * kids)


def solve():
	t = int(input())
	for _ in range(t):
		(n, k) = map(int, input().split())
		base = n // k
		r = n % k
		if r < k // 2:
			print(base * k + r)
		else:
			print(base * k + k // 2)
solve()


import sys, math
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return s[:len(s) - 1]

def invr():
	return map(int, input().split())
t = 1
t = inp()
for tt in range(t):
	(n, k) = invr()
	q = n // k * k
	q = q + min(k // 2, n - q)
	print(q)


import math

def shrey():
	(n, k) = input().split()
	n = int(n)
	k = int(k)
	print(n - max(0, n % k - k // 2))
T = input()
T = int(T)
for q in range(1, T + 1):
	shrey()


mod = 10 ** 9 + 7
import math

def ain():
	return map(int, input().split())
for _ in range(int(input())):
	(a, b) = ain()
	sol = a - a % b + min(b // 2, a % b)
	print(int(sol))


a = int(input())
result = ''
for i in range(a):
	s = input()
	(n, k) = (int(s.split(' ')[0]), int(s.split(' ')[1]))
	if n % k == 0:
		result += f'{n}\n'
	elif n % k > k // 2:
		result += f'{k // 2 + n - n % k}\n'
	else:
		result += f'{n // k * k + n % k}\n'
print(result)


import math
T = int(input())
for i in range(T):
	(n, k) = map(int, input().split())
	d = False
	if n % k == 0:
		print(n)
	else:
		print(n - n % k + min(k // 2, n % k))


q = int(input())
for i in range(q):
	(n, k) = map(int, input().split())
	ans = n // k * k
	rem = n - ans
	if rem > 0:
		ans += min(rem, k // 2)
	print(ans)


t = int(input())
while t > 0:
	(n, k) = [int(x) for x in input().split()]
	print(n - n % k + min(k // 2, n % k))
	t -= 1


for s in [*open(0)][1:]:
	(n, k) = map(int, s.split())
	print(n - max(0, n % k - k // 2))


from bisect import bisect_left as bl
from bisect import bisect_right as br
import heapq
import math
from collections import *
from functools import reduce, cmp_to_key
import sys
input = sys.stdin.readline

def factors(n):
	return sorted(list(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))))

def inv_mod(n):
	return pow(n, mod - 2, mod)

def li():
	return [int(i) for i in input().rstrip('\n').split(' ')]

def st():
	return input().rstrip('\n')

def val():
	return int(input().rstrip('\n'))

def li2():
	return [i for i in input().rstrip('\n').split(' ')]

def li3():
	return [int(i) for i in input().rstrip('\n')]
for _ in range(val()):
	(n, k) = li()
	tot = n // k * k
	n -= n // k * k
	tot += min(k // 2, n)
	print(tot)


n = int(input())
for i in range(n):
	(a, b) = input().split(' ')
	a = int(a)
	b = int(b)
	if b // 2 > a % b:
		x = a % b
	else:
		x = b // 2
	print(a // b * b + x)


for _ in range(int(input())):
	l = [int(o) for o in input().split()]
	n = l[0]
	k = l[1]
	print(n // k * k + min(k // 2, n % k))


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	a = n // m
	a = a * m
	if n % m > m // 2:
		a = a + m // 2
	else:
		a = a + n % m
	print(a)


import math
for _ in range(int(input())):
	(candies, k) = map(int, input().split(' '))
	x = math.floor(k / 2.0)
	remainder = candies % k
	y = math.floor(candies / k * 1.0)
	print(k * y + min(remainder, x))


from collections import Counter
from collections import defaultdict
import math
import random
import heapq as hq
from math import sqrt
from functools import reduce

def factors(n):
	step = 2 if n % 2 else 1
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(sqrt(n)) + 1, step) if n % i == 0)))

def inp():
	return map(int, input().split())
mod = int(1000000000.0) + 7

def solve(a, m):
	ans = []
	ds = []
	for fact in factors(m):
		if m % fact == 0 and fact != m:
			if (m // fact - 1) % a == 0:
				temp = (m - fact) // a
				ds.append(fact)
				ans.append(temp)
	ans.sort()
	an = []
	n = len(ans)
	for i in range(n):
		an.append(str(ans[i]))
	print(n)
	return ' '.join(an)

def solve1(s):
	n = len(s)
for _ in range(int(input())):
	(a, b) = inp()
	temp = a // b * b
	left = a % b
	if left >= b // 2:
		left = b // 2
	print(temp + left)


t = int(input())
for i in range(t):
	(n, k) = list(map(int, input().split()))
	n1 = n % k
	k1 = int(k / 2)
	if n1 <= k1:
		print(n)
	else:
		print(n - n1 + k1)


import math
t = int(input())
ans = []
for i in range(t):
	(n, k) = map(int, input().split(' '))
	x = math.floor(n / k)
	x = x * k
	x = x + min(n % k, math.floor(k / 2))
	ans.append(x)
for j in range(t):
	print(ans[j])


import math as m
t = int(input())
for i in range(t):
	[c, k] = list(map(int, input().split()))
	if c % k == 0:
		print(c)
	else:
		z = c % k
		temp = int(c / k)
		tobe = m.floor(k / 2)
		print(min(tobe, z) + temp * k)


import math
r = int(input())
while r:
	(n, k) = map(int, input().split())
	print(n - n % k + min(n % k, math.floor(k / 2)))
	r -= 1


from math import ceil
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	g = ceil(n / k)
	x = k // 2
	t = n // k
	print(min(n, x * g + t * (k - x)))


t = int(input())
for _ in range(t):
	(a, b) = list(map(int, input().split()))
	rem = a // b
	rem2 = b * rem
	rem3 = a - rem2
	d = b // 2
	if rem3 >= d:
		ans = rem2 + d
	else:
		ans = rem2 + rem3
	print(int(ans))


t = int(input())
while t:
	t -= 1
	(n, k) = tuple(map(int, input().split()))
	ans = n // k * k
	mod = n % k
	ans += min(k // 2, mod)
	print(ans)


k = int(input())
for i in range(k):
	(q, w) = map(int, input().split())
	print(min(q, q // w * w + w // 2))


import math
for i in range(int(input())):
	(n, k) = map(int, input().split())
	t = n // k
	rem = n % k
	print(n - max(rem - k // 2, 0))


for i in range(int(input())):
	(n, k) = map(int, input().split())
	if n % k == 0:
		print(n)
	elif n == 1:
		print(1)
	else:
		ans = n // k * k
		left = n % k
		if left >= k // 2:
			ans += k // 2
		elif left < k // 2:
			ans += left
		print(ans)


for i in range(int(input())):
	a = [int(i) for i in input().split()]
	print(a[0] // a[1] * a[1] + min(a[0] % a[1], a[1] // 2))


t = int(input())
while t > 0:
	(n, k) = map(int, input().split())
	t = t - 1
	if n > k:
		mindis = n - int(n / k) * k
		if mindis >= int(k / 2):
			maxdis = int(n / k) * k + int(k / 2)
		elif mindis < int(k / 2):
			maxdis = int(n / k) * k + mindis
		print(maxdis)
	elif n < k:
		if n <= int(k / 2):
			print(n)
		elif n > int(k / 2):
			print(int(k / 2))
	elif n == k:
		print(n)


t = int(input())
for i in range(0, t):
	n_k = input().split(' ')
	n_k = list(map(int, n_k))
	n = n_k[0]
	k = n_k[1]
	remainder = n % k
	a = n // k
	if remainder <= int(k / 2):
		print(n)
	elif remainder > int(k / 2):
		print(a * k + int(k / 2))


import math
for i in range(int(input())):
	(n, k) = list(map(int, input().split()))
	r = n // k
	a = r * k
	b = n - r * k
	c = k // 2
	if b > c:
		print(a + c)
	else:
		print(a + b)


import sys
import math
CASE = 1
rla = ''

def solve():
	(n, m) = map(int, input().split())
	r = n % m
	mi = int((n - r) / m)
	print(m * mi + min(r, m >> 1))
while True:
	rla = sys.stdin.readline()
	cases = 1
	if not rla:
		break
	if (rla == '\n') | (rla == ''):
		continue
	if CASE == 1:
		cases = int(rla)
	for cas in range(cases):
		solve()


from __future__ import division, print_function
import os, sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().strip().split(' '))

def msi():
	return map(str, input().strip().split(' '))

def li():
	return list(mi())

def dmain():
	sys.setrecursionlimit(100000000)
	threading.stack_size(40960000)
	thread = threading.Thread(target=main)
	thread.start()
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def getKey(item):
	return item[1]

def sort2(l):
	return sorted(l, key=getKey)

def d2(n, m, num):
	return [[num for x in range(m)] for y in range(n)]

def isPowerOfTwo(x):
	return x and (not x & x - 1)

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def ntl(n):
	return [int(i) for i in str(n)]

def powerMod(x, y, p):
	res = 1
	x %= p
	while y > 0:
		if y & 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def read():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def main():
	for _ in range(ii()):
		(n, k) = mi()
		m = n // k
		r = n % k
		print(m * k + min(r, k // 2))
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	a = n // k
	if n % k == 0:
		b = a
	else:
		b = a + 1
	k1 = k // 2
	total = b * k1 + a * (k - k1)
	if total > n:
		print(n)
	else:
		print(total)


T = int(input())
for _ in range(0, T):
	(n, k) = map(int, input().split())
	a = n // k
	b = a * k
	d = b
	c = n - b
	x = k // 2
	d += min(c, x)
	print(d)


t = int(input())
for __ in range(t):
	(n, k) = map(int, input().split())
	if n % k == 0:
		print(n)
	else:
		dist = n - n % k
		maxspecial = k // 2
		dist += min(maxspecial, n - dist)
		print(dist)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	if n == k:
		print(n)
		continue
	if n % k == 0:
		print(n)
		continue
	a = int(n / k)
	b = n % k
	print(a * k + min(int(k / 2), b))


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	(div, mod) = divmod(n, k)
	print(div * k + min(mod, k // 2))


def inp(n):
	if n == 1:
		return map(int, stdin.readline().split())
	elif n == 2:
		return map(float, stdin.readline().split())
	else:
		return map(str, stdin.readline().split())
from sys import *
from math import *
for i in range(int(input())):
	(n, k) = inp(1)
	(mi, ma) = (floor(n / k), ceil(n / k))
	(ans, j) = (mi * ceil(k / 2) + ma * floor(k / 2), 1)
	if ans > n:
		print(n)
	else:
		print(ans)


import operator as o
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	if n % k != 0 and n - n // k * k > k // 2:
		can = n // k * k + k // 2
	else:
		can = n
	print(can)


num_t = int(input())
for t in range(num_t):
	(n, k) = map(int, input().split())
	(q, r) = divmod(n, k)
	print(q * k + min(r, k // 2))


n = int(input())
for y in range(n):
	sc = list(map(int, input().split()))
	k = sc[1] // 2
	rep = sc[0] % sc[1]
	k = rep - k
	if k < 0:
		k = 0
	print(sc[0] - k)


t = int(input())
for v in range(t):
	(n, k) = map(int, input().split())
	x = n // k
	y = k // 2
	w = x * k
	e = n - w
	ans = w
	ans += min(y, e)
	print(ans)


t = int(input())
for i in range(t):
	(can, kid) = input().split()
	(can, kid) = (int(can), int(kid))
	print(min(can, can // kid * kid + kid // 2))


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	resto = n % k
	aux = min(resto, k // 2)
	print(n // k * k + aux)


res = []
for _ in range(int(input())):
	(n, k) = [int(i) for i in input().split()]
	a = n // k
	res.append(min(k * a + k // 2, n))
for r in res:
	print(r)


t = int(input())
l = []
for i in range(0, t):
	l.append(input().split())
for j in l:
	print(min((int(j[0]), int(j[1]) * (int(j[0]) // int(j[1])) + int(j[1]) // 2)))


from math import floor
t = int(input())
for _ in range(t):
	(n, k) = [int(i) for i in input().split()]
	if k == 2:
		print(n)
		continue
	ans = n // k * k
	if n % k <= floor(k / 2):
		ans += n % k
	else:
		ans += floor(k / 2)
	print(ans)


m = int(input())
for i in range(m):
	(n, k) = map(int, input().split())
	ch = n
	ch -= ch // k * k
	if ch >= k // 2:
		ch -= k // 2
	else:
		ch = 0
	print(n - ch)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	if n < k:
		if n < k // 2:
			print(n)
		else:
			print(k // 2)
		continue
	mina = n // k * k
	extra = min(n % k, k // 2)
	ans = mina + extra
	print(ans)


t = int(input())
for i in range(t):
	l = input().strip().split()
	(n, k) = (int(l[0]), int(l[1]))
	whole_num = n // k * k
	if n % k != 0:
		whole_num += min(k // 2, n % k)
	print(whole_num)


t = int(input())
for _ in range(t):
	(n, k) = [int(i) for i in input().split()]
	m = n // k
	tot = m * k
	rem = n - tot
	if rem > 0:
		half = int(k // 2)
		tot += min(half, rem)
	print(tot)


t = int(input())
out = []
for i in range(t):
	(n, k) = map(int, input().split())
	if n % k <= k // 2:
		out.append(n)
	else:
		out.append(n - (n % k - k // 2))
for i in out:
	print(i)


ii = lambda : int(input())
kk = lambda : map(int, input().split())
ll = lambda : list(kk())
for _ in range(ii()):
	(a, b) = kk()
	print(a // b * b + min(a % b, b // 2))


t = int(input())
for i in range(t):
	r = input().split()
	n = int(r[0])
	k = int(r[1])
	a = n // k
	b = a + 1
	sum = k // 2 * b + (k - k // 2) * a
	if sum <= n:
		print(sum)
	else:
		print(n)


t = int(input())
m = []
for i in range(t):
	m.append(list(map(int, input().split())))
for i in m:
	n = i[0]
	k = i[1]
	print(n // k * k + min(n % k, k // 2))


import math
q = int(input())
for _ in range(q):
	(n, k) = list(map(int, input().split()))
	quo = math.floor(n / k)
	r = n % k
	if r > k / 2:
		y = quo * k + math.floor(k / 2)
		print(y)
	else:
		y = quo * k + r
		print(y)


import sys
Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 18
MOD = 998244353
for _ in range(int(ri())):
	(n, k) = Ri()
	div = n // k
	rem = n % k
	summ = k * div
	summ += min(rem, k // 2)
	print(summ)


from sys import stdin
from collections import deque
from math import sqrt, floor, ceil, log, log2, log10, pi, gcd, sin, cos, asin

def ii():
	return int(stdin.readline())

def fi():
	return float(stdin.readline())

def mi():
	return map(int, stdin.readline().split())

def fmi():
	return map(float, stdin.readline().split())

def li():
	return list(mi())

def lsi():
	x = list(stdin.readline())
	x.pop()
	return x

def si():
	return stdin.readline()

def sieve(x):
	a = [True] * (x + 1)
	sq = floor(sqrt(x))
	for i in range(3, sq + 1, 2):
		if a[i]:
			for j in range(i * i, x + 1, i):
				a[j] = False
	if x > 1:
		p = [2]
	else:
		p = []
	for i in range(3, x + 1, 2):
		if a[i]:
			p.append(i)
	return p
for _ in range(ii()):
	(a, b) = mi()
	x = a // b
	p = b // 2
	z = x * (b - p)
	z += (x + 1) * p
	print(min(a, z))


for __ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	x = k // 2
	num = n // k
	print(max(num * k, min(n, num * k + x)))


cases = int(input())
for case in range(cases):
	values = input().split()
	(candies, children) = (int(values[0]), int(values[1]))
	fair_amount = candies // children
	remainder = candies % children
	biased_children = children // 2
	result = fair_amount * children
	if remainder:
		if remainder <= biased_children:
			result += remainder
		else:
			result += biased_children
	print(result)


import sys
import math
get_string = lambda : sys.stdin.readline().strip()
get_int_list = lambda : list(map(int, sys.stdin.readline().strip().split()))
get_intList_from_str = lambda : list(map(int, list(sys.stdin.readline().strip())))
get_charList_from_str = lambda : list(sys.stdin.readline().strip())
get_char_list = lambda : sys.stdin.readline().strip().split()
get_int = lambda : int(sys.stdin.readline())
pt = lambda x: sys.stdout.write(str(x))
for i in range(get_int()):
	(n, k) = get_int_list()
	count = n // k * k
	if n - count >= k // 2:
		count += k // 2
	else:
		count += n - count
	print(count)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	x = int(n / k)
	if x * k < n:
		r = n - x * k
		if r > int(k / 2):
			print(x * k + int(k / 2))
		else:
			print(x * k + r)
	else:
		print(x * k)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	ans = 0
	left = n % k
	given = n - left
	ans += given
	a = k // 2
	if left >= a:
		ans += a
	else:
		ans += left
	print(ans)


T = int(input())
for kase in range(T):
	(n, k) = [int(x) for x in input().split()]
	ans = n // k * k
	ans += min(n % k, k // 2)
	print(ans)


from sys import stdin
import math
a = int(stdin.readline())
for k in range(0, a):
	A = stdin.readline().split()
	n = int(A[0])
	k = int(A[1])
	if n % k == 0:
		print(n)
	elif n % k > int(math.floor(k / 2)):
		print(n - n % k + int(math.floor(k / 2)))
	else:
		print(n)


import sys
input = sys.stdin.readline

def getInt():
	return int(input())

def getVars():
	return list(map(int, input().split()))

def getList():
	return list(map(int, input().split()))

def getStr():
	return input().strip()
t = getInt()
for _ in range(t):
	(n, k) = getVars()
	m = n // k
	if m * k == n:
		print(n)
		continue
	m1 = k // 2
	res = min(n, m * k + m1)
	print(res)


t = int(input())
while t:
	(n, k) = map(int, input().split())
	(ans, res, temp) = (0, 0, 0)
	temp = n // k * k
	n -= temp
	if n > 0:
		temp += min(k // 2, n)
	print(temp)
	t -= 1


def main():
	t = int(input())
	for _ in range(t):
		(n, k) = [int(x) for x in input().strip().split(' ')]
		answer = solve(n, k)
		print(answer)

def solve(n, k):
	if n % k <= k // 2:
		return n
	return k * (n // k) + k // 2
main()


t = int(input())
x = []
for i in range(t):
	(n, k) = map(int, input().split())
	j = [n, k]
	x.append(j)
for c in x:
	r = c[0] % c[1]
	if r <= c[1] // 2:
		print(c[0])
	else:
		print(c[0] - r + c[1] // 2)


count = int(input())
for i in range(count):
	(sweets, kids) = [int(elem) for elem in input().split()]
	print(sweets - sweets % kids + min(kids // 2, sweets % kids))


T = int(input())
for t in range(T):
	(c, k) = map(int, input().split())
	print(c - c % k + min(c % k, k // 2))


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	d1 = n % k
	a = k
	d2 = n // k
	k = k // 2
	sum = 0
	if d1 < k:
		sum = d1 + a * d2
	else:
		sum = a * d2 + k
	print(sum)


for i in range(int(input())):
	(llll, k) = map(int, input().split())
	if llll % k <= k // 2:
		print(llll)
	else:
		print(llll // k * k + k // 2)


import sys
read = lambda : list(map(int, sys.stdin.readline().strip().split()))
for _ in range(int(input())):
	(n, k) = read()
	can = n // k * k
	n -= can
	if k // 2 <= n:
		can += k // 2
	else:
		can += n
	print(can)


t = int(input())

def santa():
	for i in range(t):
		(a, b) = map(int, input().split())
		max_candies = a // b
		max_candies *= b
		half = b // 2
		extra_candies = a - max_candies
		max_candies += min(half, extra_candies)
		print(max_candies)
santa()


t = int(input())
for i in range(t):
	temp = list(input().split())
	n = int(temp[0])
	m = int(temp[1])
	a = n // m
	b = m // 2
	res = a * m + b
	if n % m == 0 or n < res:
		print(n)
	else:
		print(res)


T = int(input())
for i in range(T):
	(n, k) = list(map(int, input().split()))
	rem = n % k
	if rem > k // 2:
		ans = n - (rem - k // 2)
	else:
		ans = n
	print(ans)


qtd = int(input())
for _ in range(qtd):
	(doces, criancas) = map(int, input().split())
	total = doces - doces % criancas
	total += min(doces % criancas, criancas // 2)
	print(total)


from sys import stdin
t = int(stdin.readline())
for i in range(t):
	line = stdin.readline()
	line = line.split(' ')
	n = int(line[0])
	k = int(line[1])
	definitely = n // k * k
	remaining = n % k
	if remaining > k // 2:
		retval = definitely + k // 2
	else:
		retval = definitely + n % k
	print(retval)


from math import *
import os, sys
from bisect import *
from io import BytesIO
sys.setrecursionlimit(10 ** 9)
n1 = int(input())
for i in range(n1):
	(n, k) = map(int, input().split())
	x = n // k * k + min(n % k, k // 2)
	print(x)


def fun(n, k):
	if n % k == 0:
		return n
	else:
		a = n // k * k
		z = min(n, a + k // 2)
		return z
x = int(input(''))
for i in range(x):
	(n, k) = map(int, input('').split())
	z = fun(n, k)
	print(z)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	limit = k // 2
	each = n // k
	print(min(n, each * k + limit))


import math
T = int(input())
for i in range(T):
	(noOfCandies, noOfKids) = map(int, input().split())
	totalNumberOfCandies = math.floor(noOfCandies / noOfKids) * noOfKids
	remainder = noOfCandies % noOfKids
	if remainder < math.floor(noOfKids / 2):
		totalNumberOfCandies += remainder
	else:
		totalNumberOfCandies += math.floor(noOfKids / 2)
	print(totalNumberOfCandies)


import math

def dtb(n):
	return bin(n).replace('0b', '')

def btd(n):
	return int(n, 2)
t = int(input())
for k in range(t):
	(n, m) = map(int, input().split())
	if n < m:
		if n <= m // 2:
			print(n)
		else:
			print(m // 2)
		continue
	if n % m == 0:
		print(n)
		continue
	ans = n // m * m
	rem = n % m
	if rem < m // 2:
		ans += rem
	else:
		ans += m // 2
	print(ans)


import sys

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 18
MOD = 10 ** 9 + 7
for _ in range(INT()):
	(N, K) = MAP()
	(d, m) = divmod(N, K)
	ans = d * K + min(m, K // 2)
	print(ans)


import math
t = int(input())
for i in range(t):
	(n, k) = input().split()
	n = int(n)
	k = int(k)
	a = n // k
	maxx = math.floor(k / 2)
	left = n - a * k
	left -= maxx
	if left > 0:
		print(n - left)
	else:
		print(n)


t = int(input())
while t:
	t = t - 1
	li = map(int, input().split(' '))
	n = []
	for i in li:
		n.append(i)
	f = n[0] // n[1]
	print(f * n[1] + min(n[0] - f * n[1], n[1] // 2))


import math
test = int(input())
while test:
	(candies, kids) = map(int, input().split(' '))
	canuse = 0
	canuse = candies // kids * kids
	remaining = candies % kids
	if remaining > 0:
		floor = math.floor(kids / 2)
		if remaining <= floor:
			canuse += remaining
		else:
			canuse += floor
	print(canuse)
	test -= 1


t = int(input())

def solve(n, k):
	if n % k == 0:
		return n
	return k * (n // k) + min(n % k, k // 2)
for item in range(t):
	(n, k) = list(map(int, input().split()))
	print(solve(n, k))


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


n = int(input())
for i in range(n):
	(a, b) = input().split()
	a = int(a)
	b = int(b)
	if a % b == 0:
		print(a)
	elif a == 1:
		print(1)
	else:
		print(a - a % b + min(b // 2, a % b))


t = int(input())
while t:
	(n, k) = map(int, input().split())
	ans = 0
	z = n // k
	ans += k * z
	rem = n - ans
	ans = ans + min(rem, k // 2)
	print(ans)
	t = t - 1


from sys import stdin
from collections import defaultdict as dd
from collections import deque as dq
import itertools as it
from math import sqrt, log, log2
from fractions import Fraction
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	q = n // m * m
	left = n - q
	left = min(left, m // 2)
	print(q + left)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	g = k // 2
	r = n // k
	ans1 = g * (r + 1) + (k - g) * r
	c = 1
	if c == 1:
		p = n - r * k
		h = min(p, g)
		if ans1 <= n:
			print(ans1)
		else:
			print(h * (r + 1) + r * (k - h))


n = int(input())
lst = []
for _ in range(n):
	lst.append(list(map(int, input().split())))
for i in lst:
	a = i[0]
	k = i[1]
	yo = a % k
	yo2 = a - yo
	if yo > k // 2:
		print(yo2 + k // 2)
	else:
		print(a)


for _ in range(int(input())):
	(h, m) = map(int, input().split())
	k = h // m * m + min(m // 2, h - h // m * m)
	print(k)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	o = n // k * k
	if o < n:
		o = o + min(n - o, k // 2)
	print(o)


t = int(input())
ans = []
for i in range(t):
	(n, k) = map(int, input().split())
	a = n // k
	remain = n - k * a
	if remain < k // 2:
		ans.append(n)
	else:
		ans.append(k * a + k // 2)
for e in ans:
	print(e)


no_of_testcases = int(input())
for i in range(no_of_testcases):
	list_of_numbers = list(map(int, input().split(' ')))
	n = list_of_numbers[0]
	k = list_of_numbers[1]
	total = n // k * k
	if total == n:
		print(total)
		continue
	remainder = n % k
	largest_additive_factor = k // 2
	if remainder > largest_additive_factor:
		remainder = largest_additive_factor
	total = total + remainder
	print(total)


import math
t = int(input())
mass = []

def f(a, b):
	c = a % b
	d = math.floor(b / 2)
	e = a // b * b
	if c > d:
		return e + d
	else:
		return e + c
for i in range(t):
	(a, b) = map(int, input().split())
	mass.append(f(a, b))
for i in mass:
	print(i)


t = int(input())
for i in range(t):
	l = input()
	(n, k) = l.split(' ')
	a = int(n) // int(k)
	total = int(n) - int(k) * a
	if total >= int(k) // 2:
		print(int(k) * a + int(k) // 2)
	else:
		print(total + a * int(k))
	l = []


t = int(input())
s = []
for jnjgn in range(0, t):
	x = input()
	xx = x.split()
	n = int(xx[0])
	k = int(xx[1])
	if k > n:
		if n <= k // 2:
			s.append(n)
		else:
			s.append(int(k // 2))
	else:
		m = n % k
		if m <= k // 2:
			s.append(n)
		else:
			s.append(int(k // 2) + n - m)
for i in s:
	print(i)


for case in ' ' * int(input()):
	(a, b) = map(int, input().split())
	c = a // b
	print(c * b + min(a - c * b, b // 2))


t = int(input())
for i in range(t):
	(n, k) = [int(x) for x in input().split()]
	min_candies = n // k
	total_candies = min_candies * k
	remaining_candies = n - total_candies
	total_candies = total_candies + min(remaining_candies, k // 2)
	print(total_candies)


from math import ceil
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	x = n // k
	y = int(ceil(n / k))
	total = x * int(ceil(k / 2)) + y * (k // 2)
	print(min(n, total))


t = int(input())
for qwe in range(t):
	(n, k) = map(int, input().split())
	if n % k == 0:
		print(n)
	else:
		a = n // k
		b = a + 1
		if n % k <= k // 2:
			print(n)
		else:
			print(n - (n % k - k // 2))


for i in range(0, int(input())):
	(candies, children) = list(map(int, input().split()))
	gc = candies // children * children
	k = candies
	candies = candies - candies // children * children
	c = children // 2
	if c >= candies:
		print(k)
	else:
		print(gc + c)


testcase_num = int(input())
for i in range(testcase_num):
	(n, k) = map(int, input().split())
	if n % k == 0:
		candy_num_total = n
	else:
		candy_num_total = n // k * k
		if n % k < k // 2:
			candy_num_total = n
		else:
			candy_num_total += k // 2
	print(candy_num_total)


for _ in range(int(input())):
	(n, k) = [int(s) for s in input().split()]
	ans = n // k * k
	ans1 = n % k
	ans += min(k // 2, ans1)
	print(ans)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split(' '))
	tot = n // k * k
	modi = n % k
	if modi > k // 2:
		modi = k // 2
	print(tot + modi)


for u in range(int(input())):
	(n, m) = map(int, input().split())
	(x, y) = divmod(n, m)
	s = x * m + min(m // 2, y)
	print(s)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
mod2 = 998244353
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))

def IF(c, t, f):
	return t if c else f

def main():
	t = I()
	rr = []
	for _ in range(t):
		(n, k) = LI()
		t = n // k
		r = min(n, k * t + k // 2)
		rr.append(r)
	return JA(rr, '\n')
print(main())


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = n % m
	s = n // m
	ans = s * m
	if a > m // 2:
		a = m // 2
	print(ans + a)


t = int(input())
while t:
	(n, k) = list(map(int, input().split()))
	res = 0
	q = int(n / k)
	res = q * k
	kh = int(k / 2)
	r = int(n % k)
	if r > kh:
		res += kh
	else:
		res += r
	print(res)
	t -= 1


no_tests = int(input())
ans = []
while no_tests > 0:
	stuff = list(map(int, input().split()))
	candies = int(stuff[0])
	children = int(stuff[1])
	if candies % children > int(children / 2):
		res = candies - candies % children + int(children / 2)
	elif candies % children == 0:
		res = candies
	else:
		res = candies - candies % children + candies % children
	ans.append(res)
	no_tests -= 1
for i in range(len(ans)):
	if i == len(ans) - 1:
		print(ans[i], end='')
	else:
		print(ans[i])


for _ in range(int(input())):
	(n, k) = (int(x) for x in input().strip().split())
	a = n // k
	rem = n % k
	if rem != 0:
		if rem <= k // 2:
			print(n)
		else:
			rem = rem - k // 2
			print(n - rem)
	else:
		print(n)


for i in range(int(input())):
	(n, k) = list(map(int, input().split()))
	p = n // k
	o = k // 2
	u = n % k
	if u >= o:
		print(p * k + o)
	else:
		print(p * k + u)


a = int(input())
for i in range(a):
	(b, c) = list(map(int, input().split()))
	n = b % c
	if n > int(c / 2):
		m = int(c / 2)
		n = n - m
		b = b - n
	print(b)


t = int(input())
for z in range(t):
	(n, k) = map(int, input().split())
	x = n % k
	print(n - max(0, x - k // 2))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	div1 = n // k
	div2 = k // 2
	if (div1 + 1) * div2 + div1 * (k - div2) >= n:
		print(n)
	else:
		print((div1 + 1) * div2 + div1 * (k - div2))


q = int(input())
for i in range(q):
	s = input().split(' ')
	n = int(s[0])
	k = int(s[1])
	a = n // k
	ans = min(n, (a + 1) * (k // 2) + (k - k // 2) * a)
	print(ans)


def candies(candy, children):
	mean = children * (candy // children)
	candy -= mean
	max_child = children // 2
	if candy > 0:
		if max_child > candy:
			mean += candy
		else:
			mean += max_child
	return mean
for _ in range(int(input())):
	(candy, children) = map(int, input().split())
	print(candies(candy, children))


test = int(input())
for _ in range(test):
	(n, k) = map(int, input().split())
	m = k // 2
	d = n / k
	r = n % k
	if r > m:
		re = r - m
		print(n - re)
	else:
		print(n)


import math
t = int(input())
while t != 0:
	(n, k) = map(int, input().split())
	roundHalfK = math.floor(k / 2)
	result = 0
	if n % k == 0:
		result = n
	else:
		remainder = n % k
		if remainder > roundHalfK:
			result = n - (remainder - roundHalfK)
		else:
			result = n
	print(result)
	t -= 1


t = int(input())
for _ in range(t):
	a = input().split()
	n = int(a[0])
	k = int(a[1])
	maxplus = k // 2
	ans = n // k * k
	n = n - n // k * k
	if n > maxplus:
		ans = ans + maxplus
	else:
		ans = ans + n
	print(ans)


import sys, math

def ii():
	return int(input())

def mii():
	return map(int, input().split())

def lmii():
	return list(mii())

def main():
	for _ in range(ii()):
		(a, b) = mii()
		dv = a // b
		rm = a % b
		ans = 0
		ans = dv * b
		ans += min(rm, b // 2)
		print(ans)
main()


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n > k:
		c = n - n % k
		n = n % k
		c += min(k // 2, n)
	elif k == n:
		c = k
	else:
		c = min(n, k // 2)
	print(c)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	h = int(k / 2)
	maxm = 0
	if n <= h:
		print(n)
		continue
	elif h < n < k:
		print(h)
		continue
	else:
		maxm = k * int(n / k)
		if n - maxm <= h:
			print(n)
			continue
		else:
			print(maxm + h)


t = int(input())
s = 0
for i in range(t):
	(n, k) = map(int, input().split())
	s = n // k
	z = k * s
	print(z + min(n - z, k // 2))


import time
LOCAL = False
start_time = None
if LOCAL:
	start_time = time.time()
t = int(input())
while t > 0:
	t -= 1
	(n, k) = list(map(lambda x: int(x), input().split(' ')))
	x = int(n / k)
	minz = int(k / 2)
	print(x * k + (n - x * k if n - x * k < minz else minz))
if LOCAL:
	print('--- %s seconds ---' % (time.time() - start_time))


from bisect import bisect_left, bisect_right
from typing import List
import collections
import bisect
import itertools
import functools
from fractions import gcd
import heapq
from math import ceil, sqrt, floor
import sys
sys.setrecursionlimit(50000)
import collections
from collections import defaultdict, deque
import collections
import bisect
from collections import defaultdict, deque
import collections
t = int(input())
for _ in range(t):
	(n, k) = list(map(int, input().split()))
	ret = k * (n // k)
	ret += min(k // 2, n - ret)
	print(ret)


for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	cnt = n % k
	ans = n - cnt
	x = min(k // 2, cnt)
	print(ans + x)


import sys
import math
import bisect

def main():
	for _ in range(int(input())):
		(n, k) = map(int, input().split())
		val = n // k * k
		n = n % k
		if n <= k // 2:
			val += n
		else:
			val += k // 2
		print(val)
main()


t = int(input())
for i in range(t):
	(n, k) = tuple(map(int, input().split(' ', 2)))
	(d, m) = divmod(n, k)
	print(d * k + min(m, k // 2))


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	no = n
	n %= k
	n -= k // 2
	print(no - max(n, 0))


import sys
import math
import heapq
import collections

def inputnum():
	return int(input())

def inputnums():
	return map(int, input().split())

def inputlist():
	return list(map(int, input().split()))

def inputstring():
	return [x for x in input()]

def inputstringnum():
	return [ord(x) - ord('a') for x in input()]

def inputmatrixchar(rows):
	arr2d = [[j for j in input().strip()] for i in range(rows)]
	return arr2d

def inputmatrixint(rows):
	arr2d = []
	for _ in range(rows):
		arr2d.append([int(i) for i in input().split()])
	return arr2d
t = int(input())
for q in range(t):
	(n, k) = inputnums()
	ans = k * (n // k)
	rem = n - ans
	ans += min(rem, k // 2)
	print(ans)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	rem = n % k
	h = k // 2
	d = n // k
	sum = k * d
	if rem < h:
		print(sum + rem)
	else:
		print(sum + h)


for i in range(int(input())):
	(a, b) = map(int, input().split())
	k = b // 2
	n = a // b
	k1 = k * (n + 1)
	k1 += n * (b - k)
	print(min(a, k1))


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	res = 0
	(x, r) = (n // k, n % k)
	res = (x + 1) * min(k // 2, r) + x * (k - min(k // 2, r))
	print(res)


def ret(st):
	st = st.split(' ')
	n = int(st[0])
	k = int(st[1])
	s = k * (n // k + 1)
	stop = k * (n // k + 1) - n
	x = 0
	y = 0
	if stop == 0 or stop == k:
		return n
	else:
		y = n // k
		x = n // k + 1
	s = n
	if k // 2 < k - stop:
		s -= k - stop - k // 2
	return s
for i in range(int(input())):
	print(ret(input()))


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	t1 = n // k
	t2 = n % k
	t3 = min(t2, k // 2)
	ans = t1 * k + t3
	print(ans)


def solve():
	(n, k) = map(int, input().split())
	a = n // k
	e1 = n - a * k
	e2 = k // 2
	if e1 <= e2:
		x = a * k + e1
	else:
		x = a * k + e2
	print(x)
for i in range(int(input())):
	solve()


t = int(input())
for tt in range(t):
	nk = input().split(' ')
	n = int(nk[0])
	k = int(nk[1])
	rem = n % k
	definite = n - rem
	if rem <= int(k / 2):
		print(definite + rem)
	else:
		print(definite + int(k / 2))


t = int(input())
for i in range(t):
	l = list(map(int, input().split()))
	ans = l[0] % l[1]
	if ans > l[1] // 2:
		print(l[0] // l[1] * l[1] + l[1] // 2)
	else:
		print(l[0])


def given_candies(candies_number, kids_number):
	fair_split = candies_number // kids_number * kids_number
	left_candies = candies_number - fair_split
	unfair_split = min(left_candies, kids_number // 2)
	return fair_split + unfair_split
tests_number = int(input())
for _ in range(tests_number):
	(candies, kids) = map(int, input().split())
	result = given_candies(candies, kids)
	print(result)


for i in range(int(input())):
	(a, b) = list(map(int, input().split()))
	print(min(a // b * b + b // 2, a))


tc = int(input())
for _ in range(tc):
	(n, k) = list(map(int, input().split()))
	a = n // k
	rem = n - a * k
	if rem == 0:
		print(n)
	else:
		b = 1
		if rem <= k // 2:
			print(a * k + b * rem)
		else:
			print(a * k + b * k // 2)


from sys import stdin, stdout
t = int(stdin.readline().strip())
for _ in range(t):
	(n, k) = map(int, stdin.readline().split())
	stdout.write('{}\n'.format(n + min(0, k // 2 - n % k)))


t = int(input())
for p in range(0, t):
	(n, k) = map(int, input().split())
	total = k * (n // k)
	remain = n % k
	m = 0
	limit = k // 2
	if limit <= remain:
		m += limit
	else:
		m += remain
	print(total + m)


import math
x = list(map(int, input().split()))
n = []
d = []
for i in range(x[0]):
	n.append(list(map(int, input().split())))
for i in range(x[0]):
	nn = n[i][0]
	k = n[i][1]
	print(min(math.floor(nn / k) * k + math.floor(k / 2), nn))


w = int(input())
for _ in range(w):
	(c, s) = list(map(int, input().split()))
	n = int(c / s)
	r = c - n * s
	rs = int(s / 2)
	if r < rs:
		sol = n * s + r
	else:
		sol = n * s + rs
	print(sol)


for i in range(int(input())):
	t = input().split()
	n = int(t[0])
	k = int(t[1])
	b = n // k
	tot = b * k
	n -= b * k
	if n > k // 2:
		tot += k // 2
	else:
		tot += n
	print(tot)


q = int(input())
for z in range(q):
	(n, k) = map(int, input().split())
	x = n // k
	n -= x * k
	m = min(k // 2, n)
	print(x * k + m)


import sys
import math
from functools import reduce
import bisect

def getN():
	return int(input())

def getNM():
	return map(int, input().split())

def getList():
	return list(map(int, input().split()))

def input():
	return sys.stdin.readline().rstrip()

def index(a, x):
	i = bisect.bisect_left(a, x)
	if i != len(a) and a[i] == x:
		return i
	return False
for _ in range(int(input())):
	(n, k) = getNM()
	print(n - n % k + min(n % k, k // 2))


x = int(input())
while x > 0:
	candies = input()
	(n, k) = candies.split()
	n = int(n)
	k = int(k)
	mod = n % k
	if mod <= k // 2:
		print(n)
	else:
		print(n - mod + k // 2)
	x -= 1


t = int(input())
while t > 0:
	(a, k) = map(int, input().split())
	v = a - a // k * k
	if v > k // 2:
		print(a - v + k // 2)
	else:
		print(a)
	t -= 1


local = False
if local:
	file = open('B.txt', 'r')

def inp():
	if local:
		return file.readline().rstrip()
	else:
		return input().rstrip()

def ints():
	return [int(_) for _ in inp().split()]
t = int(inp())
for _ in range(t):
	(n, k) = ints()
	ans = 0
	candyForEachKid = n // k
	ans += candyForEachKid * k
	candyRemain = n % k
	ans += min(candyRemain, k // 2)
	print(ans)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	mod = n % k
	flr = k // 2
	if mod <= flr:
		print(n)
		continue
	n -= mod - flr
	print(n)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n % k == 0:
		print(n)
	else:
		i = n // k
		x = k // 2
		y = n % k
		if x > y:
			x = y
		print(i * k + x)


def f(l):
	(n, k) = l
	return min(n, n // k * k + (k >> 1))
t = int(input())
for _ in range(t):
	l = list(map(int, input().split()))
	print(f(l))


n = int(input())
for _ in range(n):
	(candies, kids) = map(int, input().split())
	(x, y) = divmod(candies, kids)
	ans = x * kids
	ans += min(kids / 2, y)
	print(int(ans))


t = int(input())
res = []
for _ in range(t):
	(n, k) = map(int, input().split())
	dtwo = k // 2
	eq = n // k
	if n - eq * k >= dtwo:
		res.append(eq * k + dtwo)
	else:
		res.append(n)
for i in res:
	print(i)


def sol():
	(x, y) = map(int, input().split())
	j = x % y
	d = 0
	if j > y // 2:
		d = j - y // 2
	print(x - d)
for n in range(int(input())):
	sol()


for _ in [0] * int(input()):
	(k, n) = map(int, input().split())
	answ = k // n * n
	if k - answ >= n // 2:
		answ += n // 2
	else:
		answ += k - answ
	print(answ)


import sys
from math import gcd
from heapq import heappop
from heapq import heappush
from heapq import heapify
from bisect import insort
from bisect import bisect_right
from bisect import bisect_left
from sys import stdin, stdout
from collections import defaultdict, deque
from math import log2, ceil, floor
inp = lambda : int(input())
sip = lambda : input()
mulip = lambda : map(int, input().split())
lst = lambda : list(map(int, input().split()))
slst = lambda : list(sip())
arr2d = lambda x: [[int(j) for j in input().split()] for i in range(x)]
odds = lambda l: len(list(filter(lambda x: x % 2 != 0, l)))
evens = lambda l: len(list(filter(lambda x: x % 2 == 0, l)))
mod = pow(10, 9) + 7
Judge = 0
if Judge:
	sys.stdin = open('input.in', 'r')
for _ in range(inp()):
	(n, k) = mulip()
	mx = k // 2
	a = n // k
	if n % k != 0:
		x = n % k
		if x <= mx:
			print(n)
		else:
			print(n - (x - mx))
	else:
		print(n)


for x in range(int(input())):
	(n, k) = map(int, input().split())
	mnog = k // 2
	sr = n // k
	if mnog * (sr + 1) + sr * (k - mnog) > n:
		print(n)
	else:
		print(mnog * (sr + 1) + sr * (k - mnog))


import math
t = int(input())
for i in range(0, t):
	(a, b) = list(map(int, input().split()))
	if a >= b:
		if a % b == 0:
			print(a)
		else:
			d = a % b
			c = a - d
			f = int(math.floor(b / 2))
			if d >= f:
				print(c + f)
			else:
				print(int(c + d))
	else:
		f = int(math.floor(b / 2))
		if f <= a:
			print(f)
		else:
			print(a)


for _ in range(int(input())):
	(N, K) = map(int, input().split())
	val = N // K * K + K // 2
	if N <= val:
		print(N)
	else:
		print(val)


import math
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = n // k
	n_a = k // 2 if not k % 2 else k // 2 + 1
	n_b = k - n_a
	print(min(a * n_a + (a + 1) * n_b, n))


q = int(input())
for i in range(q):
	(n, k) = [int(j) for j in input().split()]
	a = n // k
	if not k % 2:
		b = k // 2
	else:
		b = k // 2 + 1
	print(min(k // 2 * (a + 1) + b * a, n))


num = int(input())
arr = []
for i in range(num):
	arr.append(input())
arr = [[int(i) for i in c.split(' ')] for c in arr]

def getmax(c, k):
	out = int(c / k)
	maxcand = out * k
	left = c % k
	if left <= int(k / 2):
		maxcand += left
	if left > int(k / 2):
		maxcand += int(k / 2)
	return maxcand
for i in range(num):
	print(getmax(arr[i][0], arr[i][1]))


a = int(input())
for i in range(a):
	s = str(input())
	s = s.split(' ')
	d = int(s[0])
	f = int(s[1])
	if f == 0:
		print(0)
	elif d % f == 0:
		print(d)
	else:
		k = d // f
		l = d - f * k
		l -= f // 2
		if l <= 0:
			l = 0
		print(d - l)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n / k == n // k:
		print(n)
	else:
		a = n // k
		x = a * (k - k // 2) + (a + 1) * (k // 2)
		print(min(n, a * (k - k // 2) + (a + 1) * (k // 2)))


cases = int(input())
ans = []
for i in range(cases):
	inp = input()
	li = inp.split()
	n = int(li[0])
	k = int(li[1])
	rem = n % k
	if rem < k // 2:
		ans.append(n)
	else:
		ans.append(n - rem + k // 2)
for i in ans:
	print(i)


t = int(input())
k = [[] for i in range(t)]
for i in range(t):
	(a, b) = map(int, input().split())
	k[i].append(a - a % b + min(a % b, b // 2))
for i in k:
	print(*i)


import math
testCases = int(input())
for _ in range(testCases):
	(n, k) = [int(x) for x in input().split()]
	reminder = n % k
	answer = n - reminder
	answer += min(reminder, math.floor(k / 2))
	print(answer)


import math

def ans(a, b):
	count = 0
	sum = 0
	if b == 2:
		print(a)
	else:
		k = a // b * b
		sum = a % b
		k += min(sum, b // 2)
		print(k)
t = int(input())
while t > 0:
	(a, b) = map(int, input().split())
	ans(a, b)
	t -= 1


t = int(input())
q = 0
while q < t:
	(k, d) = map(int, input().split())
	print(k - k % d + min(k % d, int(d / 2)))
	q += 1


x = int(input())
for _ in range(x):
	(n, k) = map(int, input().split())
	if n % k == 0:
		print(n)
	else:
		ans = n - n % k + min(k // 2, n % k)
		print(ans)


tc = int(input())
for _ in range(tc):
	(n, k) = map(int, input().split())
	a = -1
	if n % k >= k // 2:
		a = k // 2
	else:
		a = n % k
	print(k * (n // k) + a)


t = int(input())
for i in range(t):
	(c, k) = input().split()
	(c, k) = (int(c), int(k))
	given = int(c / k) * k
	remain = c % k
	(a, b) = (given, given)
	given2 = min(int(k / 2), remain)
	print(given + given2)


for t in range(int(input())):
	(n, k) = map(int, input().split())
	c = n % k
	if c > k // 2:
		print(n // k * k + k // 2)
	else:
		print(n // k * k + n % k)


t = int(input())
import math
while t:
	t = t - 1
	(n, k) = list(map(int, input().split(' ')))
	a = math.floor(n / k)
	n = n - a * k
	if n <= math.floor(k / 2):
		print(a * k + n)
	else:
		print(a * k + math.floor(k / 2))


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	t = a // b
	s = a - t * b
	r = b // 2
	if r >= s:
		print(a)
	else:
		print(t * b + r)


i = int(input())
for j in range(i):
	(n, k) = map(int, input().split())
	avg = n // k
	rst = n - avg * k
	dvd = k // 2
	if rst > dvd:
		print(avg * k + dvd)
	else:
		print(avg * k + rst)


alph = 'abcdefghijklmnopqrstuvwxyz'
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	a = n // k
	f = n % k
	E = a * k + min(f, k // 2)
	print(E)


def solution(t):
	out = []
	for i in range(t):
		(p, q) = map(int, input().split())
		s = p - p % q
		r = min(p % q, q // 2)
		print(s + r)

def main():
	t = int(input())
	solution(t)
main()


a = int(input())
for i in range(a):
	(x, y) = map(int, input().split())
	r = x % y
	tot = x - x % y
	print(tot + min(r, y // 2))


import math
from math import ceil
from math import factorial
from collections import Counter
from operator import itemgetter
import bisect
ii = lambda : int(input())
iia = lambda : list(map(int, input().split()))
isa = lambda : list(input().split())
t = ii()
for _ in range(t):
	(c, k) = iia()
	m = c // k
	e = c % k
	if e > k // 2:
		print(m * k + k // 2)
	else:
		print(c)


t = int(input())
for _ in range(t):
	(n, k) = [int(i) for i in input().split()]
	a = n // k
	max_candies = a * (k - k // 2) + (a + 1) * (k // 2)
	print(min(n, max_candies))


for _ in range(int(input())):
	(h, m) = map(int, input().split())
	if h % m == 0:
		print(h)
	else:
		print(h // m * m + min(h - h // m * m, m // 2))


import math
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	a = math.floor(n / k)
	b = n % k
	c = min(b, math.floor(k / 2))
	print(a * k + c)


def get_ans(n, k):
	remaining = n % k
	max_number_of_kids_with_additional_candy = k // 2
	if max_number_of_kids_with_additional_candy >= remaining:
		ans = n
	else:
		ans = n - (remaining - max_number_of_kids_with_additional_candy)
	return ans
t = int(input().strip())
for i in range(t):
	(h, m) = list(map(int, input().strip().split()))
	print(get_ans(h, m))


def f(n, k):
	a = n // k
	candy = a * k
	b = n - candy
	if b > k // 2:
		candy = candy + k // 2
	else:
		candy = candy + b
	return candy
t = int(input())
for i in range(0, t):
	(n, k) = map(int, input().split())
	print(f(n, k))


n = int(input())
for _ in range(n):
	(n, k) = [int(i) for i in input().split()]
	o = n // k * k
	p = n
	n -= o
	if n <= k // 2:
		print(p)
	else:
		print(o + k // 2)


t = int(input())
for i in range(t):
	(n, k) = input().split()
	n = int(n)
	k = int(k)
	y = n % k
	while y >= k:
		y -= k
	if y <= k // 2:
		print(n)
	else:
		print(n - (y - k // 2))


import math
n = int(input())
for i in range(n):
	(n, k) = list(map(int, input().split()))
	if math.floor(k / 2) < n % k:
		a = n % k - math.floor(k / 2)
		n = n - a
	print(n)


t = int(input())
for j in range(t):
	(n, k) = map(int, input().split(' '))
	sum1 = 0
	sum1 += n // k * k
	n = n - n // k * k
	if n <= k >> 1 and n != 0:
		print(sum1 + n)
	elif n <= k >> 1 and n == 0:
		print(sum1)
	else:
		print(sum1 + (k >> 1))


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	c = n
	n -= n // k * k
	a = k // 2
	if n >= a:
		n -= a
	else:
		n = 0
	print(c - n)


import sys
T = int(input())
S = sys.stdin.read().strip().split()
for i in range(0, len(S), 2):
	(n, k) = (int(S[i]), int(S[i + 1]))
	m = n % k
	m = min((m, int(k // 2)))
	print(int(n // k) * k + m)


for tc in range(int(input())):
	(ncand, nkid) = map(int, input().split())
	res = ncand // nkid * nkid
	ncand -= res
	res += min(ncand, nkid // 2)
	print(res)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	if int(n / k) == float(n / k):
		print(n)
		continue
	a = n // k
	m_k = k // 2
	ans = k * a + m_k
	if ans > n:
		print(n)
	else:
		print(ans)


import sys

def input():
	return sys.stdin.readline().strip()
for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	ans = n // k * k
	ans += min(n % k, k // 2)
	print(ans)


n = int(input())
for i in range(n):
	(candys, num) = list(map(int, input().split()))
	has = candys // num
	sur = candys - has * num
	if sur >= num // 2:
		print(has * num + num // 2)
	else:
		print(has * num + sur)


t = int(input())
for _ in range(t):
	(x, y) = map(int, input().split())
	n = x // y
	if x % y == 0:
		print(x)
	else:
		ans = x % y
		if ans >= y // 2:
			print(x - (ans - y // 2))
		else:
			print(x)


t = int(input())
for i in range(t):
	(n, k) = [int(x) for x in input().split()]
	m1 = k * (n // k)
	m2 = n % k
	print(m1 + min(k // 2, m2))


for t in range(int(input())):
	(n, k) = list(map(int, input().split()))
	mod = n % k
	max_stud = k // 2
	diff = min(mod, max_stud)
	print(n - (mod - diff))


t = int(input())
for _ in range(t):
	(candies, students) = list(map(int, input().split()))
	n = int(candies / students)
	re = candies - n * students
	rs = int(students / 2)
	if re < rs:
		sol = n * students + re
	else:
		sol = n * students + rs
	print(sol)


import sys
input = sys.stdin.readline
Q = int(input())
Query = [list(map(int, input().split())) for _ in range(Q)]
for (n, k) in Query:
	m = n % k
	if 0 <= m <= k // 2:
		ans = n
	else:
		ans = n // k * k + k // 2
	print(ans)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = n // k
	if n % k == 0:
		print(n)
		continue
	mx = 0
	hi = k // 2 + 1
	lo = 0
	while lo < hi:
		mid = (lo + hi) // 2
		if a * k + mid <= n:
			mx = a * k + mid
			lo = mid + 1
		else:
			hi = mid
	print(mx)


for _ in range(int(input())):
	(x, y) = map(int, input().split())
	print(x - max(0, x % y - y // 2))


def func(n, k):
	if n % k == 0:
		return n
	else:
		a = n // k
		return a * k + min(n - a * k, k // 2)
t = int(input())
for _ in range(t):
	s = list(map(int, input().split()))
	(n, k) = (s[0], s[1])
	print(func(n, k))


for i in range(int(input())):
	X = list(map(int, input().split()))
	Least = X[0] // X[1]
	X[0] -= Least * X[1]
	print(Least * X[1] + min(X[1] // 2, X[0]))


N = int(input())
for i in range(N):
	ans = 0
	(n, k) = map(int, input().split())
	ans += n // k * k
	n -= n // k * k
	ans += min(n, k // 2)
	print(ans)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	(ans, rem) = divmod(n, k)
	print(ans * k + min(rem, k // 2))


import sys
from math import floor
I = sys.stdin.readline
ans = ''
for _ in range(int(I())):
	(n, k) = map(int, I().split())
	x = n // k * k
	y = x + min(floor(k / 2), n - x)
	ans += '{}\n'.format(y)
print(ans)


for _ in range(int(input())):
	(h, m) = [int(x) for x in input().split()]
	r = h % m
	t = m * (h // m)
	t += min(r, m // 2)
	print(t)


t = int(input())
while t > 0:
	(n, k) = [int(ele) for ele in input().split()]
	if n % k > int(k / 2):
		print(k * int(n / k) + int(k / 2))
	else:
		print(n)
	t -= 1


t = int(input())
while t > 0:
	(n, k) = list(map(int, input().split()))
	num = n // k
	left = n - num * k
	if left < k // 2:
		print(n)
	else:
		left = left - k // 2
		print(n - left)
	t = t - 1


t = int(input())
for test in range(0, t):
	(n, k) = map(int, input().split())
	nr = n // k
	r = n % k
	ans = nr * k + min(r, k // 2)
	print(str(ans))


import math
t = int(input())
for i in range(0, t):
	(n, k) = map(int, input().split())
	lim = math.floor(k / 2)
	x = math.floor(n / k)
	c = x * k
	rem = n - c
	if rem > lim:
		c = c + lim
	else:
		c = c + rem
	print(c)


t = int(input())
for hh in range(0, t):
	(n, k) = [int(x) for x in input().split()]
	a = n // k
	rem = n - a * k
	gvn = min(k // 2, rem)
	rem = rem - gvn
	print(n - rem)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	equal = n // k
	n -= equal * k
	count = equal * k
	k //= 2
	count += min(k, n)
	print(count)


t = int(input())
while t:
	(n, k) = map(int, input().rstrip().split(' '))
	ma = k * (n // k) + k // 2
	if n > ma:
		print(ma)
	else:
		print(n)
	t -= 1


import sys
T = int(sys.stdin.readline())
for _ in range(T):
	(n, k) = map(int, sys.stdin.readline().split())
	if n / k - n // k > 0.5:
		print(int(k * 0.5) + n // k * k)
	else:
		print(n)


for ii in range(int(input())):
	b = [int(j) for j in input().split()]
	n = b[0]
	k = b[1]
	if n >= k:
		if n % k == 0:
			print(n)
		elif n % k >= k // 2:
			print(n // k * k + k // 2)
		else:
			print(n)
	elif n > k // 2:
		print(k // 2)
	else:
		print(n)


import math
for i in range(int(input())):
	(a, b) = map(int, input().split())
	(frac, asd) = math.modf(a / b)
	if a % b == 0 or frac <= 0.5:
		print(a)
	else:
		no = int(a / b)
		no += 0.5
		print(int(b * no))


t = int(input())
while t != 0:
	t = t - 1
	(n, k) = map(int, input().split())
	(l, r) = (0, n)
	ans = 0
	while l <= r:
		mid = (l + r) // 2
		if k * mid <= n:
			ans = max(ans, min(n, k * mid + k // 2))
			l = mid + 1
		else:
			r = mid - 1
	print(ans)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n % k == 0:
		print(n)
	else:
		resto = n % k
		meio = k // 2
		if resto <= meio:
			print(n)
		else:
			print(n - resto + meio)


t = int(input())
while t:
	(n, k) = input().split(' ')
	n = int(n)
	k = int(k)
	if n == k:
		print(n)
	elif n < k:
		if n > k // 2:
			print(k // 2)
		else:
			print(n)
	elif n % k > k // 2:
		r = n // k * k + k // 2
		print(r)
	else:
		r = n // k * k + n % k
		print(r)
	t = t - 1


def check(r, g, b):
	(a, b, c) = sorted([r, g, b])
	if c - (a + b) < 2:
		return 'Yes'
	return 'No'
for j in range(int(input())):
	(n, k) = map(int, input().split())
	print(n // k * k + min(n % k, k // 2))


from math import gcd, ceil, log
from collections import Counter, deque
from heapq import heappush, heappop, heapify

def rl():
	return list(map(int, input().split()))

def arp(arr):
	return ''.join(arr)
for _ in range(int(input())):
	(n, k) = rl()
	ans = n - n % k
	ans += min(k // 2, n % k)
	print(ans)


numCases = int(input())
for i in range(numCases):
	(candies, kids) = map(int, input().split(' '))
	extraCandies = candies % kids
	if extraCandies > kids // 2:
		candies = candies - extraCandies + kids // 2
		print(candies)
	else:
		print(candies)


for i in range(int(input())):
	(n, k) = map(int, input().split())
	c = k * (n // k)
	if n >= k:
		if n - c > int(k / 2):
			print(c + int(k / 2))
		else:
			print(n)
	elif k - n <= int(k / 2):
		print(int(k / 2))
	else:
		print(n)


t = int(input())
for x in range(t):
	(n, k) = map(int, input().split())
	x = n // k
	max = x * k + k // 2
	if max <= n:
		print(max)
	else:
		print(n)


t = int(input())
out = []
for i in range(t):
	a = [int(c) for c in input().split()]
	s = a[0] // a[1]
	sd = a[0] % a[1]
	if sd <= a[1] // 2:
		out.append(a[0])
	else:
		out.append(s * a[1] + a[1] // 2)
for i in range(t):
	print(out[i])


for _ in range(int(input())):
	(m, n) = map(int, input().split())
	rem = m % n
	if rem <= n // 2:
		print(m)
	else:
		print(m - rem + n // 2)


def f(n, k):
	if n % k <= k // 2:
		return n
	else:
		return n // k * k + k // 2
t = int(input())
while t > 0:
	(n, k) = map(int, input().split())
	print(f(n, k))
	t -= 1


t = int(input())
for _ in range(t):
	(n, k) = [int(x) for x in input().split()]
	m1 = int(n / k)
	a1 = m1 * k
	res = min(n, a1 + int(k / 2))
	print(res)


t = int(input())
for _ in range(t):
	(n, k) = list(map(int, input().split()))
	x = n % k - k // 2
	if x < 0:
		x = 0
	print(n - x)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
testcases = int(input())
for j in range(testcases):
	(n, k) = map(int, input().split())
	rem = n % k
	if rem >= k // 2:
		print(n - (rem - k // 2))
	else:
		print(n)


for i in range(int(input())):
	(h, m) = map(int, input().split())
	(q, r) = divmod(h, m)
	if r > m // 2:
		print(q * m + m // 2)
	else:
		print(h)


import bisect
from sys import stdin, stdout
t = int(input())
for i in range(t):
	(n, k) = list(map(int, input().split()))
	remaining = n % k
	if remaining > k // 2:
		print(n - remaining + k // 2)
	else:
		print(n)


from fractions import Fraction
import sys
import bisect
import heapq
from math import *
from collections import Counter as counter
from itertools import combinations as comb
from itertools import permutations as permutate
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
mod = 1000000007

def inp():
	return sys.stdin.readline().strip()

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def graph(vertex):
	return [[] for i in range(0, vertex + 1)]

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for p in range(t):
		solve()

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def lcm(a, b):
	return a * b // gcd(a, b)

def solve():
	(n, k) = sep()
	if n - k * (n // k) <= k // 2:
		print(n)
	else:
		print(k * (n // k) + k // 2)
testcase(int(inp()))


import math
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	print(math.floor(a / b) * b + min(math.floor(b / 2), a % b))


def solve(n, k):
	maxAplus1 = int(k / 2)
	minCandiesPerKid = int(n / k)
	remainingCandies = n % k
	ans = minCandiesPerKid * k + min(maxAplus1, remainingCandies)
	return ans
numTestCase = int(input())
for i in range(numTestCase):
	(n, k) = map(int, input().split())
	print(solve(n, k))


t = int(input())
for q in range(t):
	(n, k) = map(int, input().split())
	rez = k * (n // k)
	n = n - rez
	if n == 0:
		print(rez)
	else:
		h = k // 2
		if n > h:
			print(rez + h)
		else:
			print(rez + n)


from collections import defaultdict as dc
import sys
import math
mod = 10 ** 9 + 7

def bs(a, x):
	i = bisect_left(a, x)
	if i != len(a):
		return i
	else:
		return len(a)

def binarysearchforsolvingeqautions(a, i, l, r):
	while 1:
		mid = (l + r) / 2
		(p, q) = force(a, mid, i)
		if abs(p - q) < 1e-13:
			return mid
		elif p > q:
			l = mid
		else:
			r = mid

def bs(a, b):
	l = a
	r = b + 1
	x = b
	ans = 0
	while l < r:
		mid = (l + r) // 2
		if x | mid > ans:
			ans = x | mid
			l = mid + 1
		else:
			r = mid
	return ans

def digit(n):
	a = []
	while n > 0:
		a.append(n % 10)
		n = n // 10
	return a

def inp():
	p = int(input())
	return p

def line():
	p = list(map(int, input().split()))
	return p
for _ in range(inp()):
	(n, k) = line()
	z = n // k
	l = z * (k - k // 2) + (z + 1) * (k // 2)
	r = z * (k - k // 2) + z * (k // 2)
	print(max(min(l, n), r))


t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	x = b // 2
	m = a // b
	print(m * b + min(a - m * b, x))


import math
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	down = math.floor(k / 2)
	cand = math.floor(n / k)
	if down * (cand + 1) + (k - down) * cand <= n:
		print(down * (cand + 1) + (k - down) * cand)
	else:
		print(n)


t = int(input())
for i in range(t):
	(n, k) = input().split()
	n = int(n)
	k = int(k)
	ave = n // k
	res = ave * k + k // 2
	if res > n:
		print(n)
	else:
		print(res)


for _ in range(int(input())):
	cnt = 0
	q = []
	(h, m) = map(int, input().split())
	te = h % m
	if h % m == 0:
		print(h)
	elif te > m // 2:
		print(h - te + m // 2)
	else:
		print(h)


m = int(input())
while m:
	a = [int(x) for x in input().split()]
	n = a[0]
	k = a[1]
	a = int(n / k)
	c = n % k
	if c > k / 2:
		c = k / 2
	print(int(a * k + c))
	m -= 1


t = int(input())
for i in range(t):
	(k, n) = [int(j) for j in input().split()]
	a = k // n
	r = k % n
	print(a * n + min(r, n // 2))


s = int(input())
for _ in range(0, s):
	(n, k) = [int(u) for u in input().split()]
	val = k // 2
	val2 = n % k
	final_ans = n // k * k + min(n % k, k // 2)
	print(final_ans)


t = int(input())
for p in range(t):
	(n, k) = map(int, input().split())
	nor = int(n / k)
	e = int(k / 2)
	c = nor * k
	amt = n - c
	a = min(e, amt)
	print(c + a)


t = int(input())
for _ in range(t):
	(n, k) = [int(x) for x in input().split()]
	tot = n // k * k
	n %= k
	tot += min(k // 2, n)
	print(tot)


for i in range(int(input())):
	(c, k) = map(int, input().split())
	m = c % k
	if m == 0:
		print(c)
	elif k // 2 > m:
		print(c)
	else:
		print(k * (c // k) + k // 2)


t = int(input())
for i in range(t):
	dados = input().split()
	div_int = int(dados[0]) // int(dados[1])
	limi = int(dados[1]) // 2
	rest = int(dados[0]) - div_int * int(dados[1])
	if rest >= limi:
		mult = int(dados[1]) * div_int + limi
	else:
		mult = int(dados[1]) * div_int + rest
	print(mult)


t = int(input())
for _ in range(t):
	ans = 0
	(c, k) = map(int, input().split())
	if c % k <= k // 2:
		ans = c // k * k + c % k
	else:
		ans = c // k * k + k // 2
	print(ans)


from math import sqrt, gcd, ceil
from collections import deque

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().split())

def li():
	return list(mi())
t = ii()
while t:
	t -= 1
	(n, k) = mi()
	s = n // k * k
	n -= n // k * k
	s += min(n, k // 2)
	print(s)


import math
elem = int(input())
for x in range(elem):
	ar = []
	for i in input().split(' '):
		ar.append(int(i))
	a = math.floor(ar[0] / ar[1])
	b = a + 1
	left = ar[0] - ar[1] * a
	maxCan = math.floor(ar[1] / 2)
	if maxCan > left:
		maxCan = left
	print(ar[0] - left + maxCan)


for i in range(int(input())):
	(a, b) = map(int, input().split())
	tot = a // b * b
	rem = a - tot
	r = b // 2
	if rem >= b // 2:
		tot += b // 2
	else:
		tot += rem
	print(tot)


l = []
for i in range(int(input())):
	(t, k) = map(int, input().split())
	a = t - t % k
	l.append(a + min(t % k, k // 2))
print(*l, sep='\n')


from sys import stdin
t = int(stdin.readline())
for i in range(t):
	(n, k) = (int(x) for x in stdin.readline().split())
	if k == 0:
		print(0)
		continue
	print(n // k * k + min(n % k, k // 2))


def inp(dtype=str, strip=True):
	s = input()
	res = [dtype(p) for p in s.split()]
	res = res[0] if len(res) == 1 and strip else res
	return res

def problem1():
	t = inp(int)
	for _ in range(t):
		(h, m) = inp(int)
		print((23 - h) * 60 + (60 - m))

def problem2():
	t = inp(int)
	for _ in range(t):
		(n, k) = inp(int)
		res = n // k * k + min(n % k, k // 2)
		print(res)

def problem3():
	pass

def problem4():
	pass

def problem5():
	pass
problem2()


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	t = n // k
	r = n % k
	rem = k // 2
	print(t * k + min(r, rem))


from sys import stdin, stdout
import bisect

def st():
	return list(stdin.readline().strip())

def inp():
	return int(stdin.readline())

def li():
	return list(map(int, stdin.readline().split()))

def mp():
	return map(int, stdin.readline().split())

def pr(n):
	stdout.write(str(n) + '\n')

def soe(limit):
	l = [1] * (limit + 1)
	prime = []
	for i in range(2, limit + 1):
		if l[i]:
			for j in range(i * i, limit + 1, i):
				l[j] = 0
	for i in range(2, limit + 1):
		if l[i]:
			prime.append(i)
	return prime

def segsoe(low, high):
	limit = int(high ** 0.5) + 1
	prime = soe(limit)
	n = high - low + 1
	l = [0] * (n + 1)
	for i in range(len(prime)):
		lowlimit = low // prime[i] * prime[i]
		if lowlimit < low:
			lowlimit += prime[i]
		if lowlimit == prime[i]:
			lowlimit += prime[i]
		for j in range(lowlimit, high + 1, prime[i]):
			l[j - low] = 1
	for i in range(low, high + 1):
		if not l[i - low]:
			if i != 1:
				print(i)

def power(a, n):
	r = 1
	while n:
		if n & 1:
			r = r * a
			n = n - 1
		else:
			a = a * a
			n = n >> 1
	return r

def solve():
	(n, k) = mp()
	a = n - n % k
	a += min(n % k, k // 2)
	print(a)
for _ in range(inp()):
	solve()


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	maxx = 0
	if n % k == 0:
		print(n)
	else:
		a = n // k
		n = n - k * a
		print(min(k // 2, n) + k * a)


t = int(input())
all = [str(input()) for i in range(0, t)]
for i in range(0, len(all)):
	candies = int(all[i].split(' ')[0])
	children = int(all[i].split(' ')[1])
	a = candies // children
	answer_cher = a * children
	answer = answer_cher + min(candies % children, children // 2)
	print(answer)


from math import floor
a = input()
a = int(a)
candies = []
for i in range(a):
	b = input()
	candies.append(b.split())
	for j in range(len(candies[i])):
		candies[i][j] = int(candies[i][j])
	print(int(min(floor(candies[i][0] / candies[i][1]) * candies[i][1] + floor(candies[i][1]) / 2, candies[i][0])))


t = int(input())
for case in range(t):
	(n, k) = list(map(int, input().split()))
	ans = n // k * k
	n -= k * (n // k)
	ans += min(k // 2, n)
	print(ans)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	y = n % k
	if y == 0:
		print(n)
	else:
		c = n // k
		m = min(n - k * c, k // 2)
		print(k * c + m)


from sys import stdin, stdout
import math
from itertools import permutations, combinations
from collections import defaultdict
from bisect import bisect_left

def L():
	return list(map(int, stdin.readline().split()))

def In():
	return map(int, stdin.readline().split())

def I():
	return int(stdin.readline())
P = 1000000007
for t in range(I()):
	(n, k) = In()
	if n % k == 0:
		mi = n
	else:
		mi = n // k * k + k // 2
		if mi > n:
			mi = n
	print(mi)


from math import *
from collections import *
import sys
sys.setrecursionlimit(10 ** 9)
t = int(input())
for y in range(t):
	(n, k) = map(int, input().split())
	print(min(n, n // k * k + k // 2))


n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	s = a // b * b
	k = a % b
	if k > b / 2:
		k = b // 2
	s += k
	print(s)


for i in range(int(input())):
	(a, b) = list(map(int, input().split()))
	if a % b == 0:
		print(a // b * b)
	else:
		print(min(a, a // b * b + b // 2))


import os
import sys
debug = True
if debug and os.path.exists('input.in'):
	input = open('input.in', 'r').readline
else:
	debug = False
	input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return s[:len(s) - 1]

def invr():
	return map(int, input().split())
test_count = inp()
for t in range(test_count):
	if debug:
		print('Test Case #', t + 1)
	(n, k) = invr()
	m = n // k
	k2 = k // 2
	print(min(n, k * m + k2))


num_of_q = int(input())
for i in range(num_of_q):
	(n, k) = [int(i) for i in input().split()]
	ans = n
	ext = n % k
	if ext > k // 2:
		ans -= ext - k // 2
	print(ans)


t = int(input())
for w in range(t):
	a = input().split(' ')
	n = int(a[0])
	k = int(a[1])
	c = n // k * k
	n -= c
	if n <= k // 2:
		print(n + c)
	else:
		print(c + k // 2)


def sweets(n, k):
	a = n // k
	if n - a * k <= k // 2:
		kb = n - a * k
	else:
		kb = k // 2
	return a * k + kb
t = int(input())
for i in range(t):
	(n, k) = [int(s) for s in input().split()]
	print(sweets(n, k))


for i in range(int(input())):
	(n, m) = [int(i) for i in input().split()]
	if n % m == 0:
		print(n)
	else:
		k = n // m
		less = (m + 1) // 2
		ans = k * less + (k + 1) * (m - less)
		print(min(ans, n))


import math
t = int(input())
arr = []
for _ in range(t):
	arr.append(list(map(int, input().strip().split())))
for i in range(t):
	[n, k] = arr[i]
	print(n // k * k + min(n % k, math.floor(k / 2)))


for iter in range(int(input())):
	(candy, childrens) = list(map(int, input().split()))
	norma = candy // childrens * childrens
	dop = childrens // 2
	if dop + norma >= candy:
		print(candy)
	else:
		print(dop + norma)


for i in range(int(input())):
	(h, m) = map(int, input().split())
	t = h // m * m
	if h - t > m // 2:
		print(t + m // 2)
	else:
		print(h)


ntc = int(input())
for i in range(ntc):
	hh = list(map(int, input().split(' ')))
	candies = hh[0]
	k = hh[1]
	tot = 0
	tot += candies // k * k
	candies -= tot
	tot += min(k // 2, candies)
	print(tot)


for testcase in range(int(input())):
	(n, k) = list(map(int, input().split()))
	equal_candies = n // k
	candies_left = n % k
	if candies_left < k // 2:
		print(equal_candies * k + candies_left)
	else:
		print(equal_candies * k + k // 2)


t = int(input())
cnt = 0
for i in range(10000):
	cnt += 5
for _ in range(t):
	(n, k) = map(int, input().split())
	ans = n // k * k
	z = n - n // k * k
	ans += min(k // 2, z)
	print(ans)


import math
N = int(input())
for i in range(N):
	(n, k) = map(int, input().split())
	first_dist = math.floor(n / k)
	rem = n % k
	print(k * first_dist + min(rem, math.floor(k / 2)))