651 B | 623 chars
import sys
from math import sqrt, pi, sin, factorial, ceil, floor
from datetime import datetime, timedelta
# sys.setrecursionlimit(10**7)
BLANK = " "
# inp = input
inp = lambda : sys.stdin.readline().rstrip()
mii = lambda x = BLANK : [*map(int,inp().split(x))]
mfi = lambda x = BLANK : [*map(float,inp().split(x))]
ii = lambda : int(inp())
fi = lambda : float(inp())
p = print
def solve():
n, k = mii()
# k명 k명 k명 n % k명
# -> n // k 개의 그룹
# -> n // k 만큼 줄어든다.
if n < k:
p(n)
else:
p(k - 1)
if __name__ == "__main__":
tc = ii()
for t in range(1, tc+1):
ret = solve()