The game of Berland poker is played with a deck of $n$ cards, $m$ of which are jokers. $k$ players play this game ($n$ is divisible by $k$).

At the beginning of the game, each player takes $\frac{n}{k}$ cards from the deck (so each card is taken by exactly one player). The player who has the maximum number of jokers is the winner, and he gets the number of points equal to $x - y$, where $x$ is the number of jokers in the winner's hand, and $y$ is the maximum number of jokers among all other players. If there are two or more players with maximum number of jokers, all of them are winners and they get $0$ points.

Here are some examples:  $n = 8$, $m = 3$, $k = 2$. If one player gets $3$ jokers and $1$ plain card, and another player gets $0$ jokers and $4$ plain cards, then the first player is the winner and gets $3 - 0 = 3$ points;  $n = 4$, $m = 2$, $k = 4$. Two players get plain cards, and the other two players get jokers, so both of them are winners and get $0$ points;  $n = 9$, $m = 6$, $k = 3$. If the first player gets $3$ jokers, the second player gets $1$ joker and $2$ plain cards, and the third player gets $2$ jokers and $1$ plain card, then the first player is the winner, and he gets $3 - 2 = 1$ point;  $n = 42$, $m = 0$, $k = 7$. Since there are no jokers, everyone gets $0$ jokers, everyone is a winner, and everyone gets $0$ points. 

Given $n$, $m$ and $k$, calculate the maximum number of points a player can get for winning the game.


-----Input-----

The first line of the input contains one integer $t$ ($1 \le t \le 500$) — the number of test cases.

Then the test cases follow. Each test case contains three integers $n$, $m$ and $k$ ($2 \le n \le 50$, $0 \le m \le n$, $2 \le k \le n$, $k$ is a divisors of $n$).


-----Output-----

For each test case, print one integer — the maximum number of points a player can get for winning the game.


-----Example-----
Input
4
8 3 2
4 2 4
9 6 3
42 0 7

Output
3
0
1
0



-----Note-----

Test cases of the example are described in the statement.

Source: codeforces | Difficulty: EASY
Tags: Complete search

Mathematics

Greedy algorithms


Solutions:
import math
t = int(input())
while t > 0:
	inp = input()
	q = list(map(int, inp.split(' ')))
	n = q[0]
	m = q[1]
	k = q[2]
	cards_on_one = n // k
	if cards_on_one >= m:
		print(m)
	else:
		winnerJ = cards_on_one
		jokers = m - winnerJ
		oJ = jokers // (k - 1)
		if jokers % (k - 1) == 0:
			print(winnerJ - oJ)
		else:
			print(winnerJ - oJ - 1)
	t -= 1


import sys
buff_readline = sys.stdin.readline
readline = sys.stdin.readline
INF = 2 ** 62 - 1

def read_int():
	return int(buff_readline())

def read_int_n():
	return list(map(int, buff_readline().split()))

def read_float():
	return float(buff_readline())

def read_float_n():
	return list(map(float, buff_readline().split()))

def read_str():
	return readline().strip()

def read_str_n():
	return readline().strip().split()

def error_print(*args):
	print(*args, file=sys.stderr)

def mt(f):
	import time

	def wrap(*args, **kwargs):
		s = time.time()
		ret = f(*args, **kwargs)
		e = time.time()
		error_print(e - s, 'sec')
		return ret
	return wrap

def slv(N, M, K):
	p0 = min(N // K, M)
	M -= p0
	p = [0] * (K - 1)
	for i in range(M):
		p[i % (K - 1)] += 1
	if p[0] == p0:
		return 0
	return max(0, p0 - p[0])

def main():
	T = read_int()
	for _ in range(T):
		(N, M, K) = read_int_n()
		print(slv(N, M, K))
main()


test = int(input())
for _ in range(test):
	(n, m, k) = map(int, input().split())
	pp = n // k
	if m <= pp:
		print(m)
	else:
		left = m - pp
		if left % (k - 1):
			maxi = left // (k - 1) + 1
		else:
			maxi = left // (k - 1)
		print(pp - maxi)


import math
t = int(input())
for j in range(t):
	(n, m, k) = map(int, input().split())
	if n // k >= m:
		print(m)
	else:
		diff = m - n // k
		d = k - 1
		ans = n // k - math.ceil(diff / d)
		print(ans)


import math
t = int(input())
for _ in range(t):
	(n, m, k) = map(int, input().split())
	cards = n // k
	if m <= cards:
		print(m)
	else:
		remcard = m - cards
		to_each = math.ceil(remcard / (k - 1))
		print(cards - to_each)


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


from math import ceil
for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	hand = n // k
	winj = min(m, hand)
	leftj = m - winj
	mx = ceil(leftj / (k - 1))
	print(winj - mx)


for t in range(int(input())):
	(n, m, k) = map(int, input().split())
	card = n // k
	if m == 0:
		print(0)
	elif card >= m:
		print(m)
	else:
		rem = m - card
		maxi = rem // (k - 1)
		if rem % (k - 1):
			maxi += 1
		print(card - maxi)


import math
t = int(input())
for i in range(t):
	(n, m, k) = map(int, input().split(' '))
	c = int(n / k)
	if m <= c:
		print(m)
	elif m > c:
		v = int(math.ceil((m - c) / (k - 1)))
		if v == c:
			print('0')
		else:
			print(c - v)


t = int(input())
r = []

def init(a):
	for l in range(len(a)):
		a[l] = int(a[l])
	return a
for i in range(t):
	(n, m, k) = input().split()
	n = int(n)
	m = int(m)
	k = int(k)
	a = []
	cnt = 0
	if m == 0:
		r.append(0)
	elif n / k >= m:
		r.append(m)
	elif n / k < m:
		p = m - n / k
		while p > 0:
			p = p - (k - 1)
			cnt = cnt + 1
		r.append(int(n / k) - cnt)
for k in range(t):
	print(r[k])


from math import ceil

def calcScore(cards, jokers, players):
	cards_pp = cards // players
	player1_jokers = min(jokers, cards_pp)
	remaining_jokers = jokers - player1_jokers
	player2_jokers = ceil(remaining_jokers / (players - 1))
	return player1_jokers - player2_jokers

def solve():
	t = int(input())
	for i in range(t):
		(cards, jokers, players) = [int(x) for x in input().split()]
		print(calcScore(cards, jokers, players))
solve()


import sys
import math
import collections
from sys import stdin, stdout, setrecursionlimit
import bisect as bs
setrecursionlimit(2 ** 20)
M = 10 ** 9 + 7
T = int(stdin.readline())
for _ in range(T):
	(n, m, k) = list(map(int, stdin.readline().split()))
	e = n // k
	if m <= e:
		print(m)
		continue
	ex = (m - e) // (k - 1) + (1 if (m - e) % (k - 1) != 0 else 0)
	print(e - ex)


import math
num = int(input())
for i in range(num):
	inp = input().split()
	inp = [int(i) for i in inp]
	(n, m, k) = inp
	c = n // k
	if c > m:
		print(m)
	else:
		winner = c
		remain_jokers = m - c
		remain_players = k - 1
		second = int(math.ceil(remain_jokers / remain_players))
		print(winner - second)


t = int(input())
i = 0
while i < t:
	(n, m, k) = map(int, input().split())
	if m == 0:
		print(0)
	else:
		a = n // k
		b = a
		if b >= m:
			print(m)
		else:
			re = b
			q = m - b
			r1 = q // (k - 1)
			if q % (k - 1) != 0:
				r1 = r1 + 1
			print(re - r1)
	i = i + 1


import sys
input = sys.stdin.buffer.readline

def solution():
	for _ in range(int(input())):
		z = 0
		(n, m, k) = map(int, input().split())
		dis = n // k
		first = min(dis, m)
		m1 = m - first
		others = k - 1
		second = m1 // others
		if m1 % others != 0:
			second += 1
		ans = first - second
		print(ans)
solution()


import math
test = int(input())
for tes in range(test):
	(n, m, k) = list(map(int, input().split()))
	num = n // k
	fi = min(m, num)
	left = m - fi
	dist = left // (k - 1)
	if left % (k - 1) != 0:
		dist += 1
	print(abs(fi - dist))


t = int(input())
for x in range(t):
	(n, m, k) = map(int, input().split())
	c = n // k
	if m == 0:
		print('0')
	elif k == 1 and m > 1:
		print('0')
	elif m <= c:
		print(m)
	else:
		temp = 0
		m1 = m - c
		k1 = k - 1
		while m1 > 0:
			temp += 1
			m1 = m1 - k1
		print(c - temp)


from math import ceil

def main():
	for _ in range(int(input())):
		(n, j, k) = map(int, input().split())
		c = n // k
		if c >= j:
			print(j)
		else:
			print(c - ceil((j - c) / (k - 1)))
main()


n = int(input())
for i in range(n):
	(n, m, k) = input().split()
	n = int(n)
	m = int(m)
	k = int(k)
	cardsperplayer = n / k
	if cardsperplayer >= m:
		print(m)
	else:
		a = m - cardsperplayer
		b = k - 1
		ceil = -(-a // b)
		x = cardsperplayer - ceil
		print(int(x))


t = int(input())
for _ in range(t):
	(n, m, k) = map(int, input().split())
	eg = n // k
	left = m - eg
	if m == 0:
		print('0')
	elif m == 1:
		print('1')
	elif m <= eg:
		print(m)
	else:
		ll = int(left % (k - 1))
		if ll == 0:
			print(eg - int(left // (k - 1)))
		else:
			lee = int(left // (k - 1)) + 1
			print(eg - lee)


import sys
from collections import defaultdict as dd
from collections import deque

def eprint(*args):
	print(*args, file=sys.stderr)
zz = 1
from math import *
import copy
if zz:
	input = sys.stdin.readline
else:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('all.txt', 'w')

def li():
	return [int(x) for x in input().split()]

def fi():
	return int(input())

def si():
	return list(input().rstrip())

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

def bo(i):
	return ord(i) - ord('a')
t = 1

def intersect(a, b):
	(a, b) = (min(a, b), max(a, b))
	if a[0] <= b[0] <= a[1]:
		return True
	return False
t = fi()
while t > 0:
	t -= 1
	(n, m, k) = mi()
	z = int(ceil((m - min(n // k, m)) / (k - 1)))
	print(min(n // k, m) - z)


t = int(input())
for _ in range(t):
	(n, m, k) = [int(x) for x in input().split()]
	max_jokers = n // k
	if m < max_jokers:
		print(m)
	else:
		rem_jokers = m - max_jokers
		max_of_rem_jokers = 0
		if k > 1:
			max_of_rem_jokers = rem_jokers // (k - 1)
			if rem_jokers % (k - 1):
				max_of_rem_jokers += 1
		print(max_jokers - max_of_rem_jokers)


def read_int():
	return int(input())

def read_ints():
	return map(int, input().split(' '))
t = read_int()
for case_num in range(t):
	(n, m, k) = read_ints()
	hi = min(m, n // k)
	rest = (m - hi - 1) // (k - 1) + 1
	print(hi - rest)


import math
t = int(input())
for _ in range(t):
	(n, m, k) = [int(x) for x in input().split()]
	p = n // k
	l = []
	if m == p or m == 0:
		print(m)
	elif m > p:
		f = p
		m -= p
		r = k - 1
		w = math.ceil(m / r)
		print(f - w)
	else:
		print(m)


import math
el = int(input())
for k in range(el):
	ar = []
	for i in input().split(' '):
		ar.append(int(i))
	cards = ar[0] / ar[2]
	if cards >= ar[1]:
		print(int(ar[1]))
	else:
		temp = ar[1] - cards
		qwe = int(math.ceil(temp / (ar[2] - 1)))
		print(int(cards - qwe))


import math
t = int(input())
while t:
	(n, m, k) = map(int, input().split())
	if n // k >= m:
		print(m)
	else:
		get = n // k
		rem = m - get
		other = [rem // (k - 1)] * (k - 1)
		rem -= sum(other)
		i = 0
		while rem > 0:
			other[i] += 1
			rem -= 1
			i += 1
		get -= max(other)
		print(get)
	t -= 1


from collections import defaultdict
import sys, math
f = None
try:
	f = open('q1.input', 'r')
except IOError:
	f = sys.stdin
if 'xrange' in dir(__builtins__):
	range = xrange
sys.setrecursionlimit(10 ** 6)

def print_case_iterable(case_num, iterable):
	print('Case #{}: {}'.format(case_num, ' '.join(map(str, iterable))))

def print_case_number(case_num, iterable):
	print('Case #{}: {}'.format(case_num, iterable))

def print_iterable(A):
	print(' '.join(A))

def read_int():
	return int(f.readline().strip())

def read_int_array():
	return [int(x) for x in f.readline().strip().split(' ')]

def rns():
	a = [x for x in f.readline().split(' ')]
	return (int(a[0]), a[1].strip())

def read_string():
	return list(f.readline().strip())

def bi(x):
	return bin(x)[2:]
from collections import deque
import math

def solution(n, m, k):
	if n // k >= m:
		return m
	rest = m - n // k
	return n // k - round(math.ceil(rest / (k - 1)))

def main():
	T = read_int()
	for i in range(T):
		(n, m, k) = read_int_array()
		x = solution(n, m, k)
		if 'xrange' not in dir(__builtins__):
			print(x)
		else:
			(print >> output, str(x))
	if 'xrange' in dir(__builtins__):
		print(output.getvalue())
		output.close()
if 'xrange' in dir(__builtins__):
	import cStringIO
	output = cStringIO.StringIO()
main()


from math import ceil
for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	each = n // k
	if each > m:
		print(m)
	else:
		k = k - 1
		m = m - each
		print(each - ceil(m / k))


import math
test = int(input())
for x in range(test):
	(n, m, k) = map(int, input().split())
	if m == 0:
		print(0)
	elif n // k >= m:
		print(m)
	elif n // k < m:
		x = n // k
		a = m - n // k
		k -= 1
		y = math.ceil(a / k)
		if x == y:
			print(0)
		else:
			print(x - y)


import math
for _ in range(int(input())):
	a = input().split(' ')
	n = int(a[0])
	m = int(a[1])
	k = int(a[2])
	val = n // k
	if val < m:
		ans = max(0, val - math.ceil((m - val) / (k - 1)))
	else:
		ans = m
	print(ans)


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


import math
n = int(input())

def solve():
	(n, m, k) = map(int, input().split())
	initial = n // k
	if m <= initial:
		return m
	else:
		currMax = initial
		second = math.ceil((m - initial) / (k - 1))
		if second >= currMax:
			return 0
		else:
			return currMax - second
for i in range(n):
	print(solve())


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


for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	c = n // k
	if c >= m:
		print(m)
	else:
		l = m - c
		x = l // (k - 1)
		if l % (k - 1) > 0:
			x += 1
		print(c - x)


import math
for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	if m == 0:
		print(0)
	elif m <= n // k:
		print(m)
	elif n == k:
		print(0)
	else:
		c = n // k
		print(c - math.ceil((m - c) / (k - 1)))


t = int(input())
ans = []
for i in range(t):
	(n, m, k) = map(int, input().split())
	if m <= n // k:
		ans.append(m)
	else:
		ans.append(n // k - ((m - n // k - 1) // (k - 1) + 1))
for i in ans:
	print(i)


import math
for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	each_player = n // k
	max_take = min(m, n // k)
	left = m - max_take
	other_max = math.ceil(left / (k - 1))
	print(abs(max_take - other_max))


t = int(input())
for inh in range(0, t):
	(n, m, k) = map(int, input().split())
	c = n // k
	if c >= m:
		ans = m
	else:
		j = c
		m -= j
		k -= 1
		c = m // k
		if m % k != 0:
			c += 1
		ans = j - c
	print(ans)


import math
from io import BytesIO, IOBase
import sys
import os

def Iint():
	return int(input())

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

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

def Plist(li, s=' '):
	print(s.join(map(str, li)))

def main():
	t = Iint()
	for _ in range(t):
		(n, m, k) = Imap()
		x = n // k
		if x >= m:
			print(m)
		else:
			ans = x - math.ceil((m - x) / (k - 1))
			print(ans)
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))

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


import sys
import math
import collections
isOnline = not False
istest = not False
if not isOnline:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
inp = lambda : sys.stdin.readline()
m = 10 ** 9 + 7

def nCr(n, r):
	if n - r < 0:
		return 0
	return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
testcase = 1
if istest:
	testcase = int(input())
for _ in range(testcase):
	(n, m, k) = map(int, input().split())
	c = n // k
	if c >= m:
		print(m)
		continue
	rem = m - c
	mx2 = rem // (k - 1)
	if rem % (k - 1) > 0:
		mx2 += 1
	print(max(c - mx2, 0))


t = int(input())
for i in range(t):
	(n, m, k) = map(int, input().strip().split())
	cards = n // k
	max_jokers = min(cards, m)
	jokers_left = m - max_jokers
	second_winner = jokers_left // (k - 1)
	if second_winner == jokers_left / (k - 1):
		pass
	else:
		second_winner += 1
	print(max_jokers - second_winner)


import sys
input = lambda : sys.stdin.readline().strip()
li = lambda : list(map(int, input().split()))
I = lambda : int(input())
for _ in range(I()):
	(n, m, k) = li()
	pp = n // k
	if m < pp:
		print(m)
	else:
		l = [0 for i in range(k - 1)]
		for i in range(m - pp):
			l[i % (k - 1)] += 1
		print(pp - max(l))


t = int(input())
while t:
	t = t - 1
	(n, m, k) = map(int, input().split())
	x = n // k
	if m == 0:
		print(0)
	elif x >= m:
		print(m)
	else:
		m = m - x
		k = k - 1
		if m % k == 0:
			print(x - m // k)
			continue
		y = m % k
		y = 1 + m // k
		print(x - y)


for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	if n // k >= m:
		print(m)
		continue
	else:
		m -= n // k
		maxCount = 0
		k -= 1
		while m != 0:
			if m >= k:
				m -= k
				maxCount += 1
			else:
				maxCount += 1
				break
	print(n // (k + 1) - maxCount)


t = int(input())
l = list()
for i in range(t):
	p = list(map(int, input().split()))
	l.append(p)
for i in range(len(l)):
	lx = 0
	x = l[i]
	if x[1] == 0:
		print(0)
		continue
	y = int(x[0] / x[2])
	z = int(x[1] - y)
	if y >= x[1]:
		print(x[1])
		continue
	else:
		lx = int(z / (x[2] - 1))
		if z % (x[2] - 1) != 0:
			lx = lx + 1
			lx = y - lx
			print(lx)
			continue
		else:
			lx = y - lx
			print(lx)
			continue


for _ in range(int(input())):
	(n, m, k) = [int(x) for x in input().split()]
	ss = n // k
	if ss >= m:
		print(m)
	elif (m - ss) % (k - 1) == 0:
		print(ss - (m - ss) // (k - 1))
	else:
		print(ss - ((m - ss) // (k - 1) + 1))


from sys import stdin, gettrace
if not gettrace():

	def input():
		return next(stdin)[:-1]

def main():

	def solve():
		(n, m, k) = map(int, input().split())
		mj = min(m, n // k)
		mmj = (m - mj - 1) // (k - 1) + 1
		print(mj - mmj)
	q = int(input())
	for _ in range(q):
		solve()
main()


import sys, random, math
from bisect import bisect_left, bisect_right
input = sys.stdin.readline

def main():
	inf = 10 ** 20
	t = int(input())
	for _ in range(1, t + 1):
		(n, m, k) = map(int, input().split())
		each = n // k
		best = min(each, m)
		m -= min(each, m)
		sec = m // (k - 1)
		if m % (k - 1):
			sec += 1
		print(best - sec)
main()


from math import ceil
for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	if n // k == 1 and m != 1:
		print(0)
	elif n // k >= m:
		print(m)
	else:
		x = n // k
		y = ceil((m - x) / (k - 1))
		print(x - y)


import math
s = int(input())
for t in range(s):
	a = input().split(' ')
	n = int(a[0])
	m = int(a[1])
	k = int(a[2])
	hs = n / k
	if hs >= m:
		print(m)
	else:
		x = hs
		y = math.ceil((m - hs) / (k - 1))
		print(int(x - y))


import math
for i in range(int(input())):
	(n, m, k) = map(int, input().split())
	print(n // k - math.ceil((m - n // k) / (k - 1)) if n // k < m else m)


t = int(input())
while t:
	t -= 1
	(n, m, k) = map(int, input().split())
	if m == 0:
		print(0)
	else:
		s = n // k
		if m <= s:
			print(m)
		else:
			f = (m - s) // (k - 1)
			if f * (k - 1) == m - s:
				print(s - f)
			else:
				print(s - f - 1)


for _ in range(int(input())):
	(N, M, K) = map(int, input().split())
	D = N // K
	A = min(M, D)
	B = (M - A + K - 2) // (K - 1)
	print(A - B)


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(1000000)
	threading.stack_size(1024000)
	thread = threading.Thread(target=main)
	thread.start()
import sys
input = sys.stdin.readline
scanner = lambda : int(input())
string = lambda : input().rstrip()
get_list = lambda : list(read())
read = lambda : map(int, input().split())
get_float = lambda : map(float, input().split())

def ceil(x):
	if x != int(x):
		x = int(x) + 1
	return x

def factorial(x, m):
	val = 1
	while x > 0:
		val = val * x % m
		x -= 1
	return val

def fact(x):
	val = 1
	while x > 0:
		val *= x
		x -= 1
	return val

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

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

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

def is_integer(n):
	return math.ceil(n) == math.floor(n)

def nCr(n, k):
	if k > n:
		return 0
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

def primefs(n):
	primes = {}
	while n % 2 == 0 and n > 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0 and n > 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

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

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	(prime[0], prime[1]) = (False, False)
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime

def phi(n):
	result = n
	p = 2
	while p * p <= n:
		if n % p == 0:
			while n % p == 0:
				n = n // p
			result = result * (1.0 - 1.0 / float(p))
		p = p + 1
	if n > 1:
		result = result * (1.0 - 1.0 / float(n))
	return int(result)

def is_prime(n):
	if n == 0:
		return False
	if n == 1:
		return True
	for i in range(2, int(n ** (1 / 2)) + 1):
		if not n % i:
			return False
	return True

def next_prime(n, primes):
	while primes[n] != True:
		n += 1
	return n
MAXN = int(100000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i
spf = [0 for i in range(MAXN)]

def factoriazation(x):
	res = []
	for i in range(2, int(x ** 0.5) + 1):
		while x % i == 0:
			res.append(i)
			x //= i
	if x != 1:
		res.append(x)
	return res

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

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

def float_array():
	return list(map(float, input().strip().split()))

def str_array():
	return input().strip().split()

def binary_search(low, high, w, h, n):
	while low < high:
		mid = low + (high - low) // 2
		if check(mid, w, h, n):
			low = mid + 1
		else:
			high = mid
	return low

def check(moves, n):
	val = (moves + 1) // 2
	rem = moves - val
	sol = (val + 1) * (rem + 1)
	return sol < n

def sortSecond(val):
	return val[1]
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
alphs = 'abcdefghijklmnopqrstuvwxyz'
from itertools import permutations
import math
import bisect as bis
import random
import sys
import collections as collect
import functools as fnt

def solve():
	(n, m, k) = read()
	maxjoker = min(m, n // k)
	otherjoker = math.ceil((m - maxjoker) / (k - 1))
	print(maxjoker - otherjoker)
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')
t = scanner()
for i in range(t):
	solve()


T = int(input())
for t in range(T):
	(n, m, k) = list(map(int, input().split()))
	max_jokers = min(n // k, m)
	remaining_jokers = m - max_jokers
	other_jokers = remaining_jokers // (k - 1)
	if remaining_jokers % (k - 1) != 0:
		other_jokers += 1
	res = max_jokers - other_jokers
	print(res)


import sys
input = sys.stdin.readline
from collections import *
t = int(input())
for _ in range(t):
	(n, m, k) = map(int, input().split())
	if k == 1:
		print(0)
		continue
	if n // k >= m:
		print(m)
	else:
		ma = n // k
		m -= n // k
		mi = (m + k - 2) // (k - 1)
		print(ma - mi)


from math import ceil
from sys import stdin, stdout
int_in = lambda : int(stdin.readline())
arr_in = lambda : [int(x) for x in stdin.readline().split()]
mat_in = lambda rows: [arr_in() for y in range(rows)]
str_in = lambda : stdin.readline().strip()
out = lambda o: stdout.write('{}\n'.format(o))
arr_out = lambda o: out(' '.join(map(str, o)))
bool_out = lambda o: out('YES' if o else 'NO')
tests = lambda : range(1, int_in() + 1)
case_out = lambda i, o: out('Case #{}: {}'.format(i, o))

def solve(n, m, k):
	cards_per_player = n // k
	if cards_per_player >= m:
		return m
	other_players = k - 1
	remaining_jokers = m - cards_per_player
	max_other_hand_jokers = ceil(remaining_jokers / other_players)
	return cards_per_player - max_other_hand_jokers
for i in tests():
	(n, m, k) = arr_in()
	out(solve(n, m, k))


def solve():
	(cd, y, jk) = map(int, input().split())
	if y == 0 or jk == 0:
		print(0)
		return
	perp = cd // jk
	if perp >= y:
		print(y)
		return
	p = y - perp
	v = p // (jk - 1)
	if v == perp:
		print(0)
		return
	if p % (jk - 1) != 0:
		v += 1
	print(perp - v)
for n in range(int(input())):
	solve()


t = int(input())
for _ in range(t):
	(n, m, k) = map(int, input().split())
	c = n // k
	if c >= m:
		print(m)
	else:
		m -= c
		v = m // (k - 1)
		if m % (k - 1) == 0:
			pass
		else:
			v += 1
		print(c - v)


from math import ceil as z
for _ in ' ' * int(input()):
	(a, b, c) = map(int, input().split())
	print(min(a // c, b) - z((b - min(a // c, b)) / (c - 1)))


for s in [*open(0)][1:]:
	(n, m, k) = map(int, s.split())
	l = min(m, n // k)
	print(l + (l - m) // (k - 1))


import sys
import math
import collections

def set_debug(debug_mode=False):
	if debug_mode:
		fin = open('input.txt', 'r')
		sys.stdin = fin
t = int(input())
for ti in range(1, t + 1):
	(n, m, k) = list(map(int, input().split()))
	m1 = min(m, n // k)
	if (m - m1) % (k - 1) == 0:
		m2 = (m - m1) // (k - 1)
	else:
		m2 = (m - m1) // (k - 1) + 1
	print(m1 - m2)


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


testing_mode = True
import sys, traceback
test_data = ''
final_output = ''

def input(input_format=0, multi=0):
	if multi > 0:
		return [input(input_format) for x in range(multi)]
	else:
		next_line = next(test_data, None).strip() if test_data else sys.stdin.readline()
		if input_format == 0:
			formatted_input = [next_line]
		elif input_format == 1:
			formatted_input = list(map(int, next_line.split()))
		elif input_format == 2:
			formatted_input = list(map(float, next_line.split()))
		elif input_format == 3:
			formatted_input = next_line.split()
		elif input_format == 4:
			formatted_input = (lambda x: [x[0], list(map(int, x[1:]))])(next_line.split())
		elif input_format == 5:
			formatted_input = (lambda x: [x[0], list(map(float, x[1:]))])(next_line.split())
		else:
			formatted_input = [next_line]
		return formatted_input

def log(*args):
	if testing_mode:
		print(*args)

def out(output_line, output_format=0, newline=True):
	global final_output
	formatted_output = ''
	if output_format == 0:
		formatted_output = str(output_line)
	elif output_format == 1:
		formatted_output = ' '.join(map(str, output_line))
	elif output_format == 1:
		formatted_output = '\n'.join(map(str, output_line))
	if testing_mode:
		final_output += formatted_output + '\n' * newline
	else:
		print(formatted_output, end='\n' if newline else '')
test_inputs = ['\n4\n8 3 2\n4 2 4\n9 6 3\n42 0 7\n\n', '\n$$$\n', '\n$$$\n', '\n$$$\n']
test_outputs = ['\n3\n0\n1\n0\n\n', '\n$$$\n', '\n$$$\n', '\n$$$\n']
import math

def solve():
	for z in range(input(1)[0]):
		(n, m, k) = input(1)
		d = n // k
		w = min(d, m)
		s = math.ceil((m - w) / (k - 1))
		out(w - s)
	return

def run_all(overwrite_testing=False):
	global testing_mode, final_output, test_data
	testing_mode = overwrite_testing and testing_mode
	if testing_mode:
		tests_failed = 0
		for (test_number, (test_in, test_out)) in enumerate(zip(test_inputs, test_outputs)):
			final_output = ''
			if test_in.lstrip()[:3] == '$$$':
				continue
			test_data = iter([i for i in test_in.split('\n') if i])
			print(f'Test Case #{test_number + 1}:')
			print('<' * 20)
			fail = False
			verdict = '\x1b[92m\x1b[1mPASS\x1b[0m'
			try:
				solve()
				final = final_output.rstrip('\n')
				raw_out = iter(map(str, final.split('\n'))) if final else iter(())
			except Exception:
				raw_out = ''
				fail = True
				print('\x1b[95m')
				traceback.print_exc()
				print('\x1b[0m')
			if raw_out:
				if test_out.lstrip()[:3] == '$$$':
					verdict = '\x1b[94m\x1b[1mSKIP\x1b[0m'
					print('\x1b[94m' + '\n'.join(list(raw_out)) + '\x1b[0m')
				else:
					for line_out in [i for i in test_out.split('\n') if i]:
						line_raw = next(raw_out, '% None %')
						if line_raw == line_out.strip():
							print(f'\x1b[92m{line_raw}\x1b[0m')
						else:
							print(f'\x1b[91m{line_raw}\x1b[0m')
							fail = True
					line_raw = next(raw_out, None)
					while line_raw:
						print(f'\x1b[91m{line_raw}\x1b[0m')
						line_raw = next(raw_out, None)
						fail = True
			print('>' * 20)
			if fail:
				verdict = '\x1b[91m\x1b[1mFAIL\x1b[0m'
				tests_failed += 1
			print(verdict + '\n')
		if tests_failed:
			print(f"\x1b[91m\x1b[1m{tests_failed} TEST{('S' if tests_failed > 1 else '')} FAILED!\x1b[0m")
		else:
			print(f'\x1b[92m\x1b[1mALL TESTS PASSED!\x1b[0m')
	else:
		test_data = False
		solve()
run_all(False)


t = int(input())
for i in range(t):
	(n, m, k) = list(map(int, input().split()))
	cards = n // k
	if cards >= m:
		print(m)
	else:
		jokersleft = m - n // k
		perplayer = jokersleft // (k - 1)
		diff = jokersleft - perplayer * (k - 1)
		if diff == 0:
			shigh = cards - perplayer
		else:
			shigh = cards - perplayer - 1
		print(shigh)


t = int(input())
for i in range(0, t):
	entry = input().split(' ')
	n = int(entry[0])
	m = int(entry[1])
	k = int(entry[2])
	cards_per_player = n // k
	if m == 0:
		print(0)
	elif cards_per_player >= m:
		print(m)
	else:
		jokers_left = m - cards_per_player
		max_to_others = jokers_left // (k - 1)
		if jokers_left % (k - 1) != 0:
			max_to_others += 1
		print(cards_per_player - max_to_others)


from math import ceil
for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	win = min(n // k, m)
	rem = m - win
	print(win - ceil(rem / (k - 1)))


for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	max_jok = min(n // k, m)
	m -= max_jok
	if m % (k - 1) == 0:
		print(max_jok - m // (k - 1))
	else:
		print(max_jok - (m // (k - 1) + 1))


from math import ceil
n = int(input())
for i in range(n):
	j = list(map(int, input().split()))
	if j[0] / j[2] >= j[1]:
		print(j[1])
	else:
		d = int(j[0] / j[2])
		a = ceil((j[1] - d) / (j[2] - 1))
		print(d - a)


import sys
import math
input = sys.stdin.readline
for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	c = n // k
	if c >= m:
		print(m)
	else:
		c1 = m - c
		print(c - math.ceil(c1 / (k - 1)))


import math
for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	a = n // k
	if m <= a:
		print(m)
	elif m > a:
		print(a - (m - a + k - 2) // (k - 1))


import math

def fun(n, m, k):
	points = min(m, n // k)
	remain = max(0, m - points)
	sub = math.ceil(remain / (k - 1))
	return points - sub
for _ in range(int(input())):
	(n, m, k) = list(map(int, input().split()))
	print()
	print(fun(n, m, k))


import math
for i in range(int(input())):
	a = str(input())
	a = a.split(' ')
	n = a[0]
	m = a[1]
	k = a[2]
	n = int(n)
	m = int(m)
	k = int(k)
	if n / k >= m:
		print(m)
	else:
		p = n / k
		pog = math.ceil((m - n / k) / (k - 1))
		l = int(p - pog)
		print(l)


from math import ceil

def solve(n, m, k):
	t = n // k
	if t >= m:
		return m
	elif t == 1:
		return 0
	else:
		return t - ceil((m - t) / (k - 1))
t = int(input())
ans = []
for _ in range(t):
	(n, m, k) = list(map(int, input().split()))
	res = solve(n, m, k)
	ans.append(res)
ans = list(map(str, ans))
print('\n'.join(ans))


from sys import stdin, stdout
t = int(input())
for i in range(t):
	(n, m, k) = [int(c) for c in input().split()]
	cardPerP = n // k
	if cardPerP >= m:
		print(m)
	else:
		m -= cardPerP
		k -= 1
		jokerPerP = m // k
		if m % k > 0:
			jokerPerP += 1
		ans = cardPerP - jokerPerP
		print(ans)


from math import ceil
t = int(input())
for i in range(t):
	(cards, jokers, players) = [int(i) for i in input().split()]
	if jokers <= cards / players:
		print(jokers)
	else:
		print(int(cards / players - ceil((jokers - cards / players) / (players - 1))))


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


from math import ceil
t = int(input())
for c in range(t):
	(n, m, k) = [int(x) for x in input().split()]
	if m == 0 or n == m:
		print(0)
	elif n == k and m == 1:
		print(1)
	elif n == k:
		print(0)
	else:
		ans = n // k
		if m <= ans:
			print(m)
		elif ceil((m - ans) / (k - 1)) == ans:
			print(0)
		else:
			print(ans - ceil((m - ans) / (k - 1)))


import sys
import heapq
import math

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

def iinput():
	return int(input())

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

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

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

def main():
	(n, m, k) = rinput()
	if m <= n // k:
		print(m)
	else:
		print(n // k - (m - n // k + k - 2) // (k - 1))
for i in range(iinput()):
	main()


def maxPointsWinnerGets(cards, jokers, players):
	cardsPerPlayer = cards // players
	if jokers > cardsPerPlayer:
		jokers -= cardsPerPlayer
		players -= 1
		minJokersPerPlayer = jokers // players
		if minJokersPerPlayer == 0:
			jokersOfRunnerUp = 1
		else:
			jokersOfRunnerUp = minJokersPerPlayer + (1 if minJokersPerPlayer * players < jokers else 0)
		return cardsPerPlayer - jokersOfRunnerUp
	return jokers
t = int(input())
while t:
	(cards, jokers, players) = map(int, input().split(' '))
	print(maxPointsWinnerGets(cards, jokers, players))
	t -= 1


from math import ceil

def Berland_Poker(n, m, k):
	d = int(n / k)
	if m <= d:
		score = m
	else:
		score = d - ceil((m - d) / (k - 1))
	return score
for _ in range(int(input())):
	(n, m, k) = [int(x) for x in input().split()]
	print(Berland_Poker(n, m, k))


import math as ma
t = int(input())
for _ in range(t):
	(n, m, k) = map(int, input().split())
	cp = n // k
	if m <= cp:
		print(m)
	elif ma.ceil((m - cp) / (k - 1)) > cp:
		print(0)
	else:
		print(cp - ma.ceil((m - cp) / (k - 1)))


import math
t = int(input())
if 1 <= t <= 500:
	for i in range(t):
		(n, m, k) = list(map(int, input().split(' ')))
		if 2 <= n <= 50 and 0 <= m <= n and (2 <= k <= n) and (n % k == 0):
			p = n // k
			if m == 0:
				print(m)
			elif p >= m:
				print(m)
			elif p < m:
				q = k - 1
				r = m - p
				s = r / q
				ans = p - math.ceil(s)
				print(ans)


from sys import stdin, stdout, setrecursionlimit
input = stdin.readline
for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	x = n // k
	if x > m:
		print(m)
	else:
		m -= x
		k -= 1
		x -= (k - 1 + m) // k
		print(x)


from sys import stdin
for _ in range(int(input())):
	(n, m, k) = map(int, stdin.readline().split())
	if m == 0 or (n == k and m != 1) or m >= n:
		print(0)
		continue
	else:
		if m > n // k:
			res = n // k - (m - n // k) // (k - 1) - int((m - n // k) % (k - 1) != 0)
		else:
			res = m
		print(res)


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


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')
from math import factorial, ceil
from collections import Counter, defaultdict, deque
from heapq import heapify, heappop, heappush

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

def RLL():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def N():
	return int(input())

def comb(n, m):
	return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0

def perm(n, m):
	return factorial(n) // factorial(n - m) if n >= m else 0

def mdis(x1, y1, x2, y2):
	return abs(x1 - x2) + abs(y1 - y2)
mod = 998244353
INF = float('inf')

def main():
	for _ in range(N()):
		(n, m, k) = RL()
		one = n // k
		if m <= one:
			print(m)
		else:
			print(one - ceil((m - one) / (k - 1)))
main()


import sys
input = sys.stdin.readline

def main():
	t = int(input())
	for _ in range(t):
		(N, M, K) = [int(x) for x in input().split()]
		winner = min(N // K, M)
		second = -(-(M - winner) // (K - 1))
		print(winner - second)
main()


t = int(input())
for i in range(int(t)):
	numbers = list(map(int, input().split()))
	n = numbers[0]
	m = numbers[1]
	k = numbers[2]
	if n / k >= m:
		print(m)
	else:
		jw = n / k
		jm = int((m - jw) / (k - 1))
		if (m - jw) % (k - 1) != 0:
			jm += 1
		if jm == jw:
			print(0)
		else:
			print(int(jw - jm))


for _ in range(int(input())):
	(n, m, k) = [int(i) for i in input().split()]
	one = n // k
	if m == 0:
		print(0)
		continue
	if m <= one:
		print(m)
	else:
		ostatok = m - one
		if ostatok % (k - 1) != 0:
			print(one - ostatok // (k - 1) - 1)
		else:
			print(one - ostatok // (k - 1))


import math
for _ in range(int(input())):
	(cards, jokers, players) = map(int, input().split())
	cards_per_player = cards // players
	if cards_per_player > jokers:
		print(jokers)
		continue
	jokers_left = jokers - cards_per_player
	max_jokers_on_hands = min(cards_per_player, math.ceil(jokers_left / (players - 1)))
	print(cards_per_player - max_jokers_on_hands)


from sys import stdin, stdout
import math

def solve():
	cases = int(input())
	for case in range(1, cases + 1):
		(n, m, k) = [int(n) for n in input().split()]
		a = n // k
		if m <= a:
			print('{}'.format(m))
		else:
			j = m - a
			left = math.ceil(j / (k - 1))
			print(a - left)
solve()


import sys
import math
import collections
from collections import deque
from functools import reduce
from sys import stdin, stdout, setrecursionlimit
setrecursionlimit(2 ** 20)

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

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
for _ in range(int(stdin.readline())):
	(n, m, k) = list(map(int, stdin.readline().split()))
	if m == 0:
		print(0)
	elif n / k >= m:
		print(m)
	else:
		s = m - n // k
		if s % (k - 1) > 0:
			print(n // k - (s // (k - 1) + 1))
		else:
			print(n // k - s // (k - 1))


for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	if m == 0:
		print(0)
	elif n // k >= m:
		print(m)
	elif n // k < m:
		arr = [0] * k
		arr[0] = n // k
		m -= n // k
		ctr = 1
		while m > 0:
			arr[ctr] += 1
			m -= 1
			ctr += 1
			if ctr == k:
				ctr = 1
		print(arr[0] - arr[1])


t = int(input())
for i in range(t):
	(n, m, k) = map(int, input().split())
	a1 = n // k
	if a1 > m:
		print(m)
	else:
		m -= n // k
		x = m / (k - 1)
		if int(x) != x:
			x = int(x) + 1
		print(a1 - int(x))


for t in range(int(input())):
	(n, m, k) = map(int, input().split())
	crd = n // k
	p1 = min(crd, m)
	m -= p1
	k -= 1
	ans1 = m // k + 1 if m / k > m // k else m // k
	print(p1 - ans1)


t = int(input())
for i in range(t):
	(n, m, k) = [int(el) for el in input().split()]
	if m >= n // k:
		print(n // k - ((m - n // k) // (k - 1) + ((m - n // k) % (k - 1) != 0)))
	else:
		print(m)


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
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')
read = lambda : list(map(int, input().split(' ')))

def main():
	for _ in range(int(input())):
		(n, m, k) = read()
		if m <= n // k:
			print(m)
		else:
			taken = n // k
			m -= taken
			print(taken - (m // (k - 1) + [1, 0][not m % (k - 1)]))
main()


t = int(input())
for _ in range(t):
	(n, m, k) = [int(a) for a in input().split()]
	h = n // k
	if m <= h:
		print(m)
	else:
		d = (m - h + k - 2) // (k - 1)
		print(h - d)


from math import ceil

def solve(n, m, k):
	cards = n // k
	if cards > m:
		return m
	else:
		x = m - cards
		r = ceil(x / (k - 1))
		return cards - r
t = int(input())
for test in range(1, t + 1):
	(n, m, k) = map(int, input().rstrip().split())
	result = solve(n, m, k)
	print(result)


t = int(input())
for _ in range(t):
	(totalNoOfCards, noOfJokers, noOfPeople) = map(int, input().rstrip().split())
	if noOfJokers <= totalNoOfCards // noOfPeople or noOfJokers == 0:
		print(noOfJokers)
	else:
		score = totalNoOfCards // noOfPeople
		noOfJokers -= totalNoOfCards // noOfPeople
		nextHigher = noOfJokers // (noOfPeople - 1)
		if noOfJokers % (noOfPeople - 1) != 0:
			nextHigher += 1
		score -= nextHigher
		if score < 0:
			score = 0
		print(score)


t = int(input())
while t > 0:
	t -= 1
	(n, m, k) = map(int, input().split())
	a = n // k
	p = k
	if m == 0:
		print(0)
	elif a >= m:
		print(m)
	elif n == k:
		print(0)
	else:
		m -= a
		left = p - 1
		b = m // left
		if m % left != 0:
			b += 1
		print(a - b)


import math
for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	cards = n // k
	if m == 0:
		print(0)
	elif cards == 1 and m > 1:
		print(0)
	elif n == m:
		print(0)
	elif cards >= m:
		print(m)
	else:
		rem = m - cards
		if k == 2:
			print(cards - (m - cards))
		else:
			print(max(0, cards - int(math.ceil(rem / (k - 1)))))


for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	if m == 0:
		print(m)
	elif m == n:
		print(0)
	elif m <= n // k:
		print(m)
	else:
		num = k - 1
		per = n // k
		rem = m - n // k
		if rem <= num:
			print(per - 1)
		else:
			from math import ceil
			print(per - ceil(rem / num))


from collections import deque
from collections import OrderedDict
import math
import sys
import os
from io import BytesIO
import threading
import bisect
import heapq
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')
input = sys.stdin.readline
ara = [0] * 100005
listOdd = list()

def aratosfen():
	global ara
	for i in range(2, int(math.sqrt(len(ara)))):
		if ara[i] == 0:
			for j in range(i * 2, len(ara), i):
				ara[j] = 1
	global listOdd
	for i in range(2, len(ara)):
		if ara[i] == 0:
			listOdd.append(i)
for t in range(int(input())):
	(n, m, k) = map(int, input().split())
	rW = n // k
	if rW >= m:
		print(m)
	else:
		m -= rW
		rS = m // (k - 1)
		if m % (k - 1) != 0:
			rS += 1
		print(rW - rS)


import math
t = input()
t = int(t)
for tt in range(0, t):
	(n, m, k) = input().split()
	(n, m, k) = (int(n), int(m), int(k))
	card = n / k
	if card >= m:
		print(m)
	else:
		m -= card
		print(int(card - math.ceil(m / (k - 1))))


import math

def solve(n, m, k):
	if n // k >= m:
		return m
	return n // k - math.ceil((m - n // k) / (k - 1))
t = int(input())
for _ in range(t):
	(n, m, k) = map(int, input().split())
	ans = solve(n, m, k)
	print(ans)


from sys import exit
for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	x = min(m, n // k)
	m -= x
	y = (m + (k - 1) - 1) // (k - 1)
	print(x - y)


tess = int(input())
for i in range(tess):
	(cards, joker, player) = map(int, input().split(' '))
	cards_per_person = int(cards / player)
	if joker > cards_per_person:
		joker -= cards_per_person
		highest = int(cards_per_person)
		second_highest = int(joker / (player - 1))
		mod = joker % (player - 1)
		if 0 < mod < player - 1:
			second_highest += 1
		print(highest - second_highest)
	else:
		print(joker)


from math import ceil
for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	print([[n // k - ceil((m - n // k) / (k - 1)), m], [0, 0]][m == 0 or m == n][n // k >= m])


def main():
	t = int(input())
	for __ in range(t):
		(n, m, k) = map(int, input().split())
		play = n // k
		if play >= m:
			print(m)
		else:
			if (m - play) % (k - 1) == 0:
				temp = (m - play) // (k - 1)
			else:
				temp = (m - play) // (k - 1) + 1
			print(abs(play - temp))
main()


import math
t = int(input())

def fun(n, m, k):
	ma = n / k
	if ma >= m:
		print(m)
	else:
		m -= ma
		o = math.ceil(m / (k - 1))
		print(int(ma - o))
while t:
	t -= 1
	(n, m, k) = map(int, input().split())
	fun(n, m, k)


t = int(input())
while t:
	(n, m, k) = map(int, input().split())
	ekjon = int(n / k)
	if ekjon >= m:
		print(m)
	else:
		x = int((m - ekjon) / (k - 1))
		if (m - ekjon) % (k - 1) == 0:
			print(ekjon - x)
		else:
			print(ekjon - x - 1)
	t -= 1


import bisect
import sys
import math
input = sys.stdin.readline
from collections import defaultdict

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

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

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

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

def solve(case):
	[n, m, k] = inlt()
	cards = n // k
	if m <= cards:
		return m
	return cards - math.ceil((m - cards) / (k - 1))
if len(sys.argv) > 1 and sys.argv[1].startswith('input'):
	f = open('./' + sys.argv[1], 'r')
	input = f.readline
T = inp()
for i in range(T):
	res = solve(i + 1)
	print(str(res))


def solve():
	l = list(map(int, input().rstrip().split()))
	if l[0] // l[2] >= l[1]:
		print(l[1])
	elif l[1] == 0:
		print(0)
	else:
		a = [0] * (l[2] - 1)
		n = l[1] - l[0] // l[2]
		x = l[0] // l[2]
		j = 0
		while n > 0:
			if j >= len(a):
				j = j % len(a)
			a[j] += 1
			j += 1
			n -= 1
		print(x - max(a))
test = int(input())
for i in range(test):
	solve()


T = int(input())
for t in range(T):
	(N, M, K) = map(int, input().split())
	if M == 0 or (N == M and M != 1):
		print(0)
		continue
	if M == 1:
		print(1)
		continue
	cards = int(N / K)
	if cards >= M:
		print(M)
		continue
	rem_jokers = M - cards
	if rem_jokers > K - 1:
		if rem_jokers % (K - 1) == 0:
			print(cards - int(rem_jokers / (K - 1)))
		else:
			print(cards - int(rem_jokers / (K - 1)) - 1)
	else:
		print(cards - 1)


tt = int(input())
ans = []
for t in range(tt):
	(n, m, k) = [int(i) for i in input().split()]
	cards = n // k
	if cards >= m:
		ans.append(m)
	else:
		p = m - cards
		g = cards - p // (k - 1)
		if p % (k - 1) > 0:
			g -= 1
		ans.append(g)
for aa in ans:
	print(aa)


import math
t = int(input())
for i in range(t):
	(n, m, k) = map(int, input().split())
	if n % k == 0:
		if m == 0:
			y = 0
		elif n == k:
			if m == 1:
				y = 1
			else:
				y = 0
		else:
			x = n / k
			if m <= x:
				y = m
			else:
				z = m - x
				y = int(x - math.ceil(z / (k - 1)))
	else:
		y = 0
	print(y)


t = int(input())
for i in range(t):
	(n, m, k) = map(int, input().split())
	if n / k >= m:
		print(m)
	else:
		winner = n / k
		m -= n / k
		player = 0
		p = [0] * (k - 1)
		while m > 0:
			if player > k - 2:
				player = 0
			p[player] += 1
			m -= 1
			player += 1
		print(int(winner - max(p)))


import math
cases = int(input())
for t in range(cases):
	(n, m, k) = list(map(int, input().split()))
	if m == 0:
		print(m)
	elif n // k >= m:
		print(m)
	else:
		maxj = n // k
		leftj = m - maxj
		v = math.ceil(leftj / (k - 1))
		print(maxj - v)


def solve(n, m, k):
	cards = n / k
	if m == 0:
		return 0
	if cards > m:
		return m
	maxx = (m - cards) // (k - 1)
	maxx += 1 if (m - cards) % (k - 1) != 0 else 0
	return int(cards - maxx)
t = int(input())
for _ in range(t):
	(n, m, k) = map(int, input().split())
	print(solve(n, m, k))


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


import sys
import math as mt
I = lambda : list(map(int, input().split()))
for tc in range(int(input())):
	(n, m, k) = I()
	if n == m:
		print(0)
		continue
	if n == k:
		if m == 1:
			print(1)
		else:
			print(0)
		continue
	if m == 0:
		print(0)
		continue
	x = n // k
	if m <= x:
		print(m)
		continue
	else:
		t = m - x
		temp = t // (k - 1)
		if t % (k - 1):
			temp += 1
		print(x - temp)


import math

def solve(n, m, k):
	first_pick = n / k
	x = min(m, first_pick)
	if x == m:
		return x
	left = m - x
	y = math.ceil(left / (k - 1))
	return abs(x - y)

def main():
	t = int(input())
	i = 1
	while i <= t:
		(n, m, k) = map(int, input().split())
		ans = solve(n, m, k)
		print(int(ans))
		i += 1
main()


from math import ceil
T = int(input())
for i in range(T):
	l3 = []
	(n, m, k) = map(int, input().split())
	aa = int(n / k)
	if m == 0 or (m > 1 and aa == 1):
		print(0)
	elif aa >= m:
		print(m)
	elif aa < m:
		m -= aa
		k -= 1
		if m % k == 0:
			w = m // k
			print(aa - w)
		else:
			zp = k - m % k
			pp = m // k
			for ii in range(k):
				if ii >= zp:
					l3.append(pp + 1)
				else:
					l3.append(pp)
			print(aa - max(l3))


x = int(input())
for _ in range(x):
	(n, m, k) = map(int, input().split())
	ans = 0
	if n // k >= m:
		ans = ans + m
	else:
		if (m - n // k) % (k - 1) == 0:
			h = 0
		else:
			h = 1
		ans = ans + n // k - (h + (m - n // k) // (k - 1))
	print(ans)


def compute_max_score_in_berland_poker(num_tests):
	num_tests_run = 0
	while num_tests_run < num_tests:
		game_data = input()
		game_data_list = list(map(int, game_data.split(' ')))
		num_cards = game_data_list[0]
		num_jokers = game_data_list[1]
		num_players = game_data_list[2]
		hand_size = num_cards // num_players
		if num_jokers <= hand_size:
			max_score = num_jokers
		else:
			k = 1
			while k <= hand_size:
				if num_jokers <= (num_players - 1) * k + hand_size:
					max_score = hand_size - k
					break
				k += 1
		print(max_score)
		num_tests_run += 1
num_test_cases = int(input())
compute_max_score_in_berland_poker(num_test_cases)


import itertools
import math
import random
import sys
from bisect import bisect_left, bisect_right
from collections import defaultdict, deque
from heapq import heappop, heappush
sys.setrecursionlimit(10 ** 5)
input = sys.stdin.readline
sqrt = math.sqrt

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

def LF():
	return list(map(float, input().split()))

def LI_():
	return list(map(lambda x: int(x) - 1, input().split()))

def II():
	return int(input())

def IF():
	return float(input())

def S():
	return input().rstrip()

def LS():
	return S().split()

def IR(n):
	return [II() for _ in range(n)]

def LIR(n):
	return [LI() for _ in range(n)]

def FR(n):
	return [IF() for _ in range(n)]

def LFR(n):
	return [LI() for _ in range(n)]

def LIR_(n):
	return [LI_() for _ in range(n)]

def SR(n):
	return [S() for _ in range(n)]

def LSR(n):
	return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

def solve():
	ans = []
	for i in range(II()):
		(n, m, k) = LI()
		x = min(m, n // k)
		m -= x
		if m:
			y = (m - 1) // (k - 1) + 1
		else:
			y = 0
		ans.append(x - y)
	for ai in ans:
		print(ai)
	return
solve()


t = int(input())
for i in range(t):
	(n, m, k) = map(int, input().split())
	player_cards = n // k
	max_jokers = min(m, player_cards)
	if (m - max_jokers) % (k - 1) == 0:
		next_max = (m - max_jokers) // (k - 1)
	else:
		next_max = (m - max_jokers) // (k - 1) + 1
	print(max_jokers - next_max)


import sys
input = sys.stdin.readline
Q = int(input())
Query = [list(map(int, input().split())) for _ in range(Q)]
for (n, m, k) in Query:
	p = n // k
	if p >= m:
		ans = m
	else:
		ans = max(p - (m - p + k - 2) // (k - 1), 0)
	print(ans)


from math import ceil
tests = int(input())
for _ in range(tests):
	(n, m, k) = map(int, input().split())
	f = n // k
	print(min(m, f - ceil(max(m - f, 0) / (k - 1))))


from sys import stdin
import math
a = int(stdin.readline())
for b in range(0, a):
	A = stdin.readline().split()
	n = int(A[0])
	m = int(A[1])
	k = int(A[2])
	B = min(int(n / k), m)
	C = math.ceil((m - B) / (k - 1))
	print(B - C)


import sys
q = int(input())
for i in range(q):
	(n, m, k) = [int(j) for j in sys.stdin.readline().split()]
	if n // k >= m:
		print(m)
	elif (m - n // k) % (k - 1) == 0:
		print(n // k - (m - n // k) // (k - 1))
	else:
		print(max(0, n // k - (m - n // k) // (k - 1) - 1))


from math import *
t = int(input())

def solve(n, m, k):
	mx = min(n // k, m)
	rem = m - mx
	return mx - ceil(rem / (k - 1))
for _ in range(t):
	print(solve(*map(int, input().split())))


import math as ma
t = int(input())
for _ in range(t):
	(n, m, k) = list(map(int, input().split()))
	a = n // k
	if m <= a:
		print(m)
	else:
		m = m - a
		b = k - 1
		c = ma.ceil(m / b)
		print(a - c)


T = int(input())
for t in range(T):
	(n, m, k) = [int(i) for i in input().split()]
	if m <= n // k:
		print(m)
	else:
		top = n // k
		remain = m - top
		rest = (remain + k - 2) // (k - 1)
		print(top - rest)


t = int(input())
for _ in range(t):
	(n, m, k) = list(map(int, input().split()))
	each = n // k
	Mp = min(each, m)
	m = m - Mp
	mp = -(-m // (k - 1))
	print(Mp - mp)


for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	card = n // k
	if card >= m:
		print(m)
	else:
		rem = m - card
		others = rem // (k - 1)
		if others * (k - 1) == rem:
			print(card - others)
		else:
			print(card - others - 1)


import sys
input = lambda : sys.stdin.readline().rstrip('\r\n')
for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	cp = n // k
	if m <= cp:
		print(m)
	else:
		m -= cp
		if m % (k - 1) == 0:
			print(cp - m // (k - 1))
		else:
			print(cp - 1 - m // (k - 1))


import math
for tc in range(int(input())):
	(n, m, k) = list(map(int, input().split()))
	if m == 0:
		print(0)
	elif m <= n // k:
		print(m)
	else:
		print(n // k - math.ceil((m - n // k) / (k - 1)))


import math
for _ in range(int(input())):
	(n, m, k) = [int(x) for x in input().split()]
	r = n // k
	if m <= r:
		print(m)
	else:
		print(r - math.ceil((m - r) / (k - 1)))


from sys import stdin
from math import ceil

def func():
	return
for _ in range(int(stdin.readline())):
	(n, m, k) = map(int, stdin.readline().split())
	each = n // k
	a = min(each, m)
	b = ceil((m - a) / (k - 1))
	print(a - b)


for ii in range(int(input())):
	(n, m, k) = map(int, input().split())
	x = n // k
	if m == 0:
		print(0)
	elif x >= m:
		print(m)
	else:
		y = k - 1
		z = (m - x) / y
		zz = round((m - x) / y)
		if z > zz:
			print(x - (zz + 1))
		else:
			print(x - zz)


tq = int(input())
for x in range(tq):
	(n, m, k) = list(map(int, input().split()))
	arr = [0] * k
	arr[0] = min(m, n // k)
	if m > n // k:
		m -= n // k
		i = 1
		while m > 0:
			arr[i] += 1
			i += 1
			if i == k:
				i = 1
			m -= 1
	print(arr[0] - arr[1])


import math
from sys import stdin
input = stdin.readline
for t in range(int(input())):
	(n, m, k) = map(int, input().split())
	cards = int(n / k)
	if cards >= m:
		print(m)
	elif cards == max(1, int((m - cards) / k - 1)):
		print(0)
	else:
		print(cards - max(1, math.ceil((m - cards) / (k - 1))))


a = int(input())
for i in range(0, a):
	(n, m, k) = (int(x) for x in input().split())
	c = n // k
	if m > c:
		x = c
		y = m - x
		yf = y // (k - 1)
		if yf != y / (k - 1):
			yf += 1
		print(x - yf)
	else:
		x = m
		print(m)


from math import ceil

def max_points(n: int, m: int, k: int) -> int:
	if m < n // k:
		return m
	max_jokers = n // k
	other_jokers = m - max_jokers
	one_hand_other_jokers = ceil(other_jokers / (k - 1))
	return max_jokers - one_hand_other_jokers
for i in range(int(input())):
	print(max_points(*list(map(int, input().split()))))


import sys
readline = sys.stdin.buffer.readline

def even(n):
	return 1 if n % 2 == 0 else 0
t = int(readline())
for _ in range(t):
	(n, m, k) = map(int, readline().split())
	res = n // k
	if res >= m:
		print(m)
	else:
		rest = m - res
		h = k - 1
		print(res - (rest + h - 1) // h)


test_cases = int(input())

def get_result():
	(n, m, k) = input().split(' ')
	n = int(n)
	m = int(m)
	l = n - m
	k = int(k)
	players = [0] * k
	player_index = 0
	while n > 0:
		if m > 0 and player_index == 0:
			players[player_index] += 1
			m -= 1
		elif player_index != 0:
			if l > 0:
				l -= 1
			else:
				players[player_index] += 1
				m -= 1
		else:
			l -= 1
		player_index += 1
		player_index %= k
		n -= 1
	players.sort()
	return players[-1] - players[-2]
for _ in range(test_cases):
	print(get_result())


import math
for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	if n // k >= m:
		print(m)
		continue
	if n // k < m:
		one = n // k
		two = math.ceil((m - one) / (k - 1))
		if two >= n // k:
			print(0)
			continue
		print(one - two)
		continue


import math
t = int(input())
a = [1]
for i in range(1, 30):
	a.append(a[i - 1] + i)
for u in range(t):
	(n, m, k) = list(map(int, input().split()))
	p = n // k
	w = 0
	w = min(p, m)
	m -= w
	u = math.ceil(m / (k - 1))
	print(w - u)


for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	a = n // k
	if m // a >= 1:
		b = m - a
		c = b // (k - 1)
		d = b % (k - 1)
		if d:
			c += 1
		print(a - c)
	else:
		print(m)


for z in range(int(input())):
	(n, m, k) = map(int, input().split())
	hand = n // k
	if m <= hand:
		print(m)
	else:
		print(hand - ((m - hand) // (k - 1) + int(bool((m - hand) % (k - 1)))))


testes = int(input())
for t in range(testes):
	entrada = input()
	(totalCards, totalJokers, players) = entrada.split(' ')
	if int(totalJokers) == 0:
		print(0)
		continue
	cardsPerPlayer = int(totalCards) / int(players)
	maxJokersLeft = int(totalJokers) - cardsPerPlayer
	if maxJokersLeft <= 0:
		print(totalJokers)
		continue
	else:
		print(int(cardsPerPlayer - maxJokersLeft / (int(players) - 1)))


from math import ceil
for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	p = min(m, n // k)
	m -= p
	y = ceil(m / (k - 1))
	print(p - y)


from math import ceil

def solve():
	(n, m, k) = map(int, input().split())
	slots = n // k
	max_j = m if m <= slots else slots
	jocks = m - max_j
	result = max_j - ceil(jocks / (k - 1))
	print(result)

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


import math
times = int(input())
for i in range(times):
	(n, m, k) = list(map(int, input().split()))
	div = n / k
	if div == 1 and m > 1:
		print(0)
	elif div == 1 and m == 1:
		print(1)
	elif m < div:
		print(m)
	else:
		m -= div
		r = div - math.ceil(m / (k - 1))
		print(int(r))


import sys
input = lambda : sys.stdin.readline().rstrip()
T = int(input())
for _ in range(T):
	(N, M, K) = map(int, input().split())
	D = N // K
	if M <= D:
		print(M)
	else:
		a = D
		b = (M - D + K - 2) // (K - 1)
		print(a - b)


from math import ceil
for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	cartas = n // k
	if m > cartas:
		maior = cartas
	else:
		maior = m
	sobrou = abs(m - maior)
	menor = ceil(sobrou / (k - 1))
	print(maior - menor)


import math

def main():
	for q in range(int(input())):
		(N, K, M) = map(int, input().split())
		card = N // M
		left = max(K - card, 0)
		ans = min(K, card) - left // (M - 1) - (1 if left % (M - 1) != 0 else 0)
		print(ans)
main()


t = int(input())
for _ in range(t):
	(n, m, k) = list(map(int, input().split()))
	c = n // k
	if c >= m:
		print(m)
	else:
		m -= c
		d = 0
		while m > 0:
			d += 1
			m -= k - 1
		print(c - d)


for j in range(int(input())):
	(n, m, k) = map(int, input().split())
	p = n // k
	if m <= p:
		print(m)
	else:
		m1 = m - p
		k -= 1
		max_ = m1 // k
		if m1 % k != 0:
			max_ += 1
		print(p - max_)


for i in range(int(input())):
	(n, m, k) = map(int, input().split())
	d = n // k
	x = min(m, d)
	y = (m - x + k - 2) // (k - 1)
	print(x - y)


t = int(input())
for i in range(t):
	(totalcartas, coringas, jogadores) = [int(i) for i in input().split()]
	cartasporjogador = totalcartas / jogadores
	if cartasporjogador >= coringas:
		pontuacao = coringas
	else:
		coringas = coringas - cartasporjogador
		pontosadecrescer = coringas / (jogadores - 1)
		pontuacao = int(cartasporjogador - pontosadecrescer)
	print(pontuacao)


from math import ceil
for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	m1 = m
	m = m - min(m, n // k)
	if m == 0:
		print(m1)
	elif n == k:
		print(0)
	else:
		ans = n // k - ceil(m / (k - 1))
		print(ans)


import math
t = int(input())
for _ in range(t):
	(n, m, k) = map(int, input().split())
	print(int(min(m, n / k) - max(0, math.ceil((m - n / k) / (k - 1)))))


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')
from math import gcd, ceil

def pre(s):
	n = len(s)
	pi = [0] * n
	for i in range(1, n):
		j = pi[i - 1]
		while j and s[i] != s[j]:
			j = pi[j - 1]
		if s[i] == s[j]:
			j += 1
		pi[i] = j
	return pi

def prod(a):
	ans = 1
	for each in a:
		ans = ans * each
	return ans

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

def binary(x, length=16):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y
from math import ceil
for _ in range(int(input()) if True else 1):
	(n, m, k) = map(int, input().split())
	j = min(n // k, m)
	rem = m - j
	y = ceil(rem / (k - 1))
	print(j - y)


import math
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')
import math
for i in range(int(input())):
	(n, m, k) = map(int, input().split())
	e = n // k
	ma = min(e, m)
	m -= ma
	mi = int(math.ceil(m / (k - 1)))
	print(ma - mi)


import math
test_cases = int(input())

def testCase():
	(cards, jokers, players) = [int(x) for x in input().strip().split()]
	if jokers == 0:
		print(0)
		return
	hand = cards // players
	max_jokers = jokers if jokers <= hand else hand
	other_jokers = jokers - max_jokers
	second_most_jokers = math.ceil(other_jokers / (players - 1))
	if max_jokers == second_most_jokers:
		print(0)
	else:
		print(max_jokers - second_most_jokers)
for t in range(test_cases):
	testCase()


def solve():
	(n, m, k) = map(int, input().split())
	if m == 0:
		print(0)
		return
	cards_per_pla = n // k
	if cards_per_pla >= m:
		print(m)
		return
	rem_cards = m - n // k
	x = cards_per_pla
	if rem_cards % (k - 1) == 0:
		y = rem_cards // (k - 1)
	else:
		y = rem_cards // (k - 1) + 1
	print(x - y)
try:
	for _ in range(int(input())):
		solve()
except Exception as e:
	print(e)
	pass


t = int(input())
for q in range(t):
	[n, m, k] = [int(i) for i in input().split()]
	players = [0] * (k - 1)
	if n // k > m:
		winner = m
		m = 0
	else:
		winner = n // k
		m -= n // k
	if m == 0:
		print(winner)
	else:
		i = 0
		while m != 0:
			players[i] += 1
			m -= 1
			i += 1
			if i > k - 2:
				i = 0
		print(winner - max(players))


for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	cards = n // k
	if m <= cards:
		print(m)
	else:
		a1 = cards
		m = m - cards
		l = [0] * (k - 1)
		i = 0
		while m > 0:
			l[i] += 1
			m = m - 1
			i = (i + 1) % (k - 1)
		a2 = max(l)
		print(a1 - a2)


def solution(n, m, k):
	if m == 0 or m == n:
		return 0
	x = min(n // k, m)
	y = (m - x + k - 2) // (k - 1)
	return max(0, x - y)

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


import math
t = int(input())
for tc in range(t):
	(n, m, k) = map(int, input().split(' '))
	c = n / k
	if c >= m:
		print(m)
	else:
		m -= c
		l = math.ceil(m / (k - 1))
		print(int(c - l))


from math import ceil
t = int(input())
for _ in range(t):
	(n, m, k) = map(int, input().split())
	t = n // k
	z = min(t, m)
	x = ceil((m - z) / (k - 1))
	print(z - x)


t = int(input())
for _ in range(t):
	(n, m, k) = [int(x) for x in input().split()]
	if m == 0:
		print(0)
		continue
	if m <= n // k:
		print(m)
	else:
		m -= n // k
		if m % (k - 1) == 0:
			x = m // (k - 1)
		else:
			x = m // (k - 1) + 1
		print(max(0, n // k - x))


t = int(input())
for i in range(t):
	l = list(map(int, input().strip().split()))
	n = l[0]
	m = l[1]
	k = l[2]
	cards = n // k
	if cards >= m:
		print(m)
	elif cards < m:
		m = m - cards
		k = k - 1
		if m % k == 0:
			print(cards - m // k)
		else:
			print(cards - (m // k + 1))


import math
tc = int(input())
while tc != 0:
	tc -= 1
	(n, m, k) = map(int, input().strip().split())
	c = n // k
	if c >= m:
		print(m)
	else:
		v = m - c
		x = math.ceil(v / (k - 1))
		print(c - x)


from math import ceil
for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	cards = n // k
	if m >= cards:
		x = cards
		y = ceil((m - cards) / (k - 1))
		print(x - y)
	else:
		print(m)


from heapq import *
from collections import *
import os
import sys
from io import BytesIO, IOBase
import math
ins = lambda : [int(x) for x in input()]
inp = lambda : int(input())
inps = lambda : [int(x) for x in input().split()]

def main():
	t = inp()
	for i in range(t):
		(n, m, k) = inps()
		if m == 0:
			print(0)
			continue
		plr = n // k
		mxjok = min(m, plr)
		restm = (m - mxjok + k - 2) // (k - 1)
		print(mxjok - restm)
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')
main()


from math import ceil
t = int(input())
for _ in range(t):
	(n, m, k) = map(int, input().split())
	if m == 0:
		print(0)
	elif m <= n // k:
		print(m)
	else:
		p = n // k
		ans = ceil((m - p) / (k - 1))
		if ans != p:
			print(p - ans)
		else:
			print(0)


import math

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

def multiple_input():
	return map(int, input().split())
for _ in range(int(input())):
	(n, m, k) = multiple_input()
	card = n // k
	if m <= card:
		print(m)
	else:
		a = n // k
		m -= card
		n -= n // k
		k -= 1
		temp = math.ceil(m / k)
		print(a - temp)


for i in range(int(input())):
	(n, m, k) = map(int, input().split())
	if m <= n // k:
		print(m)
		continue
	ok = k - 1
	if (m - n // k) % ok == 0:
		dr = (m - n // k) // ok
	else:
		dr = (m - n // k) // ok + 1
	print(n // k - dr)


import sys
import math
import collections
import heapq
import itertools
import operator
readline = sys.stdin.readline
IPS = lambda : readline().rstrip()
IP = lambda : int(readline().rstrip())
MP = lambda : map(int, readline().split())
LS = lambda : list(map(int, readline().split()))

def solve():
	for _ in range(IP()):
		(n, m, k) = MP()
		if m == 0:
			print(0)
		elif int(n // k) >= m:
			print(m)
		elif (m - int(n // k)) % (k - 1) == 0:
			print(int(n // k) - int((m - n // k) / (k - 1)))
		else:
			print(n // k - (int((m - n // k) / (k - 1)) + 1))
solve()


import random, math, sys
from copy import deepcopy as dc
from bisect import bisect_left, bisect_right
from collections import Counter
input = sys.stdin.readline

def solution(n, m, k):
	each = n // k
	if m <= each:
		return m
	else:
		first = each + 1 - 1
		left = m - each
		if left % (k - 1) == 0:
			return abs(each - left // (k - 1))
		else:
			return abs(each - left // (k - 1) - 1)

def input_test():
	for _ in range(int(input())):
		(n, m, k) = map(int, input().strip().split(' '))
		out = solution(n, m, k)
		print(out)

def test():
	pass
input_test()


import sys
import math

def solve(n, m, k):
	cpp = n // k
	mm = m - cpp
	if mm < 0:
		return m
	kk = k - 1
	maxJok = math.ceil(mm / kk)
	return cpp - maxJok
number_loops = input()
for _ in range(int(number_loops)):
	(n, m, k) = list(map(int, input().split()))
	print(solve(n, m, k))


t = int(input())
for tc in range(t):
	s = input().split()
	(n, m, k) = (int(s[0]), int(s[1]), int(s[2]))
	ca = n // k
	if ca >= m:
		print(m)
	elif m == n:
		print(0)
	else:
		m = m - ca
		va = k - 1
		if m % va == 0:
			print(ca - m // va)
		else:
			print(ca - (m // va + 1))


t = int(input())
for i in range(t):
	(n, m, k) = [int(i) for i in input().split()]
	t1 = min(n // k, m)
	t2 = (m - t1) // (k - 1) + (1 if (m - t1) % (k - 1) > 0 else 0)
	print(t1 - t2)


t = int(input())
for i in range(t):
	(n, m, k) = map(int, input().split())
	c = n // k
	if m >= c:
		wj = c
		j = m - c
		mj = 0
		while j > 0:
			for l in range(k - 1):
				j -= 1
			mj += 1
		print(c - mj)
	else:
		print(m)


import math
t = int(input())
for g in range(t):
	(n, m, k) = map(int, input().split())
	c = n // k
	if c >= m:
		print(m)
	else:
		a = c
		m = m - a
		d = math.ceil(m / (k - 1))
		print(a - d)


import math
for i in range(int(input())):
	(n, m, k) = map(int, input().split())
	p = n // k
	if m == 0:
		print(0)
		continue
	if p < m:
		a = p
		m = m - a
		b = math.ceil(m / (k - 1))
		print(a - b)
	else:
		print(m)


y = int(input())
for x in range(y):
	nmk = input().split()
	n = int(nmk[0])
	m = int(nmk[1])
	k = int(nmk[2])
	a = [0] * (k - 1)
	if n // k >= m:
		ans = m
	else:
		ans = n // k
		m = m - n // k
		i = 0
		while m > 0:
			a[i] += 1
			m -= 1
			i += 1
			if i == len(a):
				i = 0
	ans = ans - max(a)
	print(ans)


for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	if n // k >= m:
		print(m)
	else:
		z = n // k
		y = m - z
		x = k - 1
		p = (y + x - 1) // x
		print(z - p)


a = int(input())
for i in range(0, a):
	(n, m, k) = map(int, input().split())
	cards = n // k
	maxx = min(cards, m)
	m = m - maxx
	count = 0
	if m > 0:
		while m > k - 1:
			count = count + 1
			m = m - (k - 1)
		if not m == 0:
			count = count + 1
		maxx = maxx - count
	print(maxx)


import sys
from os import path
if path.exists('C:/Users/prana/Desktop/sublime/input.txt'):
	sys.stdin = open('C:/Users/prana/Desktop/sublime/input.txt', 'r')
	sys.stdout = open('C:/Users/prana/Desktop/sublime/output.txt', 'w')
import math

def solve():
	(n, m, k) = input().split()
	n = int(n)
	m = int(m)
	k = int(k)
	if n // k >= m:
		print(m)
	else:
		temp = m - n // k
		count = 0
		temp1 = temp // (k - 1)
		if temp % (k - 1) == 0:
			print(n // k - temp1)
		else:
			print(n // k - temp1 - 1)
T = 1
T = int(input())
for _ in range(1, T + 1):
	print('Case #', _, file=sys.stderr)
	solve()


import math
for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	max_card = a / c
	if max_card >= b:
		print(b)
	else:
		x = (b - max_card) / (c - 1)
		x = math.ceil(x)
		print(int(max_card - x))


import math
test = int(input())
for i in range(test):
	(n, m, k) = [int(i) for i in input().split()]
	if n / k > m or n / k == m:
		print(m)
	elif n / k < m:
		if n / k == 1:
			print(0)
		else:
			print(round(n / k) - math.ceil((m - n / k) / (k - 1)))


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(n, m, k) = map(int, input().split())
	win = min(n // k, m)
	rem = m - win
	if rem == 0:
		print(win)
	else:
		print(win - (rem + k - 2) // (k - 1))


import math
t = int(input())
while t:
	t = t - 1
	(n, m, k) = [int(s) for s in input().split()]
	if m == 0:
		print('0')
	elif n == m:
		print('0')
	elif n / k >= m:
		print(m)
	else:
		jocker_left = m - n / k
		player_left = k - 1
		distributed_cards = math.ceil(jocker_left / player_left)
		print(int(n / k) - distributed_cards)


printn = lambda x: print(x, end='')
inn = lambda : int(input())
inl = lambda : list(map(int, input().split()))
inm = lambda : map(int, input().split())
ins = lambda : input().strip()
DBG = True
BIG = 10 ** 18
R = 10 ** 9 + 7

def ddprint(x):
	if DBG:
		print(x)
t = inn()
for tt in range(t):
	(n, m, k) = inm()
	x = min(m, n // k)
	y = (m - x + k - 2) // (k - 1)
	print(x - y)


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, m, k) = map(int, input().split())
	cards = n // k
	if cards >= m:
		curr_max = m
		m -= m
	else:
		curr_max = cards
		m -= cards
	arr = [0 for i in range(k - 1)]
	i = 0
	while m > 0:
		arr[i] += 1
		i = (i + 1) % (k - 1)
		m -= 1
	print(curr_max - max(arr))
t = int(input())
for _ in range(t):
	main()


import math
t = int(input())
for i in range(t):
	(n, m, k) = map(int, input().split())
	per_p = n // k
	if per_p >= m:
		print(m)
	else:
		maxi_m = per_p
		min_m = math.ceil((m - per_p) / (k - 1))
		print(maxi_m - min_m)


import math
t = int(input())
out = []
for i in range(t):
	(n, m, k) = input().split()
	if int(n) / int(k) >= int(m) or int(m) == 0:
		out.append(int(m))
	else:
		temp = int(n) // int(k)
		m = int(m) - temp
		k = int(k) - 1
		out.append(temp - math.ceil(int(m) / int(k)))
for i in range(t):
	print(out[i])


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


import sys
import math
from sys import stdin, stdout

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

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

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

def main():
	for t in range(int(input())):
		(n, m, k) = get_ints()
		s = n // k
		if m <= s:
			print(m)
		else:
			z = m - s
			v = math.ceil(z / (k - 1))
			print(s - int(v))
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')
main()


import math
for i in range(int(input())):
	(a, b, c) = list(map(int, input().split()))
	k = a // c
	if b <= k:
		print(b)
	elif b == 0:
		print(0)
	elif b > k:
		print(k - math.ceil((b - k) / (c - 1)))


t = int(input())
from math import ceil
z = 0
while z < t:
	(n, m, k) = map(int, input().split())
	if m == 0:
		print(0)
	else:
		a = n // k
		if a >= m:
			print(m)
		elif m > a:
			fstwinner = a
			m = m - fstwinner
			k -= 1
			secwinner = ceil(m / k)
			print(abs(fstwinner - secwinner))
	z += 1


import math
anss = []
for h in range(int(input())):
	(n, m, k) = map(int, input().strip().split())
	each = n // k
	if m < each:
		anss.append(str(m))
	else:
		left = m - each
		mini = math.ceil(left / (k - 1))
		anss.append(str(each - mini))
print('\n'.join(anss))


t = int(input())
for _ in range(t):
	(n, m, k) = map(int, input().split())
	a = n // k
	ma = 10 ** 9
	ma = min(ma, m, a)
	m -= ma
	pl = m // (k - 1)
	m = m % (k - 1)
	if m != 0:
		print(ma - pl - 1)
	else:
		print(ma - pl)


import math
for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	cards = n // k
	if cards > m:
		print(m)
	else:
		print(max(cards - math.ceil((m - cards) / (k - 1)), 0))


from math import ceil
t = int(input())
for i in range(t):
	X = input()
	X1 = X.split()
	n = int(X1[0])
	m = int(X1[1])
	k = int(X1[2])
	if m <= n / k:
		print(m)
	else:
		m1 = m - n / k
		v = ceil(m1 / (k - 1))
		print(int(n / k - v))


t = int(input())
for _ in range(t):
	(n, m, k) = [int(x) for x in input().split()]
	np1 = min(m, n // k)
	m -= np1
	np2 = (m + k - 2) // (k - 1)
	print(np1 - np2)


n = int(input())
l = []
for i in range(n):
	m = list(map(int, input().split()))
	l.append(m)
for i in l:
	no_player = i[2]
	no_card = i[0]
	joker = i[1]
	top_card = no_card // no_player
	if top_card > joker:
		print(joker)
	else:
		temp = (joker - no_card // no_player) // (no_player - 1)
		if (joker - no_card // no_player) % (no_player - 1) != 0:
			temp += 1
		print(top_card - temp)


import math
T = int(input())
for tt in range(0, T):
	(n, m, k) = map(int, input().split())
	if m == 0:
		print(0)
		continue
	a = n // k
	if m <= a:
		print(m)
		continue
	if k == 2:
		print(n - m)
		continue
	if m > k * (a - 1) + 1:
		print(0)
		continue
	r = (m - a) % (k - 1)
	s = (m - a) // (k - 1)
	if r == 0:
		print(a - s)
	else:
		print(a - (s + 1))


from sys import stdin, stdout
import math
fastinput = stdin.readline
fastout = stdout.write
for _ in range(int(fastinput())):
	(n, m, k) = map(int, fastinput().split())
	x = n // k
	if m <= x:
		print(m)
	else:
		m -= x
		if m % (k - 1) != 0:
			ans = -1
		else:
			ans = 0
		print(ans + x - m // (k - 1))


for _ in range(int(input())):
	(n, m, k) = list(map(int, input().split(' ')))
	x = min(n // k, m)
	rest = m - x
	if rest == 0:
		y = 0
	elif rest % (k - 1) == 0:
		y = rest // (k - 1)
	else:
		y = rest // (k - 1) + 1
	print(x - y)


import sys

def input():
	return sys.stdin.readline().rstrip()
t = int(input())
answers = []
for _ in range(t):
	(n, m, k) = [int(i) for i in input().split()]
	my_hand = min(n // k, m)
	other_hand = (m - my_hand - 1) // (k - 1) + 1
	answers.append(my_hand - other_hand)
print(*answers, sep='\n')


t = int(input())
for i in range(t):
	(n, m, k) = [int(x) for x in input().split()]
	perp = int(n / k)
	if m <= perp:
		print(m)
	elif (m - perp) % (k - 1) == 0:
		print(perp - int((m - perp) / (k - 1)))
	else:
		print(perp - int((m - perp) / (k - 1)) - 1)


for _ in range(int(input())):
	(n, jockers, persons) = map(int, input().split())
	cards_per_person = n // persons
	if jockers <= cards_per_person:
		print(jockers)
	elif jockers > cards_per_person:
		if persons - 1 >= jockers - cards_per_person:
			print(cards_per_person - 1)
		elif (jockers - cards_per_person) % (persons - 1) == 0:
			print(cards_per_person - (jockers - cards_per_person) // (persons - 1))
		else:
			print(cards_per_person - (jockers - cards_per_person) // (persons - 1) - 1)


for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	x = min(m, n // k)
	y = -((x - m) // (k - 1))
	print(max(0, x - y))


from math import ceil
t = int(input())
for i in range(t):
	(n, m, k) = map(int, input().split())
	x = n / k
	if m <= x:
		print(int(m))
	elif m == 0:
		print(0)
	elif m > x:
		m = m - x
		s = ceil(m / (k - 1))
		if x == s:
			print(0)
		else:
			print(int(x - s))


import math
t = int(input())
for i in range(t):
	(n, m, k) = list(map(int, input().split()))
	if n // k >= m:
		print(m)
	else:
		winner = n // k
		left = m - n // k
		print(winner - math.ceil(left / (k - 1)))


import math
t = int(input())
while t:
	inp1 = list(map(int, input().strip().split()))[:3]
	(n, m, k) = (inp1[0], inp1[1], inp1[2])
	if m == 0:
		print(0)
	else:
		cards_each_one = n // k
		first_person = min(cards_each_one, m)
		m -= first_person
		k -= 1
		if m == 0:
			print(first_person)
		elif m <= k:
			print(first_person - 1)
		else:
			val = math.ceil(m / k)
			print(first_person - val)
	t -= 1


from math import ceil
for _ in range(int(input())):
	l = input().split()
	l = [int(i) for i in l]
	n = l[0]
	m = l[1]
	k = l[2]
	ab = n / k
	pl = n - m
	if ab >= m:
		print(m)
	elif ab < m:
		c = m - ab
		f = ab
		e = ceil(c / (k - 1))
		print(int(f - e))


for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	no_of_cards_each_player_has = n // k
	if m > no_of_cards_each_player_has:
		remaining_queen = m - no_of_cards_each_player_has
		remaining_player = k - 1
		if remaining_player == 0:
			print(no_of_cards_each_player_has)
		else:
			temp = remaining_queen // remaining_player
			if remaining_queen % remaining_player == 0:
				print(no_of_cards_each_player_has - temp)
			else:
				print(no_of_cards_each_player_has - temp - 1)
	else:
		print(m)


def cap(n, m, k):
	t = n // k
	if m > t:
		rem = m - t
		pl = k - 1
		if rem <= pl:
			print(t - 1)
		elif rem % pl == 0:
			print(t - rem // pl)
		else:
			print(t - rem // pl - 1)
	else:
		print(m)
n = int(input())
for i in range(n):
	a = list(map(int, input().split(' ')))
	cap(a[0], a[1], a[2])


from bisect import bisect_left as bl
from bisect import bisect_right as br
from heapq import heappush, heappop
import math
from collections import *
from functools import reduce, cmp_to_key, lru_cache
import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
M = mod = 10 ** 9 + 7

def factors(n):
	return sorted(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().split()]

def st():
	return str(input().rstrip())[2:-1]

def val():
	return int(input().rstrip())

def li2():
	return [str(i)[2:-1] for i in input().rstrip().split()]

def li3():
	return [int(i) for i in st()]
for _ in range(val()):
	(n, m, k) = li()
	one = min(m, n // k)
	m -= one
	second = m // (k - 1) + (1 if m % (k - 1) else 0)
	print(one - second)


import sys
input = lambda : sys.stdin.readline().rstrip()
t = int(input())
g = [list(map(int, input().split())) for i in range(t)]
ans = [0] * t
for i in range(t):
	n = g[i][0]
	m = g[i][1]
	k = g[i][2]
	if n // k >= m:
		ans[i] = m
	else:
		r = -((m - n // k) // -(k - 1))
		ans[i] = max(n // k - r, 0)
for i in range(t):
	print(ans[i])


a = int(input())
for i in range(a):
	list = [int(x) for x in input().split()]
	n = list[0]
	m = list[1]
	k = list[2]
	card = n / k
	j = m
	arr = []
	for lp in range(k - 1):
		arr.append(0)
	lp = 0
	if m > card:
		j -= card
		while 3 < 4:
			arr[lp] += 1
			j -= 1
			if j <= 0:
				break
			lp += 1
			if lp == k - 1:
				lp = 0
		h = card - int(arr[0])
	if card >= m:
		h = m
	print(int(h))


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 main():
	t = I()
	rr = []
	for _ in range(t):
		(n, m, k) = LI()
		t = n // k
		r = min(m, t)
		r -= (m - r + k - 2) // (k - 1)
		rr.append(r)
	return JA(rr, '\n')
print(main())


from __future__ import division, print_function
import bisect
import math
import heapq
import itertools
import sys
from collections import deque
from atexit import register
from collections import Counter
from functools import reduce
if sys.version_info[0] < 3:
	from io import BytesIO as stream
else:
	from io import StringIO as stream

def sync_with_stdio(sync=True):
	global input, flush
	if sync:
		flush = sys.stdout.flush
	else:
		sys.stdin = stream(sys.stdin.read())
		input = lambda : sys.stdin.readline().rstrip('\r\n')
		sys.stdout = stream()
		register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	if m == 0:
		print(0)
	elif m <= n / k:
		print(m)
	else:
		max1 = n / k
		r = m - n / k
		print(int(max1 - math.ceil(r / (k - 1))))


import math
for _ in range(int(input())):
	(n, m, k) = list(map(int, input().split()))
	e = n // k
	p = 0
	if e >= m:
		p = m
	else:
		m -= e
		m = math.ceil(m / (k - 1))
		p = e - m
	print(p)


import sys
import math as mt
input = sys.stdin.buffer.readline
t = int(input())
for __ in range(t):
	(n, m, k) = map(int, input().split())
	if n // k >= m:
		print(m)
	else:
		if (m - n // k) % (k - 1) == 0:
			ans = n // k - (m - n // k) // (k - 1)
		else:
			ans = n // k - (m - n // k) // (k - 1)
			ans -= 1
		print(ans)


import math
import sys
from sys import stdin
input = sys.stdin.readline
for _ in range(int(input())):
	(n, m, k) = [int(j) for j in input().split()]
	if m == 0:
		print(0)
	elif n / k >= m:
		print(m)
	else:
		arr = [0] * (k - 1)
		winner = n / k
		m = m - winner
		for i in range(int(m)):
			arr[i % (k - 1)] += 1
		print(int(winner - max(arr)))


tests = int(input())

def go1(n, m, k):
	if m == 0:
		return 0
	cards = n // k
	return min(m, cards)

def go2(n, m, k):
	if m == 0:
		return 0
	l = []
	for i in range(k):
		l.append(0)
	index = 0
	while m > 0:
		l[index] += 1
		index += 1
		if index == k:
			index = 0
		m -= 1
	return l[0]
for i in range(tests):
	(n, m, k) = [int(x) for x in list(input().split())]
	mx = go1(n, m, k)
	mx2 = go2(n - n // k, m - mx, k - 1)
	print(mx - mx2)


def count(n, m, k):
	if m == n:
		return 0
	elif m <= n // k:
		return m
	else:
		(d, key) = ({}, 0)
		cards = n // k
		m -= cards
		k -= 1
		while m > 0:
			key = m % k
			d[key] = d.get(key, 0) + 1
			m -= 1
		return cards - max(d.values())
for i in range(int(input())):
	(n, m, k) = list(map(int, input().split()))
	res = count(n, m, k)
	print(res)


import math
t = int(input())
for i in range(t):
	(n, m, k) = [int(x) for x in input().split()]
	cards = n // k
	if cards < m:
		print(cards - math.ceil((m - cards) / (k - 1)))
	elif cards >= m:
		print(m)


for _ in range(int(input())):
	(cards_count, jokers_count, players) = map(int, input().split())
	cards_per_player = cards_count // players
	if cards_per_player >= jokers_count:
		print(jokers_count)
	else:
		jokers_count -= cards_per_player
		other_players = players - 1
		if jokers_count <= other_players:
			print(cards_per_player - 1)
		else:
			jokers_per_other_players = jokers_count // other_players
			if jokers_count % other_players == 0:
				score = cards_per_player - jokers_per_other_players
			else:
				jokers_per_other_players += 1
				score = cards_per_player - jokers_per_other_players
			print(score)


import math
for j in range(int(input())):
	(n, k, m) = map(int, input().split())
	if k == 0:
		print(0)
	elif k <= n / m:
		print(k)
	else:
		d = n / m
		print(int(d - math.ceil((k - d) / (m - 1))))


t = int(input())
ans = []
for i in range(t):
	(n, m, k) = map(int, input().split())
	if n // k < m:
		if k == 2 and n != m:
			ans.append(n // k - (m - n // k))
		elif (n - n // k - (n - m)) / (k - 1) != (n - n // k - (n - m)) // (k - 1):
			ans.append(n // k - 1 - (n - n // k - (n - m)) // (k - 1))
		elif (n - n // k - (n - m)) / (k - 1) == (n - n // k - (n - m)) // (k - 1):
			ans.append(n // k - (n - n // k - (n - m)) // (k - 1))
		else:
			ans.append(0)
	elif n // k >= m:
		ans.append(m)
for i in range(t):
	print(ans[i])


def main():
	for _ in range(int(input())):
		(n, m, k) = map(int, input().split())
		each = n // k
		if m <= each:
			print(m)
		else:
			ans = each
			m -= each
			ans -= m // (k - 1)
			m = m % (k - 1)
			if m > 0:
				ans -= 1
			print(max(ans, 0))
main()


import math
for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	card_for_one_player = int(n / k)
	if m <= card_for_one_player:
		print(m)
	else:
		rem = m - card_for_one_player
		ans = int(math.ceil(rem / (k - 1)))
		print(card_for_one_player - ans)


import math
for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	cards = n // k
	mx = 0
	sm = 0
	if cards == 1 and m != 1 or m == 0:
		print(0)
	elif m >= cards:
		mx = cards
		m -= cards
		sm = math.ceil(m / (k - 1))
		print(mx - sm)
	else:
		print(m)


from math import ceil
t = int(input())
for i in range(t):
	(n, m, k) = [int(i) for i in input().split()]
	print(min(m, n // k - ceil((m - n // k) / (k - 1))))


T = int(input())
import math
for _ in range(T):
	(n, m, k) = map(int, input().split())
	ma = min(n // k, m)
	nokori = m - ma
	hoka = math.ceil(nokori / (k - 1))
	if ma == hoka:
		print(0)
	else:
		print(ma - hoka)


import sys, math, os
from io import BytesIO, IOBase
from bisect import bisect_left as bl, bisect_right as br, insort
from collections import defaultdict as dd, deque, Counter

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

def mdata():
	return list(map(int, data().split()))

def outl(var):
	sys.stdout.write(' '.join(map(str, var)) + '\n')

def out(var):
	sys.stdout.write(str(var) + '\n')
sys.setrecursionlimit(100000)
INF = float('inf')
mod = int(1000000000.0) + 7

def main():
	for t in range(int(data())):
		(n, m, k) = mdata()
		flag = False
		if n // k >= m:
			print(m)
		else:
			print(n // k - math.ceil((m - n // k) / (k - 1)))
main()


import math
t = int(input())
for _ in range(t):
	(n, m, k) = list(map(int, input().rstrip().split()))
	if m == 0:
		print(0)
	else:
		each = n // k
		if each >= m:
			print(m)
		else:
			max = each
			min = int(math.ceil((m - max) / (k - 1)))
			print(max - min)


import math
t = int(input())
for _ in range(t):
	(n, m, k) = [int(x) for x in input().split()]
	y = int(n / k)
	if m <= y:
		print(m)
	else:
		p = m - y
		z = int(math.ceil(p / (k - 1)))
		a = y - z
		print(a)


t = int(input())
for i in range(t):
	(n, m, k) = map(int, input().split())
	a = n // k
	if a >= m:
		print(m)
	else:
		y = m - a
		z = y / (k - 1)
		if z == int(z):
			print(a - int(z))
		else:
			print(a - int(z) - 1)


t = int(input())
for _ in range(t):
	(n, m, k) = map(int, input().split())
	cards = n // k
	winjoker = min(n // k, m)
	m -= winjoker
	if m % (k - 1) == 0:
		print(winjoker - m // (k - 1))
	else:
		print(winjoker - m // (k - 1) - 1)


t = int(input())
for _ in range(t):
	(n, m, k) = list(map(int, input().split()))
	cards_per_person = n // k
	max_joker = min(cards_per_person, m)
	left_jokers = m - max_joker
	(d, r) = divmod(left_jokers, k - 1)
	print(max_joker - (d + bool(r)))


import math
for i in range(int(input())):
	(a, b, c) = map(int, input().split())
	d = a // c
	if b <= d:
		print(b)
	else:
		k = b - d
		s = math.ceil(k / (c - 1))
		print(d - s)


for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	p = n // k
	if p >= m:
		print(m)
		continue
	elif p == 1 or m == 0:
		print(0)
		continue
	else:
		m = m - p
		k -= 1
		q = m // k
		r = m % k
		if r != 0:
			q += 1
		print(p - q)


import math
test_case = int(input())
for t in range(test_case):
	(cards, jokers, players) = map(int, input().split())
	cards_dealt = cards // players
	max_jokers = min(jokers, cards_dealt)
	min_jokers = int(math.ceil((jokers - max_jokers) / (players - 1)))
	print(int(max_jokers - min_jokers))


import sys
input = lambda : sys.stdin.readline().strip()
inp = lambda : list(map(int, sys.stdin.readline().strip().split()))
for _ in range(int(input())):
	(n, m, k) = list(map(int, input().split()))
	t = n // k
	one = min(t, m)
	m -= one
	two = (m + k - 2) // (k - 1)
	print(one - two)


import math
t = int(input())
for you in range(t):
	l = input().split()
	n = int(l[0])
	m = int(l[1])
	k = int(l[2])
	cards = min(m, n // k)
	if cards == m:
		print(m)
	else:
		z = m - cards
		curr = math.ceil((m - cards) / (k - 1))
		print(cards - curr)


import math
t = int(input())

def solve():
	(n, m, k) = map(int, input().split())
	each = int(n / k)
	jokers = m
	winner = min(each, jokers)
	jokers -= winner
	second = int(math.ceil(jokers / (k - 1)))
	print(winner - second)
for i in range(t):
	solve()


t = int(input())
for test in range(t):
	(n, m, k) = input().split()
	(n, m, k) = (int(n), int(m), int(k))
	if m == 0:
		print(0)
		continue
	cards = n // k
	if cards >= m:
		print(m)
		continue
	points = cards
	m -= cards
	max_other_point = m / (k - 1)
	if max_other_point > int(max_other_point):
		max_other_point = int(max_other_point) + 1
	max_other_point = int(max_other_point)
	gained = points - max_other_point
	print(gained)


import math
t = int(input())
for j in range(t):
	(n, m, k) = list(map(int, input().split()))
	f = n // k
	if f == 1 and m > 1:
		print(0)
	elif f >= m:
		print(m)
	else:
		print(f - math.ceil((m - f) / (k - 1)))


t = int(input())
for i in range(t):
	(n, m, k) = map(int, input().split())
	d = n // k
	a1 = min(m, d)
	a2 = (m - a1 + k - 2) // (k - 1)
	print(a1 - a2)


t = int(input())
while t > 0:
	(n, m, k) = list(map(int, input().split()))
	jokers = n // k
	if m > jokers:
		m -= jokers
		x = m // (k - 1)
		if m % (k - 1) != 0:
			x += 1
		print(jokers - x)
	else:
		print(m)
	t -= 1


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


import math
t = int(input())
for i in range(t):
	(n, m, k) = map(int, input().split())
	v = n // k
	x = min(m, v)
	if m - x == 0:
		y = 0
	else:
		y = math.ceil((m - x) / (k - 1))
		if y >= x:
			y = x
	print(x - y)


from sys import stdin, stdout
import math
for _ in range(int(stdin.readline())):
	(n, m, k) = map(int, stdin.readline().split())
	div = n // k
	if m == 0:
		stdout.write('0' + '\n')
	elif div >= m:
		stdout.write(str(m) + '\n')
	else:
		m -= div
		k -= 1
		ciel = math.ceil(m / k)
		print(div - ciel)


for i in range(int(input())):
	(n, m, k) = map(int, input().split())
	print(min(m, (n - m) // (k - 1)))


import math

def main():
	for _ in range(int(input())):
		(n, m, k) = list(map(int, input().split()))
		x = n // k
		if x >= m:
			print(m)
		else:
			print(x - math.ceil((m - x) / (k - 1)))
main()


for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	temp = n // k
	if m <= temp:
		print(m)
	else:
		m -= temp
		k -= 1
		i = 1
		while m > k:
			i += 1
			m -= k
		print(temp - i)


r = int(input())
p = []
for i in range(r):
	x = [int(x) for x in input().split(' ')]
	if x[1] <= x[0] / x[2]:
		p.append(x[1])
	else:
		people = (x[1] - x[0] / x[2]) / (x[2] - 1)
		if (x[1] - x[0] / x[2]) / (x[2] - 1) > (x[1] - x[0] / x[2]) // (x[2] - 1):
			people += 1
		people = int(people)
		p.append(x[0] // x[2] - people)
for i in p:
	print(i)


from math import *
from copy import *
from string import *
from random import *
from sys import stdin
from sys import maxsize
from operator import *
from itertools import *
from collections import Counter
import math
import math
import time

def bin1(l, r, k, t, b, val, ans):
	if l > r:
		return ans
	else:
		mid = (l + r) // 2
		v = k ** mid
		if v == val:
			return v
		elif v > val:
			ans = mid
			return bin1(mid + 1, r, k, t, b, val, ans)
		else:
			return bin1(l, mid - 1, k, t, b, val, ans)

def bin2(l, r, k, t, b, val, ans):
	if l > r:
		return ans
	else:
		mid = (l + r) // 2
		v = t * k ** mid + b * mid
		if v == val:
			return v
		elif v > val:
			ans = mid
			return bin2(l, mid - 1, k, t, b, val, ans)
		else:
			return bin2(mid + 1, r, k, t, b, val, ans)

def SieveOfEratosthenes(n):
	prime = [-1 for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == -1:
			for i in range(p * p, n + 1, p):
				prime[i] = p
		p += 1
	l1 = []
	for i in range(2, n + 1):
		if prime[i] == -1:
			l1.append(i)
	return l1

def bin(l, r, ll, val):
	if l > r:
		return -1
	else:
		mid = (l + r) // 2
		if val >= ll[mid][0] and val <= ll[mid][1]:
			return mid
		elif val < ll[mid][0]:
			return bin(l, mid - 1, ll, val)
		else:
			return bin(mid + 1, r, ll, val)

def deci(n):
	s = ''
	while n != 0:
		if n % 2 == 0:
			n = n // 2
			s = '0' + s
		else:
			n = n // 2
			s = '1' + s
	return s

def diff(s1, s2):
	if len(s1) < len(s2):
		v = len(s1)
		while v != len(s2):
			s1 = '0' + s1
			v = v + 1
	else:
		v = len(s2)
		while v != len(s1):
			s2 = '0' + s2
			v = v + 1
	c = 0
	for i in range(len(s1)):
		if s1[i:i + 1] != s2[i:i + 1]:
			c = c + 1
	return c
from sys import stdin, stdout

def fac(a, b):
	v = a
	while a != b:
		v *= a - 1
		a = a - 1
	return v

def bino(l, r, n):
	if l > r:
		return -1
	else:
		mid = (l + r) // 2
		val1 = math.log(n / mid + 1, 2)
		val2 = int(val1)
		if val1 == val2:
			return val1
		elif val1 < 1.0:
			return bino(l, mid - 1, n)
		else:
			return bino(mid + 1, r, n)

def binary(l, r, val, ans):
	if l > r:
		return -1
	else:
		mid = (l + r) // 2
		v = val ** 5 - mid ** 5
		print(v)
		if v == ans:
			print('HOHOHOH')
			return mid
		elif v < ans:
			return binary(mid + 1, r, val, ans)
		else:
			return binary(l, mid - 1, val, ans)

def check(n):
	v = 1
	while n != 0:
		if n % 10 == 0 or n % 10 == 1:
			n = n // 10
		else:
			v = 0
			break
	return v

def stairs(n, m, val, c, l):
	if val > n:
		return 100000
	elif val == n:
		if l[val] != -1:
			return l[val]
		elif c % m == 0:
			l[val] = c
			return l[val]
		else:
			l[val] = 100000
			return l[val]
	else:
		l[val] = min(stairs(n, m, val + 1, c + 1, l), stairs(n, m, val + 2, c + 1, l))
		return l[val]

def fact(n):
	if n == 0 or n == 1:
		return 1
	else:
		return n * fact(n - 1)

def some(n):
	s = 0
	while n != 0:
		s += fact(n % 10)
		n //= 10
	return s

def bin(ll, l, r, val, ans):
	if l > r:
		return ans
	else:
		mid = (l + r) // 2
		if ll[mid] >= val:
			ans = mid
			return bin(ll, l, mid - 1, val, ans)
		else:
			return bin(ll, mid + 1, r, val, ans)

def fn(n):
	c = -1
	for i in range(2, int(sqrt(n)) + 1):
		if n % 2 == 0:
			c = i
			break
	if c == -1:
		c = n
	return c

def check(n):
	val = 0
	while n != 0:
		if n % 10 > 1:
			val = -1
			break
		n = n // 10
	return val

def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)
t = int(input())
for i in range(t):
	(n, m, k) = map(int, input().split(' '))
	val = n // k
	if val >= m:
		print(m)
	else:
		a = m - val
		if a % (k - 1) == 0:
			print(val - a // (k - 1))
		else:
			print(val - (a // (k - 1) + 1))


def main():
	t = int(input())
	for i in range(t):
		(n, m, k) = map(int, input().split())
		if n // k >= m:
			print(m)
		else:
			count = 0
			m -= n // k
			while m > 0:
				m -= k - 1
				count += 1
			print(n // k - count)
main()


def xyz(cards, joker, player):
	person_cards = cards // player
	if person_cards >= joker:
		return joker
	else:
		n = joker - person_cards
		rem = (n + player - 2) // (player - 1)
		return person_cards - rem
for num in range(int(input())):
	(x, y, z) = map(int, input().split())
	print(xyz(x, y, z))


t = int(input())
for i in range(t):
	(n, m, k) = map(int, input().split())
	cart = n // k
	joker_max = min(m, cart)
	joker = m - joker_max
	igroki = k - 1
	a = [0] * igroki
	numb = 0
	while joker != 0:
		a[numb] += 1
		joker -= 1
		numb = (numb + 1) % igroki
	if joker_max == max(a):
		print(0)
	else:
		print(joker_max - max(a))


t = int(input())
for _ in range(t):
	(n, m, k) = map(int, input().split())
	wj = min(n // k, m)
	rj = m - wj
	if n - m >= (k - 1) * (n // k):
		print(wj)
	elif rj <= k - 1:
		print(max(wj - 1, 0))
	else:
		lj = 1
		while rj > k - 1:
			rj -= k - 1
			lj += 1
		lj = min(lj, n // k)
		print(max(wj - lj, 0))


import sys, math
tc = int(sys.stdin.readline())
for _ in range(tc):
	(n, m, k) = map(int, sys.stdin.readline().split())
	one_man = n // k
	if m <= one_man:
		print(m)
	else:
		m -= one_man
		hands = [0] * (k - 1)
		while m > 0:
			for i in range(len(hands)):
				if m <= 0:
					break
				hands[i] += 1
				m -= 1
		hands.sort(reverse=True)
		if hands[0] == one_man:
			print(0)
		else:
			print(one_man - hands[0])


import sys
input = sys.stdin.readline

def main():
	for _ in range(int(input())):
		(n, m, k) = list(map(int, input().split()))
		temp = min(n // k, m)
		temp1 = m - min(n // k, m)
		if temp1 % (k - 1) != 0:
			print(temp - temp1 // (k - 1) - 1)
		else:
			print(temp - temp1 // (k - 1))
main()


for tc in range(1, 1 + int(input())):
	(n, m, k) = map(int, input().split())
	kk = n // k
	x = min(m, kk)
	m -= x
	k -= 1
	y = (m + k - 1) // k
	print(x - y)


import math
test = int(input())
test_arr = []
for _ in range(test):
	(n, m, k) = map(int, input().split())
	each = n // k
	x = min(each, m)
	y = 0
	if k > 1:
		if m - x > k - 1:
			y = math.ceil((m - x) / (k - 1))
		elif m - x > 0:
			y = 1
	test_arr.append(x - y)
for t in test_arr:
	print(t)


import math

def solve(n, jokers, num_players):
	cards_per_player = n // num_players
	if jokers <= cards_per_player:
		return jokers
	min_jokers_per_player = math.ceil((jokers - cards_per_player) / (num_players - 1))
	return max(0, cards_per_player - min_jokers_per_player)
T = int(input())
for _ in range(T):
	(n, m, k) = map(int, input().split())
	print(solve(n, m, k))


import math

def solution():
	(n, m, k) = list(map(int, input().split()))
	hand_size = n // k
	if hand_size >= m:
		print(m)
		return
	rem = m - hand_size
	rp = k - 1
	maxP = math.ceil(rem / rp)
	print(hand_size - maxP)
T = int(input())
while T:
	solution()
	T -= 1


t = int(input())
n = list()
m = list()
k = list()
for i in range(t):
	inputs = input()
	(ni, mi, ki) = list(map(int, inputs.split(' ')))
	n.append(ni)
	m.append(mi)
	k.append(ki)

def rec(n, m, k, diff):
	if m == 0:
		return diff
	else:
		m -= k - 1
	return m
for i in range(t):
	if m[i] == 0:
		print(0)
	elif m[i] == 1:
		print(1)
	elif n[i] == k[i]:
		print(0)
	elif n[i] / k[i] >= m[i]:
		print(m[i])
	else:
		diff = n[i] // k[i]
		while m[i] > n[i] // k[i]:
			diff -= 1
			m[i] = rec(n[i], m[i], k[i], diff)
		print(diff)


for t in range(int(input())):
	(a, b, c) = [int(i) for i in input().split()]
	j = 0
	j = a // c
	if j == b // c or b == 0:
		j = 0
	elif b < j:
		j = b
	else:
		k = (b - j) // (c - 1)
		if (b - j) % (c - 1) != 0:
			k += 1
		j = j - k
	print(j)


import math
t = int(input())
for _ in range(0, t):
	(n, m, k) = map(int, input().strip().split(' '))
	perplayer = n // k
	if m <= perplayer:
		print(m)
	else:
		first = perplayer
		x = math.ceil((m - perplayer) / (k - 1))
		if x <= 0:
			print(0)
		else:
			print(first - x)


from sys import stdin
import math
t = int(stdin.readline().strip())
for _ in range(t):
	(n, j, k) = (int(var) for var in input().split())
	if j <= n // k:
		print(j)
	else:
		firstPerson = n // k
		j -= n // k
		print(firstPerson - math.ceil(j / (k - 1)))


import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__

def gift():
	for _ in range(t):
		(n, m, k) = list(map(int, input().split()))
		divis = n // k
		maxjok = min(divis, m)
		didi = (m - maxjok) % (k - 1)
		minjok = (m - maxjok) // (k - 1)
		if didi:
			minjok += 1
		yield (maxjok - minjok)
t = int(input())
ans = gift()
print(*ans, sep='\n')


T = int(input())
for t_itr in range(T):
	(N, M, K) = list(map(int, input().rstrip().split()))
	if N // K >= M:
		result = M
	else:
		(d, m) = divmod(M - N // K, K - 1)
		result = N // K - d
		if m > 0:
			result -= 1
	print(result)


t = int(input())
while t != 0:
	(n, m, k) = map(int, input().split())
	a = [0] * k
	if n // k < m:
		a[0] = n // k
		m -= n // k
	else:
		a[0] = m
		m = 0
	while m != 0:
		for i in range(k):
			if m == 0:
				break
			if a[i] == n // k:
				continue
			a[i] += 1
			m -= 1
	mx = max(a)
	a.remove(mx)
	print(mx - max(a))
	t -= 1


t = int(input())
for i in range(t):
	(n, m, k) = map(int, input().split())
	l = n // k
	f = m - l
	if l >= m:
		print(m)
	else:
		print(l - f // (k - 1) - (1 if f % (k - 1) else 0))


t = int(input())
for i in range(t):
	(n, m, k) = [int(x) for x in input().split()]
	maxPoints = 0
	if m <= n / k:
		maxPoints = m
	else:
		maxPoints = n / k
		rest = m - n / k
		maxPoints -= rest // (k - 1) + 1 * (rest % (k - 1) > 0)
	print(int(maxPoints))


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	d = a // c
	if d >= b:
		print(b)
	elif d == 1 or b == 0:
		print(0)
	else:
		print(d - ((b - d) // (c - 1) + int((b - d) % (c - 1) != 0)))


for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	ndk = n // k
	if ndk >= m:
		print(m)
	else:
		print(ndk - (m - ndk - 1) // (k - 1) - 1)


from sys import stdin, stdout
lis = lambda : list(map(int, input().split()))
Ma = lambda : map(int, input().split())
inte = lambda : int(input())
st = lambda : input()
import math
from collections import Counter
for i in range(inte()):
	(n, m, k) = Ma()
	if n / k >= m:
		print(m)
	else:
		x = n / k
		y = m - x
		if y >= k - 1:
			print(int(x - math.ceil(y / (k - 1))))
		else:
			print(int(x) - 1)


import sys
import math
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(n, m, k) = map(int, input().split())
	max_joker = min(m, n // k)
	m -= max_joker
	min_joker = math.ceil(m / (k - 1))
	print(max_joker - min_joker)


import sys
import math
import operator as op
from functools import reduce

def read_line():
	return sys.stdin.readline()[:-1]

def read_int():
	return int(sys.stdin.readline())

def read_int_line():
	return [int(v) for v in sys.stdin.readline().split()]

def read_float_line():
	return [float(v) for v in sys.stdin.readline().split()]

def ncr(n, r):
	r = min(r, n - r)
	numer = reduce(op.mul, range(n, n - r, -1), 1)
	denom = reduce(op.mul, range(1, r + 1), 1)
	return numer / denom

def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)

def gcdExtended(a, b):
	if a == 0:
		return (b, 0, 1)
	(gcd, x1, y1) = gcdExtended(b % a, a)
	x = y1 - b // a * x1
	y = x1
	return (gcd, x, y)
t = read_int()
for i in range(t):
	(n, m, k) = read_int_line()
	if n // k >= m:
		print(m)
	else:
		v = n // k
		if v + (v - 1) * k < m:
			print(0)
		else:
			val = m - n // k
			if val <= k - 1:
				print(v - 1)
				continue
			val = math.ceil(val / (k - 1))
			print(v - val)


for t in range(int(input())):
	(n, m, k) = map(int, input().split())
	num = n // k
	if num >= m:
		print(m)
	else:
		print(num - ((m - num) // (k - 1) + ((m - num) % (k - 1) != 0)))


import math
t = input()
t = int(t)
while t > 0:
	(n, m, k) = input().split()
	(n, m, k) = (int(n), int(m), int(k))
	if m == 0:
		print(0)
		t -= 1
		continue
	cards = n // k
	if cards > m:
		print(m)
	else:
		p1 = cards
		m -= cards
		al = math.ceil(m / (k - 1))
		print(p1 - al)
	t -= 1


from math import *
from sys import stdin, stdout
input = stdin.buffer.readline
t = int(input())
while t > 0:
	ip = [int(x) for x in input().split()]
	n = ip[0]
	m = ip[1]
	k = ip[2]
	if m <= n // k:
		ans = m
	else:
		ans = n // k - ceil((m - n // k) / (k - 1))
	print(ans)
	t -= 1


def solve():
	(n, m, k) = map(int, input().split())
	ans = 0
	for x in range(0, min(m, n // k) + 1):
		y = -(-(m - x) // (k - 1))
		if 0 <= y <= n // k:
			ans = max(ans, x - y)
	print(ans)
t = int(input())
for _ in range(t):
	solve()


from math import ceil
for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	each = n // k
	mx = min(each, m)
	rem = m - mx
	p = ceil(rem / (k - 1))
	ans = mx - p
	print(ans)


for i in range(int(input())):
	(n, m, k) = list(map(int, input().split()))
	if m <= n // k:
		print(m)
	else:
		b = n // k
		m -= b
		k -= 1
		if m <= k:
			print(b - 1)
		elif k >= 2:
			c = m // k
			if m % k == 0:
				print(b - c)
			else:
				print(b - c - 1)
		else:
			print(b - m)


def main():
	test_cases = int(input())
	for i in range(test_cases):
		case_input = str(input()).split()
		persons = int(case_input[2])
		total = int(case_input[0])
		number_cards = total / persons
		joker = int(case_input[1])
		if joker <= number_cards:
			print(joker)
		elif joker > number_cards:
			aux = (joker - number_cards) // (persons - 1)
			if (joker - number_cards) % (persons - 1) != 0:
				aux += 1
			print(int(number_cards - aux))
main()


def solve():
	(n, m, k) = map(int, input().split())
	if n // k >= m:
		print(m)
	else:
		rp = k - 1
		rj = m - n // k
		if rj % rp == 0:
			print(n // k - rj // rp)
		else:
			j = rj // rp + 1
			print(n // k - j)

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


import math

def solve(n, m, k):
	x1 = min(n // k, m)
	r = m - x1
	x2 = math.ceil(r / (k - 1))
	return x1 - x2
t = int(input())
for _ in range(t):
	(n, m, k) = map(int, input().split())
	print(solve(n, m, k))


t = int(input())
import math
output = []
for _ in range(t):
	(n, m, k) = list(map(int, input().split()))
	if n // k >= m:
		output.append(m)
	else:
		output.append(n // k - math.ceil((m - n // k) / (k - 1)))
for item in output:
	print(item)


import math
t = int(input())
for test in range(t):
	(n, m, k) = map(int, input().split())
	mx = n // k
	arr = []
	arr.append(min(mx, m))
	m -= min(mx, m)
	ever = math.ceil(m / (k - 1))
	arr.append(ever)
	arr.sort(reverse=True)
	print(int(arr[0] - arr[1]))


import math
t = int(input())
while t:
	t += -1
	(n, m, k) = map(int, input().split())
	if m == n:
		print(0)
	elif n // k >= m:
		print(m)
	else:
		m = m - n // k
		tmp = math.ceil(m / (k - 1))
		print(n // k - tmp)


for i in [*open(0)][1:]:
	(n, m, k) = map(int, i.split())
	print((min(m, n // k) * k - m) // (k - 1))


import sys
input = sys.stdin.readline

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

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

def solve(test):
	(cards, jokers, players) = test
	cards_per_player = cards // players
	if jokers <= cards_per_player:
		print(jokers)
		return
	jokers_per_loser = (jokers - cards_per_player) // (players - 1)
	if (jokers - cards_per_player) % (players - 1) != 0:
		jokers_per_loser += 1
	print(cards_per_player - jokers_per_loser)

def main():
	T = inp()
	tests = []
	for _ in range(T):
		tests.append(inlt())
	for test in tests:
		solve(test)
main()


import math
for i in range(int(input())):
	(n, m, k) = map(int, input().split())
	q = n // k
	f = min(m, q)
	r = math.ceil((m - f) / (k - 1))
	print(f - r)


import sys
from collections import defaultdict
from copy import copy
R = lambda t=int: t(input())
RL = lambda t=int: [t(x) for x in input().split()]
RLL = lambda n, t=int: [RL(t) for _ in range(n)]

def solve():
	(n, m, k) = RL()
	p = n // k
	max_jokers = min(m, p)
	m -= max_jokers
	min_jokers = (m + (k - 2)) // (k - 1)
	print(max_jokers - min_jokers)
T = R()
for t in range(1, T + 1):
	solve()


import sys
from math import ceil
_INPUT_LINES = sys.stdin.read().splitlines()
input = iter(_INPUT_LINES).__next__

def empty(*arg):
	pass
debug = empty
tc = int(input())
for zzz in range(tc):
	(n, m, k) = map(int, input().split())
	b = n // k
	if b < m:
		r = m - b
		t = ceil(r / (k - 1))
		debug('b = {},t = {}'.format(b, t))
		if t < b:
			print(b - t)
		else:
			print(0)
	else:
		print(m)


import math

def check(n, k):
	return n // 2 * k + math.ceil(k / 2) * (n % 2)

def solution():
	(n, m, k) = map(int, input().split())
	z = n // k
	if m == min(m, z):
		print(m)
		return
	ans = math.ceil((m - z) / (k - 1))
	print(z - ans)
for _ in range(int(input())):
	solution()


import math
for i in range(int(input())):
	(n, m, k) = map(int, input().split())
	if int(n / k) >= m:
		print(m)
	elif n == m or (n / k == 1 and m != 1):
		print(0)
	elif n != m and n / k != 1:
		max = int(n / k)
		if (m - max) / (k - 1) == int((m - max) / (k - 1)):
			min = int((m - max) / (k - 1))
		else:
			min = int((m - max) / (k - 1) + 1)
		print(max - min)


from collections import deque
from sys import stdin, stdout
import math
input = stdin.readline
for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	have = n
	one = n // k
	mx = min(one, m)
	m -= mx
	bf = m // (k - 1) + (1 if m % (k - 1) else 0)
	if bf > one - 1:
		print(0)
	else:
		print(abs(mx - (m // (k - 1) + (1 if m % (k - 1) else 0))))


import math
for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	val = n // k
	if val >= m:
		print(m)
	else:
		value = val - math.ceil((m - val) / (k - 1))
		print(value)


t = int(input())
while t:
	t = t - 1
	(n, m, k) = map(int, input().split())
	if n // k >= m:
		print(m)
	elif m == 0:
		print(0)
	elif n // k == 1 and m == 2:
		print(0)
	else:
		remj = m - n // k
		rp = k - 1
		if remj == rp or remj < rp:
			print(n // k - 1)
		elif remj % rp == 0:
			print(n // k - remj // rp)
		elif remj > rp:
			x = remj // rp
			print(n // k - (x + 1))


import math
for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	if m == 0:
		print(0)
	else:
		d = n // k
		if d >= m:
			print(m)
		else:
			dif = m - d
			play = k - 1
			print(d - math.ceil(dif / play))


import math
t = int(input())
for _ in range(t):
	(n, m, k) = map(int, input().split())
	j = min(n // k, m)
	rem = m - j
	j2 = math.ceil(rem / (k - 1))
	print(j - j2)


import math

def foo(n, m, k):
	if m == 0:
		return 0
	each = n // k
	if each >= m:
		return m
	maxJocker = each
	m -= each
	k -= 1
	n -= each
	return maxJocker - math.ceil(m / k)
for _ in range(int(input())):
	(n, m, k) = [*map(int, input().split())]
	print(foo(n, m, k))


t = int(input())
for x in range(t):
	(n, m, k) = map(int, input().split())
	if m < n / k:
		max = m
	else:
		max = n // k
	if (m - max) % (k - 1) != 0:
		p = (m - max) // (k - 1) + 1
	else:
		p = (m - max) // (k - 1)
	print(max - p)


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	x = b
	if a / c >= b:
		print(b)
	else:
		b = a // c
		s = [b]
		for i in range(c - 1):
			s.append(1)
		while sum(s) < x:
			s[s.index(min(s))] += 1
			b -= 1
		print(max(s) - max(s[1:]))


for t in range(int(input())):
	(n, m, k) = [int(x) for x in input().split()]
	cpp = n // k
	jfp = min([cpp, m])
	m = m - jfp
	rp = [0 for i in range(k - 1)]
	while m:
		for i in range(k - 1):
			rp[i] += 1
			m -= 1
			if m == 0:
				break
	mxj = max(rp)
	ans = jfp - mxj
	print(0) if ans < 0 else print(ans)


for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	per = n // k
	if m <= per:
		print(m)
		continue
	other = 0
	m -= per
	while m > 0:
		other += 1
		m -= k - 1
	print(per - other)


for t in range(int(input())):
	(n, m, k) = map(int, input().split())
	p = n // k
	r = min(m, p)
	if r >= m:
		print(m)
	else:
		d = m - r
		f = d // (k - 1) + int(bool(d % (k - 1)))
		print(r - f)


from math import ceil
arr = []
for k in range(int(input())):
	arr.append([int(k) for k in list(input().split(' '))])
for line in arr:
	(n, m, k) = line
	kolvo_kart = n // k
	if kolvo_kart > m:
		max_kolvo_j = m
		m = 0
	else:
		max_kolvo_j = kolvo_kart
		m = m - kolvo_kart
	print(max_kolvo_j - ceil(m / (k - 1)))


for i in range(int(input())):
	(n, m, k) = map(int, input().split())
	card = n // k
	if m <= card:
		print(m)
	else:
		print(card - ((m - card - 1) // (k - 1) + 1))


for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	each = n // k
	if each >= m:
		print(m)
	else:
		print(each - int(abs((-m + each) // (k - 1))))


import math
from sys import stdin
input = stdin.readline
for _ in range(int(input())):
	(n, m, k) = [int(i) for i in input().split()]
	d = n // k
	w = min(m, d)
	w2 = (m - w + k - 2) // (k - 1)
	print(w - w2)


from math import ceil
t = int(input())
for _ in range(t):
	(n, m, k) = map(int, input().split())
	ans = min(m, int(n / k))
	if m > int(n / k):
		m = m - ans
		ans -= ceil(m / (k - 1))
	print(ans)


t = int(input())
for i in range(t):
	s = input().split()
	n = int(s[0])
	m = int(s[1])
	k = int(s[2])
	if m <= n / k:
		print(m)
		continue
	elif n // k == 1:
		print('0')
		continue
	else:
		p = m - n // k
		q = k - 1
		if p % q == 0:
			print(n // k - p // q)
		else:
			print(n // k - p // q - 1)


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


t = int(input())
while t > 0:
	(n, m, k) = input().split()
	(n, m, k) = (int(n), int(m), int(k))
	(val, ans) = (n // k, 0)
	if m <= val:
		ans = m
	elif (m - val) / (k - 1) == (m - val) // (k - 1):
		ans = val - (m - val) / (k - 1)
	else:
		ans = val - (m - val) // (k - 1) - 1
	print(int(ans))
	t -= 1


t = int(input())
tests = []
for i in range(t):
	tests.append(input())
for test in tests:
	lst = test.split()
	n = int(lst[0])
	m = int(lst[1])
	k = int(lst[2])
	if m == 0:
		max = 0
	else:
		cpp = n // k
		if m <= cpp:
			max = m
		else:
			remjok = m - cpp
			min = remjok // (k - 1)
			if remjok % (k - 1) != 0:
				min += 1
			max = cpp - min
	print(max)


cases = input()
for i in range(0, int(cases)):
	inss = input()
	list = inss.split(' ')
	n = int(list[0])
	m = int(list[1])
	k = int(list[2])
	z = int(n / k)
	x = min(m, z)
	lol = 1
	if (m - z) % (k - 1) == 0 or m <= z:
		lol = 0
	y = max(int((m - z) / (k - 1)) + lol, 0)
	print(x - y)


t = int(input())
for i in range(t):
	(n, jokers, players) = [int(i) for i in input().split()]
	each = int(n / players)
	if each >= jokers:
		print(jokers)
	elif jokers == 0:
		print(0)
	elif jokers > each and each == 1:
		print(0)
	elif jokers > each:
		rem = jokers - each
		l = [0 for f in range(players - 1)]
		while rem > 0:
			for i in range(len(l)):
				l[i] += 1
				rem -= 1
				if rem == 0:
					break
		print(each - max(l))


import math
t = int(input())
ans = []
for i in range(t):
	(n, m, k) = [int(i) for i in input().split()]
	cards = n // k
	if cards >= m:
		ans.append(m)
	else:
		m = m - cards
		k_w = 0
		while True:
			k = k - 1
			k_w += math.floor(m / k)
			m = m - math.floor(m / k) * k
			if m == 0:
				ans.append(cards - k_w)
				break
for i in ans:
	print(i)


def N():
	return int(input())

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

def L():
	return list(NM())

def LN(n):
	return [N() for i in range(n)]

def LL(n):
	return [L() for i in range(n)]
t = N()

def f():
	if n // k >= m:
		print(m)
	else:
		print(n // k - (m - n // k + k - 2) // (k - 1))
for i in range(t):
	(n, m, k) = NM()
	f()


import sys
import math
t = int(sys.stdin.readline())
for x in range(t):
	(n, m, k) = list(map(int, sys.stdin.readline().strip().split(' ')))
	if m > n / k:
		print(int(n / k - math.ceil((m - n / k) / (k - 1))))
	else:
		print(m)


a0 = int(input())
for _ in range(a0):
	(n, m, k) = input().strip().split(' ')
	(n, m, k) = [int(n), int(m), int(k)]
	if m < n // k:
		print(m)
	else:
		r = 0
		new_m = m - n // k
		if new_m % (k - 1) > 0:
			r = 1
		print(n // k - new_m // (k - 1) - r)


t = int(input())
cases = []
for i in range(t):
	cases.append([int(j) for j in input().split()])
for i in range(t):
	n = cases[i][0]
	m = cases[i][1]
	k = cases[i][2]
	get = n // k
	pts = min(m, get)
	m -= pts
	while m > 0:
		m -= k - 1
		pts -= 1
	print(pts)


q = int(input())
for i in range(q):
	(n, m, k) = map(int, input().split())
	ans = 0
	a = n // k
	if a >= m:
		print(m)
	else:
		m -= a
		if m % (k - 1) != 0:
			print(a - (m // (k - 1) + 1))
		else:
			print(a - m // (k - 1))


import math
t = int(input())
cases = []
for i in range(t):
	line = input().split()
	case = [int(i) for i in line]
	cases.append(case)
for case in cases:
	n = case[0]
	m = case[1]
	k = case[2]
	max_jokers = min(n // k, m)
	min_max = math.ceil((m - max_jokers) / (k - 1))
	print(max_jokers - min_max)


from collections import defaultdict as dd
import math
import sys
import string
input = sys.stdin.readline

def nn():
	return int(input())

def li():
	return list(input())

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

def lm():
	return list(map(int, input().split()))
q = nn()
for _ in range(q):
	(n, m, k) = mi()
	j_win = min(n // k, m)
	j_second = (m - j_win + k - 2) // (k - 1)
	print(j_win - j_second)


import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop, heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10 ** 9 + 7
inf = float('inf')

def I():
	return int(sys.stdin.readline())

def LI():
	return list(map(int, sys.stdin.readline().split()))
t = I()
for _ in range(t):
	(n, m, k) = LI()
	s = n // k
	x = min(m, s)
	m = m - x
	tmp = m % (k - 1)
	if tmp != 0:
		ans = x - (m // (k - 1) + 1)
	else:
		ans = x - m // (k - 1)
	print(ans)


t = int(input())
for _ in range(t):
	(n, m, k) = map(int, input().split())
	if m == 0:
		print(0)
	else:
		d = n // k
		if d < m:
			m1 = m - d
			val = m1 // (k - 1)
			if m1 % (k - 1) != 0:
				val += 1
			print(d - val)
		else:
			print(m)


import math
for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	r = min(n // k, m)
	print(r - math.ceil((m - r) / (k - 1)))


def f(n, m, k):
	if m <= n / k:
		return m
	if (m - n / k) / (k - 1) == int((m - n / k) / (k - 1)):
		return int(n / k - (m - n / k) // (k - 1))
	return int(n / k - ((m - n / k) // (k - 1) + 1))
for tc in range(int(input())):
	al = list(map(int, input().split()))
	print(f(al[0], al[1], al[2]))


import math
T = int(input())
for i in range(T):
	(a, b, c) = map(int, input().split())
	epc = a // c
	if epc >= b:
		print(b)
	else:
		cdw = epc
		b = b - cdw
		rpc = math.ceil(b / (c - 1))
		if rpc == cdw:
			print('0')
		else:
			print(abs(rpc - cdw))


tc = int(input())

def solve(n, m, k):
	eachp = n // k
	if m <= eachp:
		return m
	remaining = m - eachp
	if remaining % (k - 1) == 0:
		sub = remaining // (k - 1)
	else:
		sub = remaining // (k - 1) + 1
	return eachp - sub
for _ in range(tc):
	(n, m, k) = map(int, input().split())
	print(solve(n, m, k))


for _ in range(int(input())):
	(cards, jokers, players) = map(int, input().split())
	tmp = cards // players
	if tmp >= jokers:
		ans = jokers
	else:
		winner = tmp
		jokers -= tmp
		players -= 1
		a = jokers // players
		jokers -= a * players
		if jokers > 0:
			a += 1
		ans = winner - a
	if ans < 0:
		print(0)
	else:
		print(ans)


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))

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

def write(*args, end='\n'):
	for x in args[:-1]:
		sys.stdout.write(str(x) + ' ')
	sys.stdout.write(str(args[-1]))
	sys.stdout.write(end)

def r_array():
	return [int(x) for x in input().split()]

def r_int():
	return int(input())

def main():
	for _ in range(int(input())):
		(n, j, k) = map(int, input().split())
		c = n // k
		if j == 0:
			print(0)
		elif c >= j:
			print(j)
		else:
			l = 0
			if (j - c) % (k - 1) != 0:
				l = 1
			print(c - (j - c) // (k - 1) - l)
main()


import sys
input = sys.stdin.readline
from math import ceil

def solve(n, m, k):
	cards_per_player = n / k
	if cards_per_player >= m:
		return m
	else:
		winner_m = cards_per_player
		m -= cards_per_player
		k -= 1
		losers_m_max = ceil(m / k)
		return int(winner_m - losers_m_max)
t = int(input())
for _ in range(t):
	(n, m, k) = map(int, input().split())
	print(solve(n, m, k))


import math
TT = int(input())
for _ in range(TT):
	(n, m, k) = map(int, input().split())
	c = n // k
	x = min(c, m)
	z = m - x
	y = math.ceil(z / (k - 1))
	print(max(0, x - y))


import math
for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	maxc = a // c
	maxs = min(b, maxc)
	other = b - maxs
	print(maxs - math.ceil(other / (c - 1)))


from sys import stdin, setrecursionlimit, stdout
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().rstrip()
res = ['YES', 'NO']
test_case = ii()
while test_case:
	test_case -= 1
	(n, m, k) = mi()
	x = n // k
	if m <= x:
		ans = m
	else:
		mx = ceil((m - x) / (k - 1))
		if mx < x:
			ans = x - mx
		else:
			ans = 0
	print(ans)


import math
t = int(input())
for x in range(t):
	(n, m, k) = map(int, input().split())
	max_jokers = 0
	if m >= n / k:
		max_jokers += n / k
	elif m < n / k:
		max_jokers += m
	second_max_jokers = math.ceil((m - max_jokers) / (k - 1))
	answer = max_jokers - second_max_jokers
	print(round(answer))


t = int(input())
for i in range(t):
	(n, m, k) = map(int, input().split())
	k2 = k
	k = n // k
	k = min(m, k)
	ans = k - (m - k + k2 - 2) // (k2 - 1)
	print(ans)


t = int(input())
for z in range(t):
	(n, m, k) = list(map(int, input().split()))
	no = n // k
	(w, l) = (0, 0)
	if no < m:
		w = no
		l = (m - no) // (k - 1)
		if (m - no) % (k - 1) != 0:
			l += 1
	else:
		w = m
		l = 0
	print(w - l)


t = int(input())
import math
delay = []
for _ in range(t):
	s = input().split()
	n = int(s[0])
	m = int(s[1])
	k = int(s[2])
	cards = n // k
	if m < cards:
		print(m)
	else:
		other = math.ceil((m - cards) / (k - 1))
		if other == cards:
			print(0)
		else:
			print(cards - other)


import math
for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	a = n // k
	if a >= m:
		print(m)
	else:
		d = a
		e = math.ceil((m - a) / (k - 1))
		print(d - e)


import sys
import heapq
import random
import collections
import math

def solve(n, m, k):
	a = n // k
	if a >= m:
		return m
	o = math.ceil((m - a) / (k - 1))
	return a - o

def console(*args):
	print('\x1b[36m', *args, '\x1b[0m', file=sys.stderr)
	return
for case_num in range(int(input())):
	(n, m, k) = list(map(int, input().split()))
	res = solve(n, m, k)
	print(res)


import sys
import os
import heapq
import math
try:
	path = './file/input.txt'
	if os.path.exists(path):
		sys.stdin = open(path, 'r')
except:
	pass
t = int(input())

def printd(value):
	pass
for _ in range(t):
	arr = list(map(int, input().split(' ')))
	(n, m, k) = (arr[0], arr[1], arr[2])
	result = 0
	count = int(n / k)
	if m <= count:
		result = m
	else:
		tmp = m - count
		one = 0 if tmp % (k - 1) == 0 else 1
		result = count - (int(tmp / (k - 1)) + one)
	print(result)


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
from sys import stdin, stdout
import math, queue, heapq
fastinput = stdin.readline
fastout = stdout.write
t = int(fastinput())
while t:
	t -= 1
	(n, m, k) = map(int, fastinput().split())
	eachget = n // k
	if m <= eachget:
		print(m)
	else:
		m -= eachget
		a = 1 if m % (k - 1) != 0 else 0
		print(eachget - m // (k - 1) - a)


import sys
import math
lines = sys.stdin.readlines()
for line in lines[1:]:
	game_info = list(map(int, line.split(' ')))
	cards = game_info[0]
	pokers = game_info[1]
	players = game_info[2]
	if pokers <= int(cards / players):
		print(pokers)
	else:
		max_pokers = int(cards / players)
		pokers_left = pokers - int(cards / players)
		max_other = math.ceil(pokers_left / (players - 1))
		if max_other == max_pokers:
			print(0)
		else:
			print(max_pokers - max_other)


import math
t = int(input())
for test in range(t):
	(a, b, c) = map(int, input().split())
	if b == 0:
		print('0')
	elif b <= a // c:
		print(b)
	else:
		p = a // c
		if (b - p) % (c - 1) == 0:
			print(p - (b - p) // (c - 1))
		else:
			print(p - 1 - (b - p) // (c - 1))


import sys
input = iter(sys.stdin.read().splitlines()).__next__
sys.setrecursionlimit(10000)
TC = int(input())
for tc in range(TC):
	(N, M, K) = map(int, input().split())
	my_jokers = min(N // K, M)
	rem_jokers = M - my_jokers
	max_other_jokers = (rem_jokers + (K - 1 - 1)) // (K - 1)
	res = my_jokers - max_other_jokers
	print(res)


import math
for _ in range(int(input())):
	(n, j, k) = map(int, input().split())
	card = n // k
	if j <= card:
		maxj = j
		print(maxj)
	else:
		maxj = card
		rest = j - card
		otherj = math.ceil(rest / (k - 1))
		print(maxj - otherj)


def rs():
	return input().strip()

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

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

def ia_to_s(a):
	return ' '.join([str(s) for s in a])

def solve(n, m, k):
	d = n // k
	d_max = min(m, d)
	left = m - d_max
	dd = left // (k - 1)
	if left % (k - 1) > 0:
		dd += 1
	return d_max - dd

def main():
	for _ in range(ri()):
		(n, m, k) = ria()
		print(solve(n, m, k))
main()


for i in range(0, int(input())):
	(n, m, k) = list(map(int, input().split()))
	if n // k >= m:
		print(m)
	elif n // k < m:
		q = n // k
		kk = m - q
		p = [0] * (k - 1)
		z = 0
		while kk != 0:
			p[z] = p[z] + 1
			z = z + 1
			if z == k - 1:
				z = 0
			kk = kk - 1
		l = max(p)
		print(q - l)


t = int(input())
for h in range(t):
	(n, m, k) = map(int, input().split())
	p = n // k
	if p >= m:
		print(m)
	else:
		ans = (m - p) // (k - 1)
		if ans * (k - 1) != m - p:
			ans += 1
		if ans < 0:
			print('0')
		else:
			print(p - ans)


import math
m = input()
for i in range(int(m)):
	(n, j, k) = input().split()
	if int(n) / int(k) >= int(j):
		print(j)
	else:
		cards = int(n) / int(k)
		lj = int(j) - cards
		temp1 = float(lj) / float(int(k) - 1)
		temp = math.ceil(temp1)
		print(int(cards - temp))


for lo in range(int(input())):
	(n, m, k) = map(int, input().split())
	if m == 0:
		print(0)
	else:
		x = n // k
		m1 = m
		m = m - x
		k = k - 1
		if m <= 0:
			print(m1)
		else:
			y = m // k
			z = m % k
			if z > 0:
				y += 1
			print(x - y)


t = int(input())
from math import ceil
for case in range(t):
	(n, m, k) = map(int, input().split())
	cards = n // k
	max_jokers = min(cards, m)
	min_jokers = ceil((m - max_jokers) / (k - 1))
	print(max(0, max_jokers - min_jokers))


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	if a // c >= b:
		print(b)
	else:
		m = a // c
		b -= m
		z = b // (c - 1)
		if b % (c - 1) != 0:
			z += 1
		print(m - z)


import sys
readline = sys.stdin.readline
readlines = sys.stdin.readlines
ns = lambda : readline().rstrip()
ni = lambda : int(readline().rstrip())
nm = lambda : map(int, readline().split())
nl = lambda : list(map(int, readline().split()))
prn = lambda x: print(*x, sep='\n')

def solve():
	(n, m, k) = nm()
	if n // k >= m:
		print(m)
		return
	else:
		m -= n // k
		print(n // k - (m - 1) // (k - 1) - 1)
	return
T = ni()
for _ in range(T):
	solve()


from math import ceil
for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	x = min(n // k, m)
	rem = m - x
	y = ceil(rem / (k - 1))
	fans = x - y
	print(fans)


import sys
input = sys.stdin.readline

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

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

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

def invr():
	return map(int, input().split())
t = inp()
for _ in range(t):
	(n, m, k) = invr()
	maxi = min(n // k, m)
	mini = (m - maxi) // (k - 1)
	if (m - maxi) % (k - 1):
		mini += 1
	print(maxi - mini)


import math
T = int(input())
for _ in range(T):
	(n, m, k) = list(map(int, input().split()))
	w = min(m, n // k)
	r = m - w
	v = math.ceil(r / (k - 1))
	ans = w - v
	print(ans)


from sys import stdin
from math import ceil

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

def sinput():
	return input()

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

def linput():
	return list(map(int, stdin.readline().split()))
t = iinput()
while t:
	t -= 1
	(n, m, k) = minput()
	p = min(n // k, m)
	q = ceil((m - p) / (k - 1))
	print(p - q)


import math
t = int(input())
for x in range(t):
	[n, m, k] = list(map(int, input().split()))
	temp = min(m, n // k)
	print(temp - math.ceil((m - temp) / (k - 1)))


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	ave = a // c
	maxi = min(b, ave)
	second = (b - maxi + c - 2) // (c - 1)
	print(maxi - second)


from math import ceil

def fn():
	(n, m, k) = map(int, input().split())
	cpp = n // k
	if m >= cpp:
		wi = cpp
	else:
		wi = m
	rem = m - wi
	return wi - ceil(rem / (k - 1))
for _ in range(int(input())):
	print(fn())


t = int(input())
for _ in range(t):
	(n, m, k) = map(int, input().split())
	if m <= n / k:
		print(m)
		continue
	cards = m - n / k
	p = k - 1
	ans = n / k
	while True:
		if cards <= p:
			ans -= 1
			break
		ans -= cards // p
		cards -= p * (cards // p)
		if cards <= 0:
			break
	print(int(ans))


def solve(n, m, k):
	ans = 0
	cards_pp = round(n / k)
	if m == n:
		ans = 0
	elif m <= cards_pp:
		ans = m
	elif k > 2:
		if (m - cards_pp) % (k - 1) == 0:
			ans = cards_pp - (m - cards_pp) // (k - 1)
		else:
			ans = cards_pp - (m - cards_pp) // (k - 1) - 1
	else:
		ans = cards_pp - (m - cards_pp)
	return ans
t = int(input())
for ___ in range(t):
	(n, m, k) = (int(l) for l in input().split(' '))
	answer = solve(n, m, k)
	print(answer)


for _ in range(int(input())):
	(t, j, k) = map(int, input().split())
	n = t // k
	if j <= n or k == 1:
		print(j)
	else:
		mx = n
		k -= 1
		j -= n
		t -= n
		if j % k == 0:
			print(mx - j // k)
		else:
			print(mx - j // k - 1)


import math
N = int(input())
for i in range(N):
	(n, m, k) = input().split()
	(total, jokers, players) = (int(n), int(m), int(k))
	if jokers < 1:
		print(0)
		continue
	in_hand = total // players
	if jokers > in_hand:
		remaining_jokers = jokers - in_hand
		if remaining_jokers > (players - 1) * (in_hand - 1):
			print(0)
		else:
			second_most = math.ceil(remaining_jokers / (players - 1))
			print(in_hand - second_most)
	else:
		print(jokers)


def solve(n, j, k):
	crd = n // k
	if j <= crd:
		return j
	nm = j - crd
	k -= 1
	return crd - (nm // k + int(bool(nm % k)))

def main():
	t = int(input())
	ans = [0] * t
	for i in range(t):
		(n, j, k) = [int(i) for i in input().split()]
		ans[i] = solve(n, j, k)
	print('\n'.join(map(str, ans)))
main()


from math import ceil

def prog():
	for _ in range(int(input())):
		(n, m, k) = map(int, input().split())
		if n // k >= m:
			print(m)
		else:
			most = n // k
			m -= most
			next_most = ceil(m / (k - 1))
			print(most - next_most)
prog()


import math
turns = int(input())
for _ in range(turns):
	(n, m, k) = [int(x) for x in input().split()]
	rest_joker = m - n / k
	if rest_joker <= 0:
		print(m)
		continue
	max_rest_joker = math.ceil(rest_joker / (k - 1))
	print(int(n / k - max_rest_joker))


import math
t = int(input())
for _ in range(t):
	(n, m, k) = list(map(int, input().split()))
	qty_cards = n / k
	if qty_cards >= m:
		print(m)
	else:
		max_value = qty_cards
		rest = m - max_value
		k -= 1
		check = math.ceil(rest / k)
		print(int(max_value - check))


import sys
import math
try:
	sys.stdin = open('Input.txt', 'r')
	sys.stdout = open('Output.txt', 'w')
except:
	pass
input = sys.stdin.readline
for testCases in range(int(input())):
	(n, m, k) = map(int, input().split())
	if m <= n // k:
		print(m)
	else:
		rest = m - n // k
		rest = math.ceil(rest / (k - 1))
		print(n // k - rest)


t = int(input())
for _ in range(t):
	(n, m, k) = [int(s) for s in input().split()]
	r = m - n // k
	if r <= 0:
		r = 0
	elif r % (k - 1) > 0:
		r //= k - 1
		r += 1
	else:
		r //= k - 1
	print(min(m, n // k) - r)


for _ in range(int(input())):
	(n, m, k) = list(map(int, input().split()))
	if n // k >= m:
		print(m)
	else:
		num = (m - n // k + k - 2) // (k - 1)
		print(max(n // k - num, 0))


import math
t = int(input())
while t:
	(n, m, k) = map(int, input().split())
	a = n // k
	if k == 1:
		print(min(n, m))
	elif m == 0:
		print(0)
	elif a >= m:
		print(m)
	else:
		b = m - a
		c = math.floor(b / (k - 1))
		c1 = b % (k - 1)
		if c1 > 0:
			c1 = 1
		print(a - (c1 + c))
	t -= 1


test_case = int(input())
for _ in range(test_case):
	(n, m, k) = [int(b) for b in input().split()]
	a = int(n / k)
	if a >= m:
		print(m)
	elif (m - a) % (k - 1) == 0:
		print(a - int((m - a) / (k - 1)))
	else:
		print(a - int((m - a) / (k - 1)) - 1)


import math
t = int(input())
for i in range(t):
	(n, m, k) = map(int, input().split())
	max = n / k
	if max > m:
		print(m)
		continue
	else:
		a = math.ceil((m - max) / (k - 1))
		print(int(max - a))


from math import *

def solve():
	(n, m, k) = map(int, input().split())
	hcg = min(n / k, m)
	sm = ceil(float(m - hcg) / (k - 1))
	sm = min(sm, n / k)
	print(int(hcg - sm))
t = int(input())
for loop in range(t):
	solve()


import sys
for t in range(int(input())):
	(n, m, k) = map(int, sys.stdin.readline().strip().split())
	p = n // k
	if p >= m:
		print(m)
	else:
		temp = (m - p) // (k - 1)
		if (m - p) % (k - 1) != 0:
			temp += 1
		print(p - temp)


def ceil(x):
	y = int(x)
	return y + int(x != y)

def que_41():
	for t in range(int(input())):
		(total_cards, jokers, players) = map(int, input().split())
		cards_per_player = total_cards // players
		max_jokers_for_winner = min(jokers, cards_per_player)
		remaining_jokers = max(0, jokers - max_jokers_for_winner)
		min_jokers_for_others = ceil(remaining_jokers / (players - 1))
		print(max_jokers_for_winner - min_jokers_for_others)
que_41()


from math import ceil, sqrt, log2, floor, pi
for _ in range(int(input())):
	(N, M, K) = map(int, input().split())
	MaxJoker = min(int(N / K), M)
	RemainingJoker = M - MaxJoker
	A = int(ceil(RemainingJoker / (K - 1)))
	print(MaxJoker - A)


import math
for i in range(int(input())):
	(n, m, k) = map(int, input().split())
	if n // k == 1 and m != 1 or m == 0:
		print(0)
	elif n // k >= m or n // k == 1:
		print(m)
	elif n // k < m:
		t1 = n // k
		t2 = math.ceil((m - n // k) / (k - 1))
		print(t1 - t2)


for i in range(int(input())):
	(n, m, k) = map(int, input().split())
	n //= k
	if m == 0 or (n == 1 and m != 1):
		print(0)
	elif m <= n:
		print(m)
	else:
		m -= n
		k -= 1
		if m % k == 0:
			print(n - m // k)
		else:
			print(n - m // k - 1)


t = int(input())
for _ in range(t):
	(n, m, k) = map(int, input().split())
	if m <= n // k:
		print(m)
	else:
		ans = n // k
		m -= ans
		k -= 1
		if m / k == m // k:
			ans -= m // k
		else:
			ans -= m // k + 1
		print(ans)


def solve():
	(n, m, k) = list(map(lambda x: int(x), input().split()))
	if m <= n / k:
		return m
	rem_ = m - n // k
	dist = rem_ / (k - 1)
	return n // k - int(dist) if dist == int(dist) else n // k - int(dist + 1)
cases = int(input())
ans = []
for case in range(cases):
	ans.append(solve())
for el in ans:
	print(el)


from math import ceil, floor
t = int(input())
for _ in range(t):
	(n, m, k) = tuple((int(x) for x in input().split()))
	if m <= n / k:
		print(m)
	else:
		point = floor(n / k) - ceil((m - floor(n / k)) / (k - 1))
		print(0 if point <= 0 else point)


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

def Golf():
	(n, *t) = map(int, open(0).read().split())

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

def S_():
	return input()

def IS():
	return input().split()

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

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

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

def NI(n):
	return [int(input()) for i in range(n)]

def NI_(n):
	return [int(input()) - 1 for i in range(n)]

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

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

def LtoS(ls):
	return ''.join([chr(i + 97) for i in ls])

def RA():
	return map(int, open(0).read().split())

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

def GGI(h, w, search=None, replacement_of_found='.', mp_def={'#': 1, '.': 0}, boundary=1):
	mp = [boundary] * (w + 2)
	found = {}
	for i in range(h):
		s = input()
		for char in search:
			if char in s:
				found[char] = (i + 1) * (w + 2) + s.index(char) + 1
				mp_def[char] = mp_def[replacement_of_found]
		mp += [boundary] + [mp_def[j] for j in s] + [boundary]
	mp += [boundary] * (w + 2)
	return (h + 2, w + 2, mp, found)

def TI(n):
	return GI(n, n - 1)

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

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

def show(*inp, end='\n'):
	if show_flg:
		print(*inp, end=end)
YN = ['YES', 'NO']
Yn = ['Yes', 'No']
mo = 10 ** 9 + 7
inf = float('inf')
FourNb = [(-1, 0), (1, 0), (0, 1), (0, -1)]
EightNb = [(-1, 0), (1, 0), (0, 1), (0, -1), (1, 1), (-1, -1), (1, -1), (-1, 1)]
compas = dict(zip('WENS', FourNb))
cursol = dict(zip('LRUD', FourNb))
l_alp = string.ascii_lowercase
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
input = lambda : sys.stdin.readline().rstrip()

class Tree:

	def __init__(self, inp_size=None, ls=None, init=True, index=0):
		self.LCA_init_stat = False
		self.ETtable = []
		if init:
			if ls == None:
				self.stdin(inp_size, index=index)
			else:
				self.size = len(ls) + 1
				(self.edges, _) = GI(self.size, self.size - 1, ls, index=index)
		return

	def stdin(self, inp_size=None, index=1):
		if inp_size == None:
			self.size = int(input())
		else:
			self.size = inp_size
		(self.edges, _) = GI(self.size, self.size - 1, index=index)
		return

	def listin(self, ls, index=0):
		self.size = len(ls) + 1
		(self.edges, _) = GI(self.size, self.size - 1, ls, index=index)
		return

	def __str__(self):
		return str(self.edges)

	def dfs(self, x, func=lambda prv, nx, dist: prv + dist, root_v=0):
		q = deque()
		q.append(x)
		v = [-1] * self.size
		v[x] = root_v
		while q:
			c = q.pop()
			for (nb, d) in self.edges[c]:
				if v[nb] == -1:
					q.append(nb)
					v[nb] = func(v[c], nb, d)
		return v

	def EulerTour(self, x):
		q = deque()
		q.append(x)
		self.depth = [None] * self.size
		self.depth[x] = 0
		self.ETtable = []
		self.ETdepth = []
		self.ETin = [-1] * self.size
		self.ETout = [-1] * self.size
		cnt = 0
		while q:
			c = q.pop()
			if c < 0:
				ce = ~c
			else:
				ce = c
				for (nb, d) in self.edges[ce]:
					if self.depth[nb] == None:
						q.append(~ce)
						q.append(nb)
						self.depth[nb] = self.depth[ce] + 1
			self.ETtable.append(ce)
			self.ETdepth.append(self.depth[ce])
			if self.ETin[ce] == -1:
				self.ETin[ce] = cnt
			else:
				self.ETout[ce] = cnt
			cnt += 1
		return

	def LCA_init(self, root):
		self.EulerTour(root)
		self.st = SparseTable(self.ETdepth, init_func=min, init_idl=inf)
		self.LCA_init_stat = True
		return

	def LCA(self, root, x, y):
		if self.LCA_init_stat == False:
			self.LCA_init(root)
		(xin, xout) = (self.ETin[x], self.ETout[x])
		(yin, yout) = (self.ETin[y], self.ETout[y])
		a = min(xin, yin)
		b = max(xout, yout, xin, yin)
		id_of_min_dep_in_et = self.st.query_id(a, b + 1)
		return self.ETtable[id_of_min_dep_in_et]

class SparseTable:

	def __init__(self, ls, init_func=min, init_idl=float('inf')):
		self.func = init_func
		self.idl = init_idl
		self.size = len(ls)
		self.N0 = self.size.bit_length()
		self.table = [ls[:]]
		self.index = [list(range(self.size))]
		self.lg = [0] * (self.size + 1)
		for i in range(2, self.size + 1):
			self.lg[i] = self.lg[i >> 1] + 1
		for i in range(self.N0):
			tmp = [self.func(self.table[i][j], self.table[i][min(j + (1 << i), self.size - 1)]) for j in range(self.size)]
			tmp_id = [self.index[i][j] if self.table[i][j] == self.func(self.table[i][j], self.table[i][min(j + (1 << i), self.size - 1)]) else self.index[i][min(j + (1 << i), self.size - 1)] for j in range(self.size)]
			self.table += [tmp]
			self.index += [tmp_id]

	def query(self, l, r):
		if r > self.size:
			r = self.size
		N = self.lg[r - l]
		return self.func(self.table[N][l], self.table[N][max(0, r - (1 << N))])

	def query_id(self, l, r):
		if r > self.size:
			r = self.size
		N = self.lg[r - l]
		(a, b) = (self.index[N][l], self.index[N][max(0, r - (1 << N))])
		if self.table[0][a] == self.func(self.table[N][l], self.table[N][max(0, r - (1 << N))]):
			b = a
		return b

	def __str__(self):
		return str(self.table[0])

	def print(self):
		for i in self.table:
			print(*i)
show_flg = False
show_flg = True
ans = 0

def solve():
	return
T = I()
for _ in range(T):
	(n, m, k) = LI()
	d = min(m, n // k)
	k -= 1
	a = (m - d + k - 1) // k
	ans = d - max(0, a)
	print(ans)


t = int(input())
for i in range(t):
	(n, m, k) = map(int, input().split())
	comm = n // k
	count = [0] * k
	if comm >= m:
		print(m)
	else:
		first = comm
		temp = (m - first) // (k - 1)
		if (m - first) % (k - 1):
			temp += 1
		print(comm - temp)


import math
t = int(input())
for z in range(t):
	(n, m, k) = [int(i) for i in input().split()]
	nce = n / k
	if nce >= m:
		print(m)
	else:
		maxx = nce
		print(int(maxx - math.ceil((m - maxx) / (k - 1))))


t = int(input())
for i in range(t):
	(n, m, k) = map(int, input().split(' '))
	if m == 0:
		print('0')
	elif n // k >= m:
		print(m)
	else:
		a = n // k
		s = 0
		for i in range(a + 1):
			if i * (k - 1) >= m - a:
				s += i
				break
		print(a - s)


t = int(input())
for i in range(t):
	nmk = input()
	nmk = nmk.split()
	n = int(nmk[0])
	m = int(nmk[1])
	k = int(nmk[2])
	if m == 0:
		print(0)
	elif n / k >= m:
		print(m)
	elif m > n / k:
		if (m - n / k) % (k - 1) == 0:
			print(n // k - (m - n // k) // (k - 1))
		else:
			print(n // k - (m - n // k) // (k - 1) - 1)


import math
tc = int(input())
while tc:
	(n, m, k) = map(int, input().split(' '))
	tc -= 1
	cards_per_member = n // k
	if m <= cards_per_member:
		print(m)
	elif m / cards_per_member >= 1:
		print(cards_per_member - math.ceil((m - cards_per_member) / (k - 1)))
	else:
		print(cards_per_member)


n = int(input())
for i in range(n):
	(n, m, k) = map(int, input().split())
	x = min(m, int(n / k))
	y = int((m - x) / (k - 1)) + ((m - x) % (k - 1) != 0)
	print(x - y)


from math import ceil
for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	myjoker = min(m, n // k)
	if myjoker == m:
		print(m)
		continue
	rem = m - myjoker
	ans = myjoker - ceil(rem / (k - 1))
	print(ans)


t = int(input())
for _ in range(t):
	(n, m, k) = map(int, input().split())
	p = n // k
	cards = []
	tmp_card = min(m, p)
	m -= tmp_card
	cards.append(tmp_card)
	i = 0
	opp = [0] * (k - 1)
	while m != 0:
		idx = i % (k - 1)
		opp[idx] += 1
		i += 1
		m -= 1
	print(cards[0] - max(opp))


inp = input
for _ in range(int(inp())):
	(n, m, k) = map(int, inp().strip().split(' '))
	if m == 0 or n == 0:
		print(0)
		continue
	if k == 1:
		print(m)
		continue
	each = min(n // k, m)
	if m <= each:
		print(each)
		continue
	fir = each
	rem = m - each
	rget = rem // (k - 1)
	if rem % (k - 1) == 0:
		print(each - rget)
	else:
		print(each - rget - 1)


T = int(input())
for i in range(T):
	(n, m, k) = [int(i) for i in input().split()]
	if n // k >= m:
		print(m)
	else:
		rem = m - n // k
		print(n // k - rem // (k - 1) - (rem % (k - 1) != 0))


import math
num_cases = int(input())
for _ in range(num_cases):
	li = input().strip().split()
	(n, m, k) = [int(i) for i in li]
	card_pp = int(n / k)
	winning_player = min(card_pp, m)
	next_player = math.ceil((m - winning_player) / (k - 1))
	print(winning_player - next_player)


t = int(input())
for i in range(t):
	(n, m, k) = map(int, input().split())
	if m <= n / k:
		print(m)
		continue
	first = int(n / k)
	m -= int(n / k)
	if m % (k - 1) == 0:
		second = int(m / (k - 1))
	else:
		second = int(m / (k - 1)) + 1
	print(first - second)


def f(n, m, k):
	if m <= n // k:
		return m
	else:
		a = n // k
		b = m - a
		x = b / (k - 1)
		y = b // (k - 1)
		if x - y == 0:
			return a - y
		else:
			return a - y - 1
t = int(input())
for i in range(t):
	[n, m, k] = input().split(' ')
	print(f(int(n), int(m), int(k)))


import math
n = int(input())
for w in range(n):
	(a, b, c) = map(int, input().split())
	if a == 0 or b == 0 or c == 0:
		print(0)
	else:
		m1 = -100000
		m2 = 0
		l = [0] * (c - 1)
		if b > a // c:
			b = b - a // c
			m2 = a // c
			while b > 0:
				for j in range(c - 1):
					if b > 0:
						l[j] = l[j] + 1
						b -= 1
					else:
						break
			for i in range(c - 1):
				if l[i] > m1:
					m1 = l[i]
			if m2 == m1:
				print(0)
			elif m1 == -100000:
				print(0)
			else:
				print(m2 - m1)
		else:
			m2 = b
			for i in range(c - 1):
				if l[i] > m1:
					m1 = l[i]
			if m2 == m1:
				print(0)
			elif m1 == -100000:
				print(0)
			else:
				print(m2 - m1)


import os
import sys
if os.path.exists('/mnt/c/Users/Square/square/codeforces'):
	f = iter(open('A.txt').readlines())

	def input():
		return next(f)
else:
	input = lambda : sys.stdin.readline().strip()
fprint = lambda *args: print(*args, flush=True)
t = int(input())
for _ in range(t):
	(n, m, k) = map(int, input().split())
	r = n // k
	a = min(r, m)
	m -= a
	b = (m + (k - 2)) // (k - 1)
	print(a - b)


from sys import stdin
input = stdin.readline

def main():
	test = int(input())
	for _ in range(test):
		count = 0
		s = set()
		l = [int(i) for i in input().split(' ')]
		n = l[0]
		m = l[1]
		k = l[2]
		c = n // k
		d = min(c, m)
		if d == m:
			print(d)
		else:
			rem = m - c
			v = rem // (k - 1)
			if rem % (k - 1) == 0:
				print(c - v)
			else:
				print(c - v - 1)
main()


t = int(input())
for i in range(t):
	(n, m, k) = map(int, input().split())
	if m == 0:
		print(0)
		continue
	cards = int(n / k)
	if cards >= m:
		print(m)
		continue
	rem = m - cards
	if rem % (k - 1) == 0:
		val = int(rem / (k - 1))
	else:
		val = int(rem / (k - 1)) + 1
	print(cards - val)


import math
t = int(input())
while t:
	t -= 1
	(n, m, k) = map(int, input().split())
	a = min(m, n // k)
	b = m - a
	k -= 1
	c = math.ceil(b / k)
	print(a - c)


T = int(input())
for _ in range(T):
	(n, m, k) = map(int, input().split())
	x = n // k
	if m <= x:
		print(m)
	elif (m - x) % (k - 1) == 0:
		y = (m - x) // (k - 1)
		print(x - y)
	else:
		y = (m - x) // (k - 1) + 1
		print(x - y)


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 ** 19
MOD = 10 ** 9 + 7
for _ in range(INT()):
	(N, M, K) = MAP()
	eachcnt = N // K
	if M <= eachcnt:
		print(M)
	else:
		x = eachcnt
		remain = M - eachcnt
		y = ceil(remain, K - 1)
		print(x - y)


from math import sqrt
t = int(input())
for q in range(0, t):
	(n, m, k) = list(map(int, input().split()))
	if m <= n // k:
		print(m)
	elif (m - n // k) % (k - 1) == 0:
		print(n // k - (m - n // k) // (k - 1))
	else:
		print(n // k - (m - n // k) // (k - 1) - 1)


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

def solve():
	[cards, jokers, players] = inp()
	if jokers == 0:
		return 0
	if cards == jokers:
		return 0
	lucky_player = cards // players
	if jokers <= lucky_player:
		return jokers
	jokers -= lucky_player
	if jokers % (players - 1) == 0:
		return lucky_player - jokers // (players - 1)
	return lucky_player - 1 - jokers // (players - 1)
[tests] = inp()
for _ in range(tests):
	print(solve())


import math

def solve():
	(n, m, k) = map(int, input().split())
	cards = n // k
	maxJoker = min(m, cards)
	minJoker = math.ceil((m - maxJoker) / (k - 1))
	print(maxJoker - minJoker)
for _ in range(int(input())):
	solve()


q = int(input())
for _ in range(q):
	(n, m, k) = map(int, input().split())
	player = n // k
	jok_pla = min(n // k, m)
	jok_re = m - jok_pla
	maksi = (jok_re + k - 2) // (k - 1)
	print(jok_pla - maksi)


from sys import stdin
input = stdin.readline
INF = 10 ** 9 + 7
MAX = 10 ** 7 + 7
MOD = 10 ** 9 + 7
for Ti in range(int(input().strip())):
	(n, m, k) = [int(x) for x in input().strip().split()]
	pc = n // k
	x = min(pc, m)
	m -= x
	y = m // (k - 1)
	y += 1 if m % (k - 1) else 0
	print(x - y)


t = int(input())
import math
for i in range(t):
	(n, m, k) = map(int, input().strip().split())
	q = int(n / k)
	count = 0
	if m <= q:
		print(m)
	elif n == m:
		print(0)
	else:
		f = int(math.ceil((m - q) / (k - 1)))
		print(q - f)


import math
text = [*open(0)]
for s in text[1:]:
	(n, m, k) = map(int, s.strip().split())
	if m == 0:
		print(0)
	elif m <= n // k:
		print(m)
	else:
		a = n // k
		m -= a
		if m // (k - 1) < 0:
			print(a - 1)
		else:
			print(a - math.ceil(m / (k - 1)))


from math import ceil

def poker(n, m, k):
	if n // k >= m:
		return m
	elif m > n // k:
		return n // k - ceil((m - n // k) / (k - 1))
	elif m == 1:
		return 1
	else:
		return 0
t = int(input())
for s in range(0, t):
	arr = list(map(int, input().strip().split()))
	print(poker(arr[0], arr[1], arr[2]))


q = int(input())
for _ in range(q):
	(n, m, k) = list(map(int, input().split(' ')))
	if m <= n // k:
		print(m)
	else:
		temp = n // k
		ans = (m - temp) // (k - 1)
		if (m - temp) % (k - 1) != 0:
			ans += 1
		ans = temp - ans
		print(ans)


from math import ceil, floor
x = int(input())
for pp in range(x):
	(card, joker, total) = map(int, input().split())
	max_ = card // total
	if max_ >= joker:
		print(joker)
		continue
	else:
		total -= 1
		joker -= max_
		ans = joker / total
		if ceil(ans) == floor(ans):
			ans = int(ans)
		else:
			ans = floor(ans) + 1
		print(max_ - ans)


t = int(input())
while t:
	ans = 0
	(x, y, z) = input().split()
	x = int(x)
	y = int(y)
	z = int(z)
	if x // z > y:
		ans = y
	else:
		y -= x // z
		if y % (z - 1) == 0:
			ans = x // z - y // (z - 1)
		else:
			ans = x // z - (y // (z - 1) + 1)
	print(ans)
	t -= 1


def main_function():
	from sys import stdin
	from sys import stdout
	from math import ceil
	input = stdin.readline
	print = stdout.write
	for _ in range(int(input())):
		(n, m, k) = map(int, input().split())
		if m <= n // k:
			print(f'{m}\n')
		else:
			print(f'{n // k - int(ceil((m - n // k) / (k - 1)))}\n')
main_function()


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()]
t = int(input())
for q in range(t):
	(n, m, k) = inputnums()
	if n // k > m:
		print(m)
	else:
		m -= n // k
		left = math.ceil(m / (k - 1))
		print(n // k - left)


from sys import stdin, stdout
t = int(stdin.readline())
for _ in range(t):
	(n, m, k) = map(int, stdin.readline().strip().split())
	Z = n // k
	x = min(Z, m)
	y = max(0, m - x)
	print(x + -y // (k - 1))


t = int(input())
for _ in range(t):
	(n, m, k) = map(int, input().split())
	x = min(n // k, m)
	r = m - x
	y = 0
	while r > 0:
		r -= k - 1
		y += 1
	print(x - y)


def printPartition(n, m):
	k = int(n / m)
	partition = []
	ct = n % m
	for i in range(1, ct + 1, 1):
		partition.append(k + 1)
	count = ct
	for i in range(count, m, 1):
		partition.append(k)
	return max(partition)
t = int(input())
n_list = []
k_list = []
m_list = []
for i in range(t):
	(n, m, k) = (int(x) for x in input().split())
	n_list.append(n)
	m_list.append(m)
	k_list.append(k)
for i in range(t):
	each_card = n_list[i] // k_list[i]
	if not m_list[i]:
		print(0)
	elif each_card > m_list[i]:
		print(m_list[i])
	else:
		print(each_card - printPartition(m_list[i] - each_card, k_list[i] - 1))


import math
T = int(input())
for t in range(T):
	(n, m, k) = map(int, input().strip().split())
	ncard = n / k
	winj = min(ncard, m)
	remj = m - winj
	maxlj = math.ceil(remj / (k - 1))
	maxpts = winj - maxlj
	print(int(maxpts))


from math import ceil
t = int(input())
for _ in range(t):
	s = input()
	(n, m, k) = map(int, s.split())
	c = n / k
	if m < 2 or c >= m:
		print(m)
	elif n == m or c == 1:
		print(0)
	else:
		j = m - c
		ans = int(c - ceil(j / (k - 1)))
		print(ans)


import math
for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	if m == 0:
		print(0)
	else:
		a = n // k
		if a >= m:
			print(m)
		else:
			b = math.ceil((m - a) / (k - 1))
			print(a - b)


import math
rr = lambda : input().strip()
rrm = lambda : map(int, rr().split())
T = int(rr())
for _ in range(T):
	(n, m, k) = rrm()
	ea = n // k
	ans = 0
	if ea >= m:
		ans = m
	else:
		dif = m - ea
		y = math.ceil(dif / (k - 1))
		ans = ea - y
	print(ans)


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 = pow(10, 9) + 7

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, m, k) = sep()
	c = n // k
	if m <= c:
		print(m)
	elif m == n:
		print(0)
	else:
		m -= c
		k -= 1
		print(c - ceil(m / k))
testcase(int(inp()))


import math

def task(n, m, k):
	hand = n // k
	handbest = min(hand, m)
	otherbest = int(math.ceil((m - handbest) / (k - 1)))
	best = handbest - otherbest
	print(best)
t = int(input())
for i in range(0, t):
	(n, m, k) = map(int, input().split())
	task(n, m, k)


import math
for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	card = n // k
	n1 = min(card, m)
	n2 = (m - n1 + k - 2) // (k - 1)
	print(n1 - n2)


numberTest = int(input())
for i in range(0, numberTest):
	(cards, jokers, players) = [int(i) for i in input().split()]
	cardForPlayers = cards / players
	if jokers > cardForPlayers:
		restanteJokers = jokers - cardForPlayers
		restantePlayers = players - 1
		restante = restanteJokers / restantePlayers
		result = cardForPlayers - restante
		print(int(result))
	else:
		print(int(jokers))


for tc in range(int(input())):
	(n, m, k) = map(int, input().split())
	z = n // k
	x = min(z, m)
	m = m - x
	k = k - 1
	y = m // k
	if m % k:
		y += 1
	print(x - y)


import math
for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	if m == 0:
		print(0)
		continue
	e = n // k
	if e >= m:
		print(m)
		continue
	remai = m - e
	kk = k - 1
	t = math.ceil(remai / kk)
	print(e - t)


for a in range(int(input())):
	(n, m, k) = map(int, input().split())
	b = n // k
	if m == 0:
		print(0)
		continue
	elif m <= b:
		print(m)
		continue
	else:
		tmp = (m - b) // (k - 1)
		if (m - b) % (k - 1) != 0:
			tmp += 1
		print(b - tmp)


import sys
from math import ceil, sqrt, sin, pi, tan
from collections import defaultdict
read = sys.stdin.buffer.readline
import heapq
mi = lambda : map(int, read().split())
li = lambda : list(mi())
cin = lambda : int(read())

def isp(n):
	i = 2
	while i * i <= n:
		if n % i == 0:
			return False
		i += 1
	return True
primes = []

def ps(sm):
	if sm < 0:
		return 1
	sq = int(sqrt(sm))
	if sq * sq == sm:
		return 0
	return 1

def check(s, d):
	for el in s:
		if int(el) in d:
			return False
	return True
import math

def nCr(n, r):
	f = math.factorial
	return f(n) / f(r) / f(n - r)
for _t in range(cin()):
	(n, m, k) = mi()
	d = n // k
	nc = min(d, m)
	rem = m - nc
	print(nc - ceil(rem / (k - 1)))


t = int(input())
ans = []
for i in range(t):
	(n, m, k) = map(int, input().split())
	a = int(n / k)
	if m <= a:
		ans.append(m)
	else:
		y = int((m - a) / (k - 1))
		if (m - a) % (k - 1) == 0:
			ans.append(a - y)
		else:
			ans.append(a - y - 1)
for item in ans:
	print(item)


import math
t = int(input())
for _ in range(t):
	(n, m, k) = map(int, input().split())
	if n // k >= m:
		print(m)
	else:
		num = n // k
		m = m - num
		ans = num - math.ceil(m / (k - 1))
		print(ans)


from sys import stdin
input = lambda : stdin.readline().strip()
from math import ceil, sqrt, factorial, gcd
t = int(input())
for _ in range(t):
	(n, m, k) = map(int, input().split())
	ma = min(n // k, m)
	m -= ma
	print(ma - ceil(m / (k - 1)))


for _ in range(int(input())):
	(n, m, k) = list(map(int, input().split()))
	cardsPerPlayer = n // k
	x = min(cardsPerPlayer, m)
	m -= x
	print(x - (m + k - 2) // (k - 1))


import math
t = int(input())
for tc in range(t):
	(n, m, k) = input().split()
	(n, m, k) = (int(n), int(m), int(k))
	if n / k >= m:
		ans = m
	else:
		ans = int(n / k - math.ceil((m - n / k) / (k - 1)))
	print(ans)


t = int(input())
while t > 0:
	t -= 1
	(n, m, k) = map(int, input().split())
	if m == 0:
		print(0)
	else:
		cpp = n // k
		if cpp >= m:
			print(m)
		else:
			tp = (m - cpp) // (k - 1)
			r = (m - cpp) % (k - 1)
			if cpp - tp - min(r, 1) >= 0:
				print(cpp - tp - min(r, 1))
			else:
				print(0)


t = int(input())
for i in range(t):
	(n, m, k) = map(int, input().split())
	mxj = min(m, n // k)
	m -= mxj
	if m % (k - 1) != 0:
		mnj = m // (k - 1) + 1
	else:
		mnj = m // (k - 1)
	print(mxj - mnj)


import sys
import math
import heapq

def I():
	return int(sys.stdin.readline())

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

def ILS():
	return list(map(str, sys.stdin.readline().strip().split()))
t = I()
for tt in range(t):
	(n, m, k) = IL()
	res = min(n // k, m)
	ot = int(math.ceil((m - res) / (k - 1)))
	print(res - ot)


for i in range(int(input())):
	(n, m, k) = map(int, input().split())
	if n // k >= m:
		x = m
		y = 0
	else:
		x = n // k
		y = (m - x) // (k - 1)
		if (m - x) % (k - 1) != 0:
			y += 1
	print(x - y)


for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	if m - n // k <= 0:
		print(m)
	else:
		m = m - n // k
		j1 = n // k
		j2 = m // (k - 1)
		if m % (k - 1) != 0:
			j2 += 1
		print(j1 - j2)


from math import ceil

def solve():
	(n, m, k) = map(int, input().split())
	if m <= n // k:
		print(m)
	else:
		print(n // k - ceil((m - n // k) / (k - 1)))
for cnt in range(int(input())):
	solve()


l = int(input())
for i in range(l):
	(n, m, k) = input().split()
	(n, m, k) = (int(n), int(m), int(k))
	cpp = n // k
	if m <= cpp:
		print(m)
	else:
		max = (m - cpp) // (k - 1)
		if (m - cpp) % (k - 1) != 0:
			max += 1
		print(cpp - max)


for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	noc = n // k
	if noc >= m:
		print(m)
	else:
		l = m - noc
		lst = [0 for i in range(k - 1)]
		i = 0
		while l > 0:
			lst[i] += 1
			i = (i + 1) % (k - 1)
			l -= 1
		print(noc - max(lst))


def ceildiv(a, b):
	return -(-a // b)
t = int(input())
for i in range(t):
	(n, m, k) = input().split()
	(n, m, k) = (int(n), int(m), int(k))
	if n / k >= m:
		points = m
	else:
		points = int(n / k - ceildiv(m - n / k, k - 1))
	print(points)


import math

def main():
	t = int(input())
	for i in range(t):
		(n, m, k) = map(int, input().split())
		if m == 0:
			print(0)
		else:
			eve = n / k
			if m < eve:
				print(m)
			else:
				m = m - eve
				k -= 1
				ans = int(math.ceil(m / k))
				print(int(eve - ans))
main()


import math

def main():
	t = int(input())
	for _ in range(t):
		(n, m, k) = [int(x) for x in input().split()]
		my_jokers = min(n // k, m)
		remaining_jokers = m - my_jokers
		min_others = math.ceil(remaining_jokers / (k - 1))
		print(my_jokers - min_others)
main()


import sys, math
t = int(input())
for _ in range(t):
	(n, m, k) = map(int, input().split())
	mm = min(m, n // k)
	m -= mm
	print(mm - math.ceil(m / (k - 1)))


t = int(input())
z = t
a = list()
ans = list()
while z > 0:
	str1 = input()
	a = str1.split()
	n = int(a[0])
	m = int(a[1])
	k = int(a[2])
	if n / k >= m:
		ans.append(m)
	else:
		u = n / k
		m = m - n / k
		k = k - 1
		if k == 1:
			ans.append(u - m)
		elif m > k:
			m = m - k
			u = u - 1
			while m > k:
				m = m - k
				u = u - 1
			ans.append(u - 1)
		else:
			ans.append(u - 1)
	z = z - 1
for r in ans:
	print(int(r))


for t in range(int(input())):
	(n, m, k) = map(int, input().split())
	each = n // k
	jokerMax = min(each, m)
	rem = m - jokerMax
	jokerMin = rem // (k - 1)
	if rem % (k - 1):
		jokerMin += 1
	print(jokerMax - jokerMin)


import math
for _ in range(int(input())):
	(n, m, k) = list(map(int, input().split()))
	maxi = min(m, n / k)
	maxi2 = math.ceil((m - maxi) / (k - 1))
	print(int(maxi - maxi2))


ll = lambda : list(map(int, input().split()))
s = lambda : input()
v = lambda : map(int, input().split())
ii = lambda : int(input())
import math
for _ in range(int(input())):
	(n, m, k) = v()
	a = n // k
	b = min(m, a)
	m -= b
	if m == 0:
		print(b)
	else:
		print(b - math.ceil(m / (k - 1)))


a = int(input())
for _ in range(a):
	b = input().split()
	c = int(b[0])
	d = int(b[1])
	e = int(b[2])
	f = c // e
	if c - d < e - 1:
		print(0)
	elif d < f:
		print(d)
	else:
		g = d - f
		print(f - (g // (e - 1) + int(g % (e - 1) != 0)))


import math
t = int(input())
for _ in range(t):
	l = list(map(int, input().split()))
	n = l[0]
	m = l[1]
	k = l[2]
	if m == 0 or m == n:
		print(0)
	elif m <= int(n / k):
		print(m)
	else:
		a = math.ceil((m - n // k) / (k - 1))
		print(int(n / k - a))


t = int(input())
for tt in range(0, t):
	arr = [int(el) for el in input().split(' ')]
	(n, m, k) = arr
	a = int(n / k)
	if a >= m:
		print(m)
	else:
		res = (m - a) % (k - 1)
		if res != 0:
			print(a - int((m - a - res) / (k - 1) + 1))
		else:
			print(a - int((m - a) / (k - 1)))


import math

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

def solve():
	(n, m, k) = list(map(int, input().split(' ')))
	cards_get = n // k
	if cards_get >= m:
		print(m)
	else:
		max_cards = cards_get
		remain = m - cards_get
		print(max_cards - math.ceil(remain / (k - 1)))
main()


from sys import stdin
for t in range(int(input())):
	(n, m, k) = map(int, stdin.readline().split())
	get = n // k
	if get >= m:
		print(m)
	else:
		left = m - get
		smax = left // (k - 1) + int(left % (k - 1) != 0)
		print(get - smax)


import math
from sys import stdin, stdout
mod = 1000000007
t = int(stdin.readline())
while t > 0:
	(n, m, k) = list(map(int, stdin.readline().split()))
	x = n // k
	if x >= m:
		stdout.write(f'{m}\n')
	else:
		ans = x - (m - x) // (k - 1)
		if (m - x) % (k - 1) != 0:
			ans = ans - 1
		stdout.write(f'{ans}\n')
	t -= 1


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

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

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

def invr():
	return map(int, input().split())
import bisect
test_cases = inp()
for i in range(test_cases):
	(N, M, K) = inlt()
	each_person = N / K
	if M <= each_person:
		print(M)
	else:
		big = each_person
		y = (M - big) // (K - 1)
		if M - big > (K - 1) * y:
			y += 1
		print(int(big - y))


import math
t = int(input())
for dud in range(t):
	(n, m, k) = [int(x) for x in input().split()]
	if n / k >= m:
		print(m)
	else:
		print(int(n / k - math.ceil((m - n / k) / (k - 1))))


import math
for i in range(int(input())):
	(n, m, k) = map(int, input().split())
	t1 = int(n / k)
	if t1 >= m:
		print(m)
	else:
		t2 = m - t1
		if t2 >= k - 1:
			if t2 % (k - 1) == 0:
				t3 = t2 / (k - 1)
			else:
				t3 = int(t2 / (k - 1)) + 1
			print(int(t1 - t3))
		else:
			print(t1 - 1)


r = int(input())
for _ in range(r):
	a = list(map(int, input().split()))
	(n, m, k) = (a[0], a[1], a[2])
	each = int(n / k)
	win = min(each, m)
	m -= win
	if m % (k - 1) == 0:
		print(win - int(m / (k - 1)))
	else:
		print(win - int(m / (k - 1)) - 1)


for i in range(int(input())):
	(n, m, k) = map(int, input().split())
	y = n // k
	c = min(y, m)
	if m == 0 or (n == k and m != 1) or n == 0:
		print(0)
	else:
		t = (m - c) / (k - 1)
		r = (m - c) // (k - 1)
		if t % 1 == 0:
			print(c - r)
		else:
			print(c - (r + 1))


import io, sys, atexit, os
import math as ma
from sys import exit
from decimal import Decimal as dec
from itertools import permutations
from itertools import combinations

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

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

def nu():
	return int(input())

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

def lcm(x, y):
	gg = find_gcd(x, y)
	return x * y // gg
mm = 1000000007

def solve():
	t = nu()
	for tt in range(t):
		(n, m, k) = num()
		p = n / k
		x = min(m, p)
		c = max(0, m - x)
		y = max(0, m - x)
		dd = ma.ceil(1.0 * y / (k - 1))
		print(int(x - dd))
solve()


import math
t = int(input())
for _ in range(t):
	(n, m, k) = map(int, input().split())
	if n // k >= m:
		print(m)
	elif n // k < m:
		max = n // k
		rem = m - n // k
		score = max - int(math.ceil(rem / (k - 1)))
		print(score)


import math
t = int(input())
for test in range(t):
	(n, m, k) = [int(x) for x in input().split()]
	cards = n // k
	if m <= cards:
		print(m)
	else:
		jl = m - cards
		minn = int(math.ceil(jl / (k - 1)))
		print(max(cards - minn, 0))


a = int(input())
for i in range(a):
	(n, m, k) = map(int, input().split())
	A = min(m, n // k)
	m = (m - A + k - 2) // (k - 1)
	print(A - m)


t = int(input())
for i in range(t):
	(n, m, k) = list(map(int, input().split()))
	b = n // k
	c = min(b, m)
	d = m - c
	h = k - 1
	e = d // h
	f = d % h
	if f == 0:
		g = e
	else:
		g = e + 1
	print(c - g)


def solve(n, m, k):
	e = n // k
	if m < e:
		return m
	remaining = m - e
	if remaining / (k - 1) > remaining // (k - 1):
		max_r = remaining // (k - 1) + 1
	else:
		max_r = remaining // (k - 1)
	return e - max_r

def read():
	t = int(input())
	for i in range(t):
		(n, m, k) = list(map(int, input().strip().split()))
		ans = solve(n, m, k)
		print(ans)
read()


def calc(n, m, k):
	return min(n / k, m) - (m - min(n / k, m) + k - 2) // (k - 1)
n = int(input())
while n > 0:
	n -= 1
	(a, b, c) = map(int, input().split())
	print(int(calc(a, b, c)))


from sys import stdin
input = stdin.readline
import bisect
import math
for xoxo in range(1):
	for _ in range(int(input())):
		(n, m, k) = map(int, input().split())
		ans = 0
		p = min(m, n // k)
		for i in range(p, 0, -1):
			x = math.ceil((m - i) / (k - 1))
			ans = max(i - x, ans)
			if x >= i:
				break
		print(ans)


from math import ceil
for test in range(int(input())):
	(n, m, k) = [int(x) for x in input().split()]
	cardToPlayer = n // k
	if m > cardToPlayer:
		y = cardToPlayer
		m = m - cardToPlayer
	else:
		y = m
		m = 0
	x = ceil(m / (k - 1))
	print(y - x)


t = int(input())
for i in range(t):
	(a, b, c) = map(int, input().split())
	e = a // c
	if b <= e:
		print(b)
	else:
		f = b - e
		if f % (c - 1) == 0:
			g = f // (c - 1)
		else:
			g = f // (c - 1)
			g = g + 1
		print(e - g)


import math
for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	if m == 0:
		print(0)
	else:
		card = n // k
		if card >= m:
			print(m)
		else:
			ans = n // k
			m = m - n // k
			ans = ans - math.ceil(m / (k - 1))
			print(ans)


from bisect import *
from collections import *
from itertools import *
import functools
import sys
import math
from decimal import *
from copy import *
from heapq import *
from fractions import *
getcontext().prec = 30
MAX = sys.maxsize
MAXN = 200010
MOD = 10 ** 9 + 7
spf = [i for i in range(MAXN)]
spf[0] = spf[1] = -1

def sieve():
	for i in range(2, MAXN, 2):
		spf[i] = 2
	for i in range(3, int(MAXN ** 0.5) + 1):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def fib(n, m):
	if n == 0:
		return [0, 1]
	else:
		(a, b) = fib(n // 2)
		c = a % m * (b % m * 2 - a % m) % m
		d = a % m * (a % m) % m + b % m * b % m % m
		if n % 2 == 0:
			return [c, d]
		else:
			return [d, c + d]

def charIN(x=' '):
	return sys.stdin.readline().strip().split(x)

def arrIN(x=' '):
	return list(map(int, sys.stdin.readline().strip().split(x)))

def ncr(n, r):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % MOD
		den = den * (i + 1) % MOD
	return num * pow(den, MOD - 2, MOD) % MOD

def flush():
	return sys.stdout.flush()
for _ in range(int(input())):
	(n, m, k) = arrIN()
	tc = n // k
	if m <= tc:
		print(m)
	else:
		m -= tc
		if m >= tc * (k - 1):
			print(0)
		else:
			print(tc - (m // (k - 1) + int(m % (k - 1) != 0)))


def main():
	t = int(input())
	for _ in range(t):
		(n, m, k) = map(int, input().split())
		cards = n // k
		if m == 0:
			ans = 0
		elif m <= cards:
			ans = m
		elif m > cards:
			players = k - 1
			max_joker = cards
			joker_left = m - cards
			if joker_left % players == 0:
				other_joker = joker_left // players
			else:
				other_joker = joker_left // players + 1
			ans = max_joker - other_joker
		print(ans)
main()


def berlandPoker(n, m, k):
	numOfCards = n // k
	if m == 0:
		return 0
	if numOfCards >= m:
		return m
	elif m > numOfCards:
		maxCard = m - numOfCards
		count = 0
		while maxCard > 0:
			count += 1
			maxCard = maxCard - min(maxCard, k - 1)
		return numOfCards - count
testCases = input()
for testCase in range(int(testCases)):
	(n, m, k) = map(int, input().split())
	res = berlandPoker(n, m, k)
	print(res)


t = input()
nmk = list()
answer = list()
for i in range(int(t)):
	tem = input()
	tem = tem.split()
	nmk.append(tem)
	n = int(nmk[i][0])
	m = int(nmk[i][1])
	k = int(nmk[i][2])
	if n / k < m:
		if (m - n / k) % (k - 1) == 0:
			ans = n / k - int((m - n / k) / (k - 1))
		else:
			ans = n / k - int((m - n / k) / (k - 1)) - 1
	else:
		ans = m
	answer.append(ans)
for l in answer:
	print(int(l))


def main():
	import sys
	input = sys.stdin.buffer.readline

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

	def lcm(a, b):
		return a * b // GCD(a, b)

	def merge(a, start, mid, end, d):
		p = start
		q = mid + 1
		arr = [0] * (end - start + 1)
		k = 0
		coun = 0
		for i in range(start, end + 1):
			if p > mid:
				arr[k] = a[q]
				q += 1
				k += 1
			elif q > end:
				arr[k] = a[p]
				d[a[p]] += coun
				k += 1
				p += 1
			elif a[p] < a[q]:
				arr[k] = a[p]
				d[a[p]] += coun
				k += 1
				p += 1
			else:
				arr[k] = a[q]
				k += 1
				q += 1
				coun += 1
		for i in range(k):
			a[start] = arr[i]
			start += 1

	def mergesort(a, start, end, d):
		if start < end:
			mid = (start + end) // 2
			mergesort(a, start, mid, d)
			mergesort(a, mid + 1, end, d)
			merge(a, start, mid, end, d)

	def inversion(l):
		d = {}
		for i in l:
			d[i] = 0
		mergesort(l, 0, len(l) - 1, d)
		return d

	def binary_search_lower(A, low, high, k):
		if high - low != 1:
			mid = (low + high) // 2
			x = A[mid]
			if x >= k:
				return binary_search_lower(A, low, mid, k)
			else:
				return binary_search_lower(A, mid, high, k)
		if A[low] >= k:
			return low
		else:
			return high

	def binary_expo(x, n):
		if n == 0:
			return 1
		elif n % 2 == 0:
			return binary_expo(x * x, n // 2)
		else:
			return x * binary_expo(x * x, (n - 1) // 2)

	def modu_expo(x, n, m):
		if n == 0:
			return 1
		elif n % 2 == 0:
			return modu_expo(x * x % m, n // 2, m)
		else:
			return x * modu_expo(x * x % m, (n - 1) // 2, m) % m

	def eEuclid(c, m):
		if m == 0:
			global d
			global x
			global y
			d = c
			x = 1
			y = 0
		else:
			eEuclid(m, c % m)
			temp = x
			x = y
			y = temp - c // m * y

	def mod_Inv(c, m):
		eEuclid(c, m)
		return (x % m + m) % m

	def ncr(n, r, p):
		num = den = 1
		for i in range(r):
			num = num * (n - i) % p
			den = den * (i + 1) % p
		return num * pow(den, p - 2, p) % p
	for _ in range(int(input())):
		(n, m, k) = map(int, input().split())
		l = [0] * k
		x = n // k
		if m <= x:
			print(m)
			continue
		m = m - x
		l = [0] * (k - 1)
		i = 0
		while m != 0:
			l[i] += 1
			m -= 1
			i += 1
			if i == k - 1:
				i = 0
		print(x - l[0])
main()


import math
for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	if n // k >= m:
		print(m)
	else:
		ma = n // k
		ma2 = math.ceil((m - ma) / (k - 1))
		print(ma - ma2)


t = int(input())
while t > 0:
	[n, m, k] = [int(x) for x in input().split()]
	if m <= n // k:
		print(m)
	else:
		arr = []
		max1 = n // k
		remaining_cards = m - max1
		equal = remaining_cards // (k - 1)
		extra = remaining_cards % (k - 1)
		if extra != 0:
			max2 = equal + 1
		else:
			max2 = equal
		ans = max1 - max2
		if ans < 0:
			ans = 0
		print(ans)
	t -= 1


t = int(input())
for i in range(t):
	(n, m, k) = [int(x) for x in input().split()]
	if m < n // k:
		print(m)
	elif m >= n // k:
		jok = n // k
		m = m - n // k
		ans = m // (k - 1)
		if (k - 1) * ans != m:
			ans += 1
		print(jok - ans)


import math
t = int(input())
for hh in range(0, t):
	(n, m, k) = [int(x) for x in input().split()]
	eachone = n // k
	if m <= eachone:
		print(m)
	else:
		rem = m - eachone
		maxrem = math.ceil(rem / (k - 1))
		ans = eachone - maxrem
		print(ans)


for _ in range(int(input())):
	(n, m, k) = list(map(int, input().split()))
	cPP = n // k
	if m - cPP < 0:
		print(m)
	else:
		jLeft = m - cPP
		x = jLeft / (k - 1)
		if int(x) == x:
			print(int(cPP - x))
		else:
			print(cPP - int(x) - 1)


from fractions import Fraction
import bisect
import os
from collections import Counter
import bisect
from collections import defaultdict
import math
import random
import heapq as hq
from math import sqrt
import sys
from functools import reduce, cmp_to_key
from collections import deque
import threading
from itertools import combinations
from io import BytesIO, IOBase
from itertools import accumulate

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

def iinput():
	return int(input())

def tinput():
	return input().split()

def rinput():
	return map(int, tinput())

def rlinput():
	return list(rinput())
mod = int(1000000000.0) + 7

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))
t = 1
for _ in range(iinput()):
	(n, m, k) = rinput()
	players = n // k
	if players >= m:
		print(m)
	else:
		val = float(m - players) / float(k - 1)
		print(players - int(math.ceil(val)))


import sys, math
from collections import deque

def solve():
	return
for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	c = n // k
	if m <= c:
		print(m)
	else:
		print(c - math.ceil((m - c) / (k - 1)))


import os
import sys
from io import BytesIO, IOBase
from collections import Counter
from collections import deque
import heapq
import math
import statistics

def sin():
	return input()

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

def sain():
	return input().split()

def iin():
	return int(sin())
MAX = float('inf')
MIN = float('-inf')

def main():
	for _ in range(iin()):
		(n, m, k) = ain()
		x = n // k
		if m <= x:
			print(m)
		else:
			j = x
			m = m - j
			p = math.ceil(m / (k - 1))
			print(j - p)
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')
main()


from sys import stdin, stdout
import math
t = int(stdin.readline())
for _ in range(t):
	(n, m, k) = map(int, stdin.readline().split())
	f = min(n // k, m)
	s = math.ceil((m - f) / (k - 1))
	print(f - s)


def ceil(a, b):
	if a % b == 0:
		return a // b
	else:
		return a // b + 1
t = int(input())
for case in range(t):
	(n, m, k) = map(int, input().split())
	taken = min(m, n // k)
	remaining = m - taken
	print(taken - ceil(remaining, k - 1))


from sys import stdin, stdout
from math import gcd, ceil, sqrt
ii1 = lambda : int(stdin.readline().strip())
is1 = lambda : stdin.readline().strip()
iia = lambda : list(map(int, stdin.readline().strip().split()))
isa = lambda : stdin.readline().strip().split()
mod = 1000000007
tc = ii1()
for _ in range(tc):
	(n, m, k) = iia()
	if m <= n // k:
		print(m)
	else:
		cards = n // k
		m -= cards
		print(cards - ceil(m / (k - 1)))


import sys, math
t = int(input())
for _ in range(t):
	(n, m, k) = map(int, sys.stdin.readline().split())
	if m == 0:
		print(0)
	else:
		c = n // k
		if m <= c:
			print(m)
		else:
			x = c
			m -= x
			j = math.ceil(m / (k - 1))
			print(x - j)


t = int(input())
for i in range(t):
	(n, m, k) = [int(x) for x in input().split()]
	p = n // k
	if p >= m:
		res = m
	else:
		(a, b) = ((m - p) // (k - 1), (m - p) % (k - 1))
		temp = a if b == 0 else a + 1
		res = p - temp
	print(res)


import math
t = int(input())
for _ in range(t):
	(n, m, k) = map(int, input().split())
	e = min(m, int(n / k))
	m -= e
	if m % (k - 1) == 0:
		print(e - int(m / (k - 1)))
	else:
		x = int(m / (k - 1)) + 1
		print(e - x)


import math
t = int(input())
for i in range(t):
	(n, m, k) = map(int, input().split())
	each = int(n / k)
	if m == 0:
		print(0)
	elif m <= each:
		print(m)
	else:
		rem = m - each
		div = math.ceil(rem / (k - 1))
		print(each - div)


import os, sys
from io import IOBase, BytesIO
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
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 get_input(a=str):
	return a(input())

def get_int_input():
	return get_input(int)

def get_input_arr(a):
	return list(map(a, input().split()))

def get_int_input_arr():
	return get_input_arr(int)
import math

def solve():
	t = get_int_input()
	for _ in range(t):
		(n, m, k) = get_int_input_arr()
		total_cards = n // k
		if m <= total_cards:
			cout << m << endl
			continue
		else:
			first_player_joker = total_cards
			else_player = m - total_cards
			if math.ceil(else_player / (k - 1)) >= first_player_joker:
				cout << 0 << endl
			else:
				cout << first_player_joker - math.ceil(else_player / (k - 1)) << endl

def main():
	solve()
main()


import math
for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	card = n // k
	l = [0] * n
	a = min(card, m)
	m -= a
	if m < 0:
		m = 0
	m = math.ceil(m / (k - 1))
	if m > card:
		m = card
	print(a - m)


import queue
import math
t = int(input())
while t:
	line = input().split()
	(n, m, k) = (int(line[0]), int(line[1]), int(line[2]))
	if m <= n // k:
		print(m)
	else:
		diff = m - n // k
		ans = n // k - int(math.ceil(diff / (k - 1)))
		print(ans)
	t -= 1


t = int(input())
for _ in range(t):
	(n, m, k) = list(map(int, input().split()))
	if n // k >= m:
		print(m)
	else:
		f = n // k
		m = m - f
		if m <= k - 1:
			print(f - 1)
		else:
			l = k - 1
			d = m // l
			if m % l == 0:
				a = f - d
			else:
				d = d + 1
				a = f - d
			print(a)


ts = int(input())
for i in range(ts):
	(n, m, k) = [int(x) for x in input().split()]
	NumOfCard = int(n // k)
	if NumOfCard >= m:
		ans = m
	else:
		ans = NumOfCard - (m - NumOfCard) // (k - 1) - (1 if (m - NumOfCard) % (k - 1) else 0)
	print(ans)


def main():
	t = int(input())
	for i in range(t):
		(n, m, k) = map(int, input().split())
		svaki_igrac = n // k
		if m <= svaki_igrac:
			print(m)
		else:
			jokeri = svaki_igrac
			ostatak = m - jokeri
			if ostatak % (k - 1) == 0:
				ostatak = ostatak // (k - 1)
			else:
				ostatak = ostatak // (k - 1) + 1
			print(jokeri - ostatak)
main()


import math
t = int(input())
for i in range(t):
	lst = list(map(int, input().rstrip().split()))
	(n, m, k) = lst
	if n / k >= m:
		print(m)
	else:
		jk = n / k
		re = m - n / k
		print(int(jk - math.ceil(re / (k - 1))))


for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	cardsWithEachOne = n // k
	if m > cardsWithEachOne:
		m = m - cardsWithEachOne
		k = k - 1
		minCardsDistribute = m // k
		if m % k != 0:
			minCardsDistribute += 1
		print(cardsWithEachOne - minCardsDistribute)
	else:
		print(m)


from math import ceil

def read_int():
	n = int(input())
	return n

def read_ints():
	ints = [int(x) for x in input().split(' ')]
	return ints

def solve(n, m, k):
	if m == 0:
		return 0
	hand_sz = n // k
	if hand_sz >= m:
		jokers = m
	else:
		jokers = hand_sz
	rem_jokers = m - jokers
	if rem_jokers == 0:
		score = jokers
	else:
		score = jokers - ceil(rem_jokers / (k - 1))
	return score
t = read_int()
for case in range(t):
	(n, m, k) = read_ints()
	sol = solve(n, m, k)
	print(sol)


import math
for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	if m <= n // k:
		print(m)
	else:
		maxjokers = n // k
		k -= 1
		secondmax = math.ceil((m - maxjokers) / k)
		print(maxjokers - secondmax)


num_inp = lambda : int(input())
arr_inp = lambda : list(map(int, input().split()))
for i in [*open(0)][1:]:
	(n, m, k) = map(int, i.split())
	print((min(m, n // k) * k - m) // (k - 1))
sp_inp = lambda : map(int, input().split())
str_inp = lambda : input()


T = int(input().strip())
for t in range(T):
	(n, m, k) = list(map(int, input().split()))
	cards = n // k
	maxcards = min(cards, m)
	minscore = (m - maxcards) // (k - 1)
	if (m - maxcards) % (k - 1):
		minscore += 1
	print(maxcards - minscore)


from math import ceil
t = int(input())
for _ in range(t):
	(cards, jokers, players) = map(int, input().split())
	cards_per_capta = cards // players
	if cards_per_capta >= jokers:
		print(jokers)
	else:
		other = jokers - cards_per_capta
		oother = ceil(other / (players - 1))
		print(cards_per_capta - oother)


t = int(input())
for i in range(t):
	(n, m, k) = map(int, input().split())
	max_card = n // k
	if m <= max_card:
		print(m)
	else:
		left = m - max_card
		sm = left // (k - 1)
		if left % (k - 1) > 0:
			sm = sm + 1
		if sm == max_card:
			print(0)
		else:
			print(max_card - sm)


T = int(input())
for t in range(T):
	(n, m, k) = map(int, input().split())
	cards = n // k
	wj = min(cards, m)
	lj = m - wj
	llj = (lj + k - 1 - 1) // (k - 1)
	print(wj - llj)


T = int(input())
for _ in range(T):
	(N, M, K) = map(int, input().split())
	d = N // K
	if M <= d:
		print(M)
		continue
	M -= d
	j = 0 - -M // (K - 1)
	print(d - j)


import math
I = input
t = int(I())
for tt in range(t):
	(n, m, k) = [int(x) for x in I().strip().split()]
	if m == 0:
		print(0)
	elif n // k >= m:
		print(m)
	else:
		n1 = n // k
		n2 = m - n // k
		n3 = k - 1
		n4 = math.ceil(n2 / n3)
		print(max(n1 - n4, 0))


import math
for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	pabe = int(n / k)
	if m == 0:
		print(0)
	elif m <= pabe:
		print(m)
	else:
		f = pabe
		m = m - pabe
		s = math.ceil(m / (k - 1))
		print(pabe - s)


t = int(input())
for i in range(t):
	(n, m, k) = map(int, input().split())
	cards = n / k
	if cards >= m:
		print(m)
	elif n == m:
		print(0)
	else:
		rem = k - 1
		cur = m - cards
		mx = cur // rem
		if cur % rem != 0:
			mx += 1
		print(int(cards - mx))


t = int(input())
for _ in range(t):
	(n, m, k) = map(int, input().split())
	ct = n // k
	k -= 1
	if ct >= m:
		print(m)
	else:
		m = m - ct
		temp = m // k
		temp1 = m % k
		if temp == ct:
			print(0)
		elif temp == ct - 1 and temp1 != 0:
			print(0)
		else:
			if temp1 == 0:
				temp1 = 0
			else:
				temp1 = 1
			ct1 = temp + temp1
			print(ct - ct1)


from sys import stdin, stdout

def solve():
	(n, m, k) = map(int, input().split())
	if m <= n // k:
		return m
	else:
		m -= n // k
		m2 = m // (k - 1)
		if m % (k - 1):
			m2 += 1
		return n // k - min(m2, n // k)
for _ in range(int(stdin.readline())):
	stdout.write(str(solve()) + '\n')


import math
t = int(input())
for i in range(t):
	(n, m, k) = map(int, input().split())
	d = n // k
	if m == 0:
		print(0)
	elif d < m:
		if (m - d) % (k - 1) == 0:
			print(d - (m - d) // (k - 1))
		else:
			print(d - ((m - d) // (k - 1) + 1))
	else:
		print(m)


for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	x = int(n / k)
	f = min(x, m)
	rem = m - f
	k -= 1
	if rem % k == 0:
		print(f - int(rem / k))
	else:
		print(f - int(rem / k) - 1)


for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	eachPlayerCards = n // k
	p1Jokers = min(m, eachPlayerCards)
	otherPlayers = (m - p1Jokers + k - 2) // (k - 1)
	print(p1Jokers - otherPlayers)


for z in range(int(input())):
	(n, m, k) = list(map(int, input().split()))
	if n / k < m:
		print(int(n / k - (m - n / k + k - 2) // (k - 1)))
	else:
		print(m)


import math
t = int(input())
for i in range(t):
	inp = input().split(' ')
	inp = [int(x) for x in inp]
	x = int(inp[0] / inp[2])
	if x >= inp[1]:
		print(inp[1])
	else:
		ans = x - math.ceil(float(inp[1] - x) / float(inp[2] - 1))
		print(ans)


import sys
input = sys.stdin.readline
flush = sys.stdout.flush
for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	if m >= n // k:
		a = n // k
		m -= a
		b = m // (k - 1) + 1 - (m % (k - 1) == 0)
		print(a - b)
		continue
	else:
		print(m)


t = int(input())
for i in range(t):
	(n, m, k) = map(int, input().split())
	maxcards = n // k
	count = min(m, maxcards)
	count1 = (m - count + k - 2) // (k - 1)
	print(count - count1)


import sys
input = sys.stdin.readline

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

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

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

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

def foo():
	(n, m, k) = map(int, input().split())
	d = n // k
	a1 = min(m, d)
	a2 = (m - a1 + k - 2) // (k - 1)
	print(a1 - a2)
t = inp()
for i in range(t):
	foo()


testy = int(input())
results = []
import math
for i in range(testy):
	wejscie = list(map(int, input().split()))
	if wejscie[1] <= wejscie[0] // wejscie[2]:
		results.append(wejscie[1])
	else:
		results.append(wejscie[0] // wejscie[2] - math.ceil((wejscie[1] - wejscie[0] // wejscie[2]) / (wejscie[2] - 1)))
for result in results:
	print(result)


t = int(input())
for _ in range(t):
	(n, m, k) = map(int, input().split())
	if m == 0:
		print(0)
		continue
	Card = int(n / k)
	Joker1 = min(m, Card)
	if m == Joker1:
		print(Joker1)
		continue
	import math
	Joker2 = max(0, math.ceil((m - Joker1) / (k - 1)))
	ans = max(0, Joker1 - Joker2)
	print(ans)


from collections import Counter
import math
t = int(input())
while t > 0:
	t = t - 1
	(n, m, k) = map(int, input().split())
	if m >= n + 2 - k:
		print(0)
	elif m <= n // k:
		print(m)
	else:
		print(n // k - math.ceil((m - n // k) / (k - 1)))


from sys import stdin
import math

def solve():
	return

def main():
	inp = stdin.readline
	for _ in range(int(inp())):
		(n, m, k) = map(int, inp().split())
		if m <= n // k:
			ans = m
		else:
			h = m - n // k
			g = k - 1
			ans = n // k - math.ceil(h / g)
		print(ans)
main()


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(n, m, k) = map(int, input().split())
	winner = min(n // k, m)
	loser_sum = m - winner
	k -= 1
	ans = winner - (loser_sum + k - 1) // k
	print(ans)


T = int(input())
for _ in range(T):
	(n, m, k) = map(int, input().split())
	p = n // k
	cards = min(m, p)
	m -= cards
	i = 0
	ls = [0] * (k - 1)
	while m != 0:
		idx = i % (k - 1)
		ls[idx] += 1
		m -= 1
		i += 1
	ans = abs(cards - max(ls))
	print(ans)


from math import *
from copy import *
t = int(input())
for i in range(t):
	(n, m, k) = list(map(int, input().split()))
	n_cards = n // k
	if m == 0:
		print(0)
		continue
	if m <= n_cards:
		print(m)
		continue
	else:
		MAX = n_cards
		leftover_c = m - n_cards
		leftover_men = k - 1
		l = [0] * (k - 1)
		pp = 0
		while leftover_c != 0:
			l[pp % len(l)] += 1
			pp += 1
			leftover_c -= 1
		print(MAX - max(l))


import math
t = int(input())
i = 0
while i < t:
	(n, m, k) = list(map(int, input().split()))
	cpp = n // k
	if m >= cpp:
		maxjokergiven = cpp
	else:
		maxjokergiven = m
	jokersledt = m - maxjokergiven
	if jokersledt % (k - 1) == 0:
		print(int(maxjokergiven - jokersledt // (k - 1)))
	else:
		print(int(maxjokergiven - (jokersledt // (k - 1) + 1)))
	i += 1


t = int(input())
for _ in range(t):
	(n, m, k) = list(map(int, input().rstrip().split()))
	n_e = int(n / k)
	if m <= n_e:
		print(m)
	elif (m - n_e) % (k - 1) == 0:
		y = int((m - n_e) / (k - 1))
		print(n_e - y)
	else:
		y = int((m - n_e) / (k - 1)) + 1
		print(n_e - y)


for i in range(int(input())):
	nmk = list(map(int, input().split()))
	(n, m, k) = (nmk[0], nmk[1], nmk[2])
	e = n // k
	if m == 0:
		print(0)
	elif m <= e:
		print(m)
	elif (m - e) // (k - 1) == (m - e) / (k - 1):
		print(e - (m - e) // (k - 1))
	else:
		print(e - (m - e) // (k - 1) - 1)


import math
for t in range(int(input())):
	(n, m, k) = map(int, input().split())
	s = 0
	if m <= n // k:
		s = m
	else:
		c = n // k
		m -= c
		k -= 1
		a = math.ceil(m / k)
		s = c - a
	print(s)


try:
	for _ in range(int(input())):
		(n, m, k) = map(int, input().split())
		c_pp = n // k
		if c_pp >= m:
			print(m)
		else:
			r_j = m - c_pp
			r_p = k - 1
			if r_j % r_p == 0:
				print(c_pp - r_j // r_p)
			else:
				print(c_pp - (r_j // r_p + 1))
except:
	pass


import sys
import math
import itertools
import functools
import collections
import operator
import fileinput
import copy
ORDA = 97

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

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

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

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

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)
for _ in range(ii()):
	(n, m, k) = mi()
	if m <= n // k:
		print(m)
	else:
		m -= n // k
		print(n // k - math.ceil(m / (k - 1)))


def solve():
	(n, m, k) = map(int, input().split())
	d = n // k
	a1 = min(m, d)
	a2 = (m - a1 + k - 2) // (k - 1)
	print(a1 - a2)
t = int(input())
for x in range(t):
	solve()


num = int(input())
while num > 0:
	num -= 1
	s = input().split(' ')
	n = int(s[0])
	m = int(s[1])
	k = int(s[2])
	d = n // k
	if m == 0:
		print('0')
	elif d >= m:
		print(m)
	else:
		m = m - d
		kk = k
		kk -= 1
		lo = 0
		t = 0
		while kk > 0:
			m -= 1
			kk -= 1
			if kk == 0:
				lo += 1
				t = lo + m
			if kk == 0 and m > 1:
				kk = k - 1
			if m == 0:
				break
		if m == 0:
			if lo == 0:
				f = d - 1
			elif kk > 0:
				f = d - lo - 1
			else:
				f = d - lo
		else:
			f = d - lo - m
		print(f)


import math
T = int(input())
while T:
	(n, m, k) = map(int, input().split())
	r = n // k
	x = min(r, m)
	m = m - x
	y = math.ceil(m / (k - 1))
	print(x - y)
	T = T - 1


for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	if m <= 1:
		print(m)
	elif n == m:
		print(0)
	else:
		c = n // k
		if m <= c:
			print(m)
		else:
			ost = m - c
			if ost > (k - 1) * (c - 1):
				print(0)
			else:
				print(c - (m - c + k - 2) // (k - 1))


for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	x = n // k
	if m <= x:
		print(m)
		continue
	m = m - x
	l = [0] * (k - 1)
	i = 0
	while m != 0:
		l[i] += 1
		m -= 1
		i += 1
		if i == k - 1:
			i = 0
	print(x - l[0])


import math
t = int(input())
for i in range(t):
	(n, m, k) = map(int, input().split())
	num = n / k
	if m <= num:
		print(m)
	else:
		y = int((m - num) / (k - 1))
		if (m - num) % (k - 1) != 0:
			y += 1
		print(int(num - y))


import math
T = int(input())

def main():
	(n, m, k) = tuple(map(int, input().split()))
	if m == 0:
		return 0
	each_player = n / k
	if m == each_player:
		return m
	elif m < each_player:
		return m
	else:
		winner_joker = each_player
		rem_jokers = m - winner_joker
		if rem_jokers % (k - 1) == 0:
			return int(winner_joker - rem_jokers / (k - 1))
		else:
			second_highest = math.ceil(rem_jokers / (k - 1))
			return int(winner_joker - second_highest)
for i in range(T):
	print(main())


from math import ceil
t = int(input())
for i in range(t):
	(n, m, k) = list(map(int, input().split()))
	pp = n // k
	if pp >= m:
		print(m)
	else:
		win = min(pp, m)
		print(win - ceil((m - win) / (k - 1)))


t = int(input())
for _ in range(t):
	(n, m, k) = map(int, input().split())
	each = n // k
	if m <= each:
		print(m)
	else:
		x = each
		m -= each
		kk = m
		m = m // (k - 1)
		if kk % (k - 1) is not 0:
			m = m + 1
		print(max(0, x - m))


import sys
input = lambda : sys.stdin.readline().rstrip()
inp = sys.stdin.buffer.readline

def I():
	return list(map(int, inp().split()))
for _ in range(I()[0]):
	(n, m, k) = I()
	a = [0] * (k - 1)
	ans = min(n // k, m)
	m -= ans
	for i in range(m):
		a[i % (k - 1)] += 1
	print(ans - max(a))


import math
t = int(input())
for _ in range(t):
	(n, m, k) = map(int, input().split())
	nn = n // k
	if nn <= m:
		ans = nn
		m = max(0, m - ans)
		mod = k - 1
		a = [0 for x in range(k - 1)]
		i = 0
		temp = 0
		while m > 0:
			a[i % mod] += 1
			temp = a[i % mod]
			i += 1
			m -= 1
		print(ans - temp)
	elif nn > m:
		ans = m
		print(ans)


import sys, math
max_int = 1000000001
min_int = -max_int
t = int(sys.stdin.readline())
for _ in range(t):
	(n, m, k) = map(int, sys.stdin.readline().split())
	hand = n // k
	if m <= hand:
		print(m)
	else:
		m -= hand
		print(hand - math.ceil(m / (k - 1)))


import math

def time(arr):
	each = int(arr[0] / arr[2])
	if each >= arr[1]:
		return arr[1]
	elif each < arr[1] and int((arr[1] - each) / (arr[2] - 1)) < 1:
		return each - 1
	elif each < arr[1] and int((arr[1] - each) / (arr[2] - 1)) >= 1:
		return each - math.ceil((arr[1] - each) / (arr[2] - 1))
	else:
		return 0
t = int(input())
ans = []
for i in range(t):
	arr = list(map(int, input().rstrip().split()))
	r = time(arr)
	ans.append(r)
for i in ans:
	print(i)


for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	if k != 0:
		if n == k and n / k < m:
			print('0')
		elif n / k >= m:
			print(m)
		elif n / k < m:
			a = m - n // k
			c = (a + (k - 2)) // (k - 1)
			print(int(n / k - c))


from math import ceil
t = int(input())
for tt in range(t):
	(n, m, k) = list(map(int, input().split()))
	d = n // k
	if m <= d:
		print(m)
	else:
		left = m - d
		y = ceil(left / (k - 1))
		print(d - y)


tests = int(input())
for _ in range(tests):
	(n, m, k) = map(int, input().split())
	if m <= n // k:
		print(m)
		continue
	else:
		x = n // k
		rem = m - x
		y = rem // (k - 1)
		if rem % (k - 1) != 0:
			y += 1
		print(x - y)


import math
num = int(input())
for case in range(num):
	(cards, jokers, players) = map(int, input().split())
	each_player_gets = int(cards / players)
	if jokers == 0 or cards == jokers:
		print('0')
	elif each_player_gets >= jokers:
		print(jokers)
	else:
		best_player_gets = each_player_gets
		jokers_left = jokers - best_player_gets
		other_players_max = int(math.ceil(jokers_left / (players - 1)))
		print(best_player_gets - other_players_max)


import math
t = int(input())
for _ in range(t):
	(n, m, k) = tuple(map(int, input().split()))
	pp = n / k
	a = min(m, pp)
	b = m - a
	c = (b + k - 2) / (k - 1)
	print(math.ceil(a - c))


import sys
inf = float('inf')
for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	if m == 0:
		print(0)
	elif n // k >= m:
		print(m)
	else:
		v = n // k
		rem = m - v
		if rem % (k - 1) == 0:
			print(v - rem // (k - 1))
		else:
			print(v - (rem // (k - 1) + 1))


ans = []
for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	if n // k >= m:
		ans.append(m)
		continue
	ans.append(n // k - ((m - n // k - 1) // (k - 1) + 1))
print('\n'.join(map(str, ans)))


t = int(input())
for i in range(t):
	(n, m, k) = map(int, input().split())
	d = n // k
	mi = min(m, d)
	rez = (m - mi + k - 2) // (k - 1)
	print(mi - rez)


t = int(input())
for i in range(t):
	(a, b, c) = [int(i) for i in input().split()]
	joker = int(a / c)
	if joker >= b:
		print(b)
	else:
		maha = 0
		for i in range(joker + 1):
			for j in range(i):
				if j + i <= b and i + (c - 1) * j >= b:
					if i - j > maha:
						maha = i - j
		print(maha)


t = int(input())
while t > 0:
	t -= 1
	(n, m, k) = map(int, input().strip().split())
	if n // k >= m:
		print(m)
		continue
	m -= n // k
	x = n // k
	y = m // (k - 1)
	if m % (k - 1) != 0:
		y += 1
	print(x - y)


import atexit
import io
import sys
import math
from collections import defaultdict, Counter
t = int(input())
for i in range(t):
	(n, m, k) = map(int, input().split())
	d = n // k
	if d >= m:
		print(m)
	else:
		left = math.ceil((m - d) / (k - 1))
		print(d - int(left))


from sys import stdin

def run(n, m, k):
	avg = n // k
	if m <= avg:
		return m
	a = avg
	b = m - avg
	c = (b + k - 2) // (k - 1)
	return a - c

def main():
	t = int(stdin.readline())
	for _ in range(t):
		(n, m, k) = [int(x) for x in stdin.readline().split()]
		ans = run(n, m, k)
		print(ans)
import os
if os.path.exists('tmp.in'):
	stdin = open('tmp.in')
main()


import math
for i in range(int(input())):
	(n, m, k) = list(map(int, input().split()))
	cards = n // k
	if m <= cards:
		print(m)
	else:
		one = cards
		other = math.ceil((m - cards) / (k - 1))
		print(one - other)


t = int(input())
for j in range(t):
	a = [int(i) for i in input().split(' ')]
	n = a[0]
	m = a[1]
	k = a[2]
	if m >= n / k:
		x = int(n / k)
		m -= x
		if m % (k - 1) == 0:
			y = int(m / (k - 1))
		else:
			y = int(m // (k - 1) + 1)
	else:
		x = m
		y = 0
	if x - y > 0:
		print(x - y)
	else:
		print(0)


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

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

def sin():
	return input()

def inin():
	return int(input())
for i in range(inin()):
	(n, m, k) = cin()
	lim = n // k
	if m <= lim:
		print(m)
	else:
		rem = m - lim
		if rem <= k - 1:
			ma = 1
		elif rem % (k - 1) == 0:
			ma = rem // (k - 1)
		else:
			ma = rem // (k - 1) + 1
		print(lim - ma)


for _ in range(0, int(input())):
	(n, m, k) = map(int, input().split())
	ncr = int(n / k)
	if m == 0:
		print('0')
		continue
	elif ncr >= m:
		print(m)
		continue
	else:
		rc = m - ncr
		rp = k - 1
		xx = rc / rp
		yy = int(xx)
		smax = 0
		if xx > yy:
			smax = yy + 1
			print(ncr - smax)
		else:
			print(ncr - yy)


t = int(input())
for tes in range(t):
	(n, m, k) = map(int, input().rstrip().split())
	x = n // k
	if m == 0:
		print(0)
	elif x >= m:
		print(m)
	elif x == 1:
		print(0)
	else:
		b = [0] * (k - 1)
		a = m - x
		while a > 0:
			for i in range(k - 1):
				if a <= 0:
					break
				b[i] += 1
				a -= 1
		if x - max(b) > 0:
			print(x - max(b))
		else:
			print(0)


from math import ceil
for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	if m == 0:
		print(0)
		continue
	if n // k >= m:
		print(m)
		continue
	mx = n // k
	k -= 1
	m -= mx
	print(mx - ceil(m / k))


import math
for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	d = n // k
	if m <= d:
		print(m)
	else:
		ostm = m - d
		ost = math.ceil(ostm / (k - 1))
		print(d - ost)


import sys
import math
try:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
except:
	pass
input = sys.stdin.readline
for tt in range(int(input())):
	(n, m, k) = map(int, input().split())
	joker = min(m, n // k)
	m -= joker
	worse = math.ceil(m / (k - 1))
	print(joker - worse)


import math
import os
import random
import re
import sys
t = int(input())
while t > 0:
	t -= 1
	(n, m, k) = map(int, input().split())
	max_card_per_player = n // k
	max_j_for_others = 0
	if m - max_card_per_player > 0:
		max_j_for_others = (m - max_card_per_player) // (k - 1)
		if (m - max_card_per_player) % (k - 1) > 0 and max_j_for_others < max_card_per_player:
			max_j_for_others += 1
		print(max_card_per_player - max_j_for_others)
	else:
		print(m)


t = int(input())
for _ in range(t):
	(n, m, k) = (int(i) for i in input().split())
	nc = n // k
	if m <= nc:
		print(m)
		continue
	rem = m - nc
	nextHighest = rem // (k - 1)
	if rem % (k - 1) > 0:
		nextHighest += 1
	print(nc - nextHighest)


from math import ceil
t = int(input())
while t:
	values = input()
	values = values.split()
	n = int(values[0])
	m = int(values[1])
	k = int(values[2])
	if n // k >= m:
		print(m)
		t -= 1
		continue
	else:
		print(n // k - ceil((m - n // k) / (k - 1)))
		t -= 1
		continue


import math
t = int(input())
for _ in range(t):
	(n, m, k) = input().split()
	(n, m, k) = (int(n), int(m), int(k))
	if m <= n / k:
		print(m)
	else:
		print(int(min(m, n / k) - math.ceil((m - n / k) / (k - 1))))


n = int(input())
for i in range(n):
	d = 0
	t = 0
	(c, j, p) = map(int, input().split())
	if j == 0:
		print(0)
	elif j <= c // p:
		print(j)
	else:
		d = j
		t = c // p
		d = j - t
		if d <= p - 1:
			print(t - 1)
		elif d % (p - 1) == 0:
			print(t - d // (p - 1))
		else:
			print(t - (d // (p - 1) + 1))


t = int(input())
while t:
	(n, m, k) = input().split()
	n = int(n)
	m = int(m)
	k = int(k)
	t = t - 1
	point = 0
	count = 0
	if m <= n // k:
		point = m
	else:
		point = n // k
		m = m - point
		count = m // (k - 1)
		m = m - count * (k - 1)
		if m != 0:
			count += 1
	point = point - count
	print(point)


for i in [0] * int(input()):
	(a, b, c) = map(int, input().split())
	print(b if a / c >= b else int(a / c - abs(-(b - a / c) // (c - 1))))


import math
t = int(input())
while t:
	(n, mm, k) = map(int, input().split())
	x = n // k
	m = mm - x
	if m <= 0:
		print(mm)
	else:
		v = math.ceil(m / (k - 1))
		print(x - v)
	t -= 1


for _ in range(int(input())):
	(n, j, k) = map(int, input().split())
	pl = n // k
	if pl >= j:
		print(j)
	else:
		re = j - pl
		k -= 1
		if re % k != 0:
			print(pl - re // k - 1)
		else:
			print(pl - re // k)


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


from sys import stdin
import math
I = stdin.readline
for _ in range(int(I())):
	(n, m, k) = list(map(int, I().split()))
	mj = min(m, n // k)
	rj = math.ceil((m - mj) / (k - 1))
	print(mj - rj)


from sys import stdin
n = int(stdin.readline().strip())
for i in range(n):
	(n, m, k) = list(map(int, stdin.readline().strip().split()))
	if m == 0:
		print(0)
	else:
		a = int(n / k)
		if m <= a:
			print(m)
		else:
			oth = m - a
			s = int(oth / (k - 1))
			ans = a - s
			if oth % (k - 1) != 0:
				ans = a - s - 1
			print(ans)


for _ in range(int(input())):
	(n, m, k) = [int(x) for x in input().split()]
	if m < 2:
		print(m)
		continue
	if n == k:
		print(0)
		continue
	if n // k >= m:
		print(m)
	else:
		a = m - n // k
		b = a // (k - 1)
		if a % (k - 1):
			b += 1
		print(n // k - b)


for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	each_cards = n // k
	if each_cards >= m:
		print(m)
	else:
		first_joker = each_cards
		rem_joker = m - first_joker
		if rem_joker <= k - 1:
			print(first_joker - 1)
		elif rem_joker % (k - 1) == 0:
			x = first_joker - rem_joker // (k - 1)
			if x >= 0:
				print(x)
			else:
				print(0)
		else:
			x = rem_joker // (k - 1) + 1
			y = first_joker - x
			if y >= 0:
				print(y)
			else:
				print(0)


t = int(input())
for i in range(t):
	(n, m, k) = map(int, input().split())
	rem = n // k
	if rem >= m:
		print(m)
	elif m == 0:
		print(0)
	else:
		mx = rem
		bcha = m - mx
		c = k - 1
		if bcha % c == 0:
			mx2 = bcha // c
		else:
			mx2 = bcha // c + 1
		print(mx - mx2)


from sys import stdin, stdout
read = stdin.readline
puts = stdout.write

def solve():
	(n, m, k) = [int(i) for i in read().split()]
	max_jokers = min(n // k, m)
	remaining_jokers = m - max_jokers
	k = k - 1
	next_max = 0
	if remaining_jokers > k:
		next_max = remaining_jokers // k
		if remaining_jokers % k != 0:
			next_max += 1
	elif remaining_jokers > 0:
		next_max = 1
	print(f'{max_jokers - next_max}')
for i in range(int(read())):
	solve()


import math

def solve(n, m, k):
	cards = n // k
	if m == 0:
		return 0
	elif cards >= m:
		return m
	else:
		j = m - cards
		count = 0
		while j > 0:
			count += 1
			j -= k - 1
		return cards - count
n = int(input())
for _ in range(n):
	(n, m, k) = map(int, input().split())
	print(solve(n, m, k))


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

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

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

def invr():
	return map(int, input().split())
entries = inp()
for i in range(entries):
	l = inlt()
	n = l[0]
	m = l[1]
	k = l[2]
	hand = min(n // k, m)
	rest = m - hand
	r = (rest + k - 2) // (k - 1)
	res = hand - r
	print(res)


import math
t = int(input())
for _ in range(t):
	(totalNoOfCards, noOfJokers, noOfPeople) = map(int, input().rstrip().split())
	if noOfJokers <= totalNoOfCards // noOfPeople or noOfJokers == 0:
		print(noOfJokers)
	else:
		score = totalNoOfCards // noOfPeople
		secondHigh = math.ceil((noOfJokers - score) / (noOfPeople - 1))
		score -= secondHigh
		print(score)


import math
t = int(input())
while t > 0:
	t -= 1
	arr = list(map(int, input().split(' ')))
	n = arr[0]
	m = arr[1]
	k = arr[2]
	d = n // k
	a1 = min(m, d)
	a2 = (m - a1 + k - 2) // (k - 1)
	print(abs(a1 - a2))


from sys import stdin, stdout
t = int(input())
for i in range(t):
	(n, m, k) = list(map(int, input().split()))
	card = n // k
	if m <= card:
		print(m)
	else:
		m -= card
		if m <= k - 1:
			print(card - 1)
		else:
			y = m // (k - 1)
			remain = m % (k - 1)
			if remain > 0:
				remain = 1
			print(card - (y + remain))


import math
num = int(input())
for i in range(num):
	(n, m, k) = [int(x) for x in input().split()]
	avg = int(n / k)
	if avg >= m:
		print(m)
		continue
	left = m - avg
	if left > k - 1:
		other_max = math.ceil(left / (k - 1))
		print(avg - other_max)
		continue
	print(avg - 1)


def solve():
	(n, m, k) = map(int, input().split())
	g = n // k
	if n - m <= k - 2:
		print(0)
		return
	top = min(g, m)
	m -= top
	k -= 1
	l = -(-m // k)
	ans = top - l
	print(ans)
t = int(input())
for i in range(t):
	solve()


for t in range(int(input())):
	(n, m, k) = map(int, input().split())
	eachPlayerCard = n // k
	winnnerJoker = 0
	if m <= eachPlayerCard:
		winnerJoker = m
		m = 0
	else:
		winnerJoker = eachPlayerCard
		m = m - eachPlayerCard
	loserJoker = m // (k - 1)
	if m % (k - 1) != 0:
		loserJoker += 1
	print(winnerJoker - loserJoker)


for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	each = n // k
	if m <= each:
		first = m
		second = 0
	else:
		first = each
		second = (m - each) // (k - 1)
		if (m - each) % (k - 1) != 0:
			second += 1
	print(first - second)


from sys import stdin
from math import ceil
inp = lambda : stdin.readline().strip()
t = int(inp())
for _ in range(t):
	(n, m, k) = [int(x) for x in inp().split()]
	eachP = n // k
	maxP = min(eachP, m)
	remaining = m - maxP
	otherMax = ceil(remaining / (k - 1))
	print(maxP - otherMax)


import math
T = int(input())
for _ in range(T):
	(n, m, k) = list(map(int, input().split()))
	card = n // k
	if m == 0:
		print(0)
	elif card >= m:
		print(m)
	else:
		print(card - math.ceil((m - card) / (k - 1)))


from math import ceil
for i in range(int(input())):
	(n, m, k) = map(int, input().split())
	your_jokers = min(n // k, m)
	their_jokers = ceil((m - your_jokers) / (k - 1))
	print(your_jokers - their_jokers)


import math
t = int(input())
for T in range(t):
	(n, m, k) = [int(x) for x in input().split()]
	each = n // k
	mx = min(each, m)
	jokers = m - mx
	rem = mx - math.ceil(jokers / (k - 1))
	print(rem)


def main():
	t = int(input())
	while t > 0:
		play_game()
		t -= 1

def play_game():
	game = list(map(int, input().split()))
	k = game[2]
	cards_per_player = game[0] / k
	m = game[1]
	x = min(cards_per_player, m)
	remaining_jokers = m - x
	remaining_players = k - 1
	y = remaining_jokers / remaining_players
	print(int(x - y))
main()


import math
import sys
input = sys.stdin.readline
t = int(input())
res = []

def ceiling(p, q):
	return (p + q - 1) // q
for cs in range(t):
	(n, m, k) = map(int, input().split())
	maxJoker = min(m, n // k)
	minJoker = ceiling(m - maxJoker, k - 1)
	res.append(maxJoker - minJoker)
print('\n'.join(map(str, res)))


from math import ceil
t = int(input())
while t:
	(n, m, k) = map(int, input().split())
	a = n // k
	if a >= m:
		print(m)
	else:
		m = m - a
		e = ceil(m / (k - 1))
		print(a - e)
	t -= 1


x = int(input())
for i in range(x):
	nmk = list(map(int, input().split()))
	n = nmk[0]
	m = nmk[1]
	k = nmk[2]

	def poker(n, m, k):
		if m == 0:
			return 0
		x = int(n / k)
		if x >= m:
			return m
		elif (m - x) % (k - 1) != 0:
			count = int((m - x) / (k - 1)) + 1
			return x - count
		else:
			count = int((m - x) / (k - 1))
			return x - count
	print(poker(n, m, k))


for _ in range(int(input())):
	Input = input().split()
	n = int(Input[0])
	m = int(Input[1])
	k = int(Input[2])
	cards_per_player = n // k
	if m <= cards_per_player:
		print(m)
	else:
		rem = m - cards_per_player
		rem_per_rest = rem / (k - 1)
		if rem_per_rest.is_integer():
			rem_per_rest = int(rem_per_rest)
		else:
			rem_per_rest = int(rem_per_rest) + 1
		print(cards_per_player - rem_per_rest)


def solve():
	(n, m, k) = [int(i) for i in input().split()]
	x = min(n // k, m)
	m -= x
	k -= 1
	y = (m - 1) // k + 1
	print(x - y)
for i in range(int(input())):
	solve()


import math
import time
from collections import defaultdict, deque
from sys import stdin, stdout
from bisect import bisect_left, bisect_right
t = 1
t = int(input())
for _ in range(t):
	(n, m, k) = map(int, stdin.readline().split())
	indicard = n // k
	if m <= indicard:
		print(m)
	else:
		m -= indicard
		ans = indicard - math.ceil(m / (k - 1))
		print(ans)


from sys import stdin, stdout
import math
from collections import Counter, deque
L = lambda : list(map(int, stdin.readline().strip().split()))
M = lambda : map(int, stdin.readline().strip().split())
I = lambda : int(stdin.readline().strip())
IN = lambda : stdin.readline().strip()
C = lambda : stdin.readline().strip().split()
mod = 1000000007

def s(a):
	print(' '.join(list(map(str, a))))
for i in range(I()):
	(n, m, k) = M()
	if n / k >= m:
		print(m)
	else:
		x = n / k
		y = m - x
		print(int(x - math.ceil(y / (k - 1))))


j = int(input())

def ceildiv(a, b):
	return -(-a // b)
for i in range(j):
	(n, m, k) = [int(i) for i in input().split()]
	if m < n / k:
		print(m)
	else:
		x = n / k
		jokersRestantes = m - x
		y = -(-jokersRestantes // (k - 1))
		print(int(x - y))


import math
nb_cases = int(input())
while nb_cases > 0:
	nb_cases -= 1
	(nb_cards, nb_jokers, nb_players) = [int(x) for x in input().split()]
	nb_joker_max = min(nb_jokers, int(nb_cards / nb_players))
	nb_jokers -= nb_joker_max
	if nb_jokers == 0:
		print(nb_joker_max)
	else:
		print(nb_joker_max - math.ceil(nb_jokers / (nb_players - 1)))


def solve(n, m, k):
	d = n // k
	if m < d:
		return m
	ans = d - ((m - d - 1) // (k - 1) + 1)
	return max(ans, 0)
t = int(input())
for _ in range(t):
	(n, m, k) = [int(x) for x in input().split()]
	print(solve(n, m, k))


import math
t = int(input())
for _ in range(t):
	(n, m, k) = map(int, input().split())
	if m == 0:
		print(0)
		continue
	p = n // k
	if p >= m:
		print(m)
	else:
		m = m - p
		k = k - 1
		d = m / k
		d = math.ceil(d)
		print(p - d)


t = int(input())
for x in range(t):
	l1 = [int(x) for x in input().split()]
	(total, jokers, people) = (l1[0], l1[1], l1[2])
	nojokers = total - jokers
	if jokers <= total // people:
		print(jokers)
	else:
		maxo = total // people
		jokers -= total // people
		people -= 1
		print(maxo - int(jokers / people) - int(jokers % people != 0))


from sys import stdin, stdout
import sys
from math import *
input = stdin.readline
for __ in range(int(input())):
	(n, m, k) = map(int, input().split())
	if n // k >= m:
		print(m)
		continue
	else:
		ans = n // k
		r = m - n // k
		ans -= r // (k - 1)
		if r % (k - 1):
			ans -= 1
		print(ans)


from math import ceil
t = int(input())
for _ in range(t):
	(n, m, k) = map(int, input().split())
	per = n // k
	if m < per:
		print(m)
	else:
		rem = m - per
		print(per - ceil(rem / (k - 1)))


testCases = int(input())
for i in range(testCases):
	NMK = list(map(int, input().split(' ')))
	n = NMK[0]
	m = NMK[1]
	k = NMK[2]
	flag = 0
	if m == 0:
		print(0)
		flag = 1
	if flag == 0:
		if n / k > m:
			print(m)
		else:
			l = []
			for i in range(k):
				l.append(0)
			l[0] = int(n / k)
			m -= int(n / k)
			i = 1
			while m > 0:
				if i == 0:
					i += 1
				l[i] += 1
				i = (i + 1) % k
				m -= 1
			l.sort(reverse=True)
			print(l[0] - l[1])


T = int(input())
for _ in range(T):
	(n, m, k) = map(int, input().split())
	result = 0
	card = n // k
	player = [0] * k
	if m == 0:
		result = 0
	elif card >= m:
		result = m
	elif card < m:
		player[0] = card
		m -= card
		while m > 0:
			for i in range(1, k):
				player[i] += 1
				m -= 1
				if m == 0:
					break
		result = player[0] - player[1]
	print(result)


t = int(input())
for _ in range(t):
	(total, joker, players) = [int(u) for u in input().split()]
	cardsPerPerson = total // players
	playerL = min(cardsPerPerson, joker)
	joker -= playerL
	jokerPerPerson = joker // (players - 1)
	joker -= jokerPerPerson * (players - 1)
	if joker != 0:
		jokerPerPerson += 1
	if jokerPerPerson == playerL:
		print(0)
	else:
		print(playerL - jokerPerPerson)


import sys, math
input = sys.stdin.readline
t = int(input())
for r in range(t):
	(n, m, k) = map(int, input().split())
	x = n // k
	if m > x:
		m -= x
		temp = math.ceil(m / (k - 1))
		print(abs(x - temp))
	else:
		print(m)


from sys import stdin, stdout
import heapq
import cProfile
from collections import Counter, defaultdict, deque
from functools import reduce
import math

def get_int():
	return int(stdin.readline().strip())

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

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

def solve():
	(n, m, k) = get_tuple()
	if m == 0:
		return 0
	if m <= n // k:
		return m
	p = math.ceil((m - n // k) / (k - 1))
	if p <= 1:
		return n // k - 1
	return n // k - p

def main():
	print(solve())
TestCases = True
if TestCases:
	for i in range(get_int()):
		main()
else:
	main()


import math
for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	if m == 0 or (n // k == 1 and m != 1):
		print(0)
	elif n // k >= m:
		print(m)
	elif m == 1:
		print(1)
	else:
		a = min(m, n // k)
		b = math.ceil((m - a) / (k - 1))
		print(a - b)


t = int(input())
while t > 0:
	t -= 1
	(n, m, k) = map(int, input().split())
	d = n // k
	a1 = min(m, d)
	a2 = (m - a1 + k - 2) // (k - 1)
	print(a1 - a2)


from math import ceil

def solve(cartas, jokers, jogadores):
	mao = cartas // jogadores
	if mao > jokers:
		return jokers
	jokers -= mao
	maximo = ceil(jokers / (jogadores - 1))
	return mao - maximo
t = int(input())
for _ in range(t):
	(n, m, k) = map(int, input().split())
	print(solve(n, m, k))


def calc():
	inp = input().split(' ')
	n = int(inp[0])
	m = int(inp[1])
	k = int(inp[2])
	cardsPerPerson = n / k
	if m <= cardsPerPerson:
		print(int(m))
		return
	else:
		winnerCards = cardsPerPerson
		cardsLeftForOthers = m - winnerCards
		if cardsLeftForOthers % (k - 1) == 0:
			runnerUpCards = cardsLeftForOthers / (k - 1)
		else:
			runnerUpCards = int(cardsLeftForOthers / (k - 1)) + 1
		winnerScore = winnerCards - runnerUpCards
		print(int(winnerScore))
t = int(input())
for i in range(t):
	calc()


from bisect import bisect_left as lower_bound, bisect_right as upper_bound
from sys import stdin, stdout
from collections import defaultdict

def solve(arr, n):
	pass

def main():
	t = int(input())
	for _ in range(t):
		(n, m, k) = list(map(int, input().strip().split()))
		winner = min(n // k, m)
		left = m - winner
		second = left // (k - 1) + (1 if left % (k - 1) else 0)
		print(winner - second)
main()


import math
for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	d = n // k
	if d >= m:
		print(m)
	else:
		r = m - d
		d1 = n // k
		if k - 1 >= r:
			print(d - 1)
		else:
			x = [0] * (k - 1)
			i = 0
			while r >= 1:
				x[i] = x[i] + 1
				i += 1
				r -= 1
				if i >= len(x):
					i = 0
			print(d - max(x))


import os
import sys
from io import BytesIO, IOBase

def iin():
	return int(input())

def lin():
	return list(map(int, input().split()))
from types import GeneratorType

def bootstrap(f, stack=[]):

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

def main():
	T = iin()
	for _ in range(T):
		(n, m, k) = lin()
		ch = n // k
		a1 = min(ch, m)
		m -= a1
		a2 = 0
		if m:
			a2 = (m + k - 2) // (k - 1)
		print(a1 - a2)
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')
main()


for _ in range(int(input())):
	s = 0
	(n, m, k) = map(int, input().split())
	s = n // k
	if s > m:
		print(m)
	elif s == m:
		print(m)
	elif s < m:
		m = m - s
		if m > 1:
			if m <= k - 1:
				print(s - 1)
			elif m > k - 1:
				i = 0
				while m > k - 1:
					m = m - (k - 1)
					i += 1
				if m > 0:
					i += 1
				print(s - i)
		else:
			print(s - m)


MOD = 1000000007
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())
from collections import *
import math
for _ in range(ii()):
	(n, m, k) = f()
	a = n // k
	if n // k >= m:
		print(m)
	else:
		print(a - math.ceil((m - a) / (k - 1)))


import os
import heapq
import sys
import math
from collections import defaultdict
from io import BytesIO, IOBase

def main():
	for _ in range(int(input())):
		(n, m, k) = map(int, input().split())
		if n // k >= m:
			print(m)
		else:
			res = n // k
			rem = abs(res - m)
			if rem % (k - 1) == 0:
				print(res - rem // (k - 1))
			else:
				print(res - (rem // (k - 1) + 1))
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')
main()


from math import ceil

class Solution:

	def __init__(self):
		(self.n, self.m, self.k) = [int(x) for x in input().split()]

	def solve_and_print(self):
		if self.m == 0:
			print(0)
		else:
			x = self.n // self.k
			if x >= self.m:
				print(self.m)
			elif x < self.m:
				self.m -= x
				y = ceil(self.m / (self.k - 1))
				print(int(x - y))
for _ in range(int(input())):
	Solution().solve_and_print()


n = int(input())
for i in range(n):
	(n, m, k) = list(map(int, input().rstrip().split()))
	t = n // k
	if t >= m:
		print(m)
	elif t < m:
		val = (m - t + (k - 2)) // (k - 1)
		print(t - val)


import math
for ad in range(int(input())):
	(n, m, k) = list(map(int, input().split()))
	if m <= n // k:
		print(m)
	else:
		x = n // k
		if x > 1:
			m -= x
			y = math.ceil(m / (k - 1))
			print(x - y)
		elif m > 1:
			print(0)
		else:
			print(1)


t = int(input())
for _ in range(t):
	(n, m, k) = map(int, input().split())
	cards = n / k
	val = min(cards, m)
	op = (m - val) // (k - 1)
	if (m - val) % (k - 1) != 0:
		op += 1
	ans = abs(val - op)
	print(int(ans))


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


t = int(input())
while t > 0:
	t -= 1
	(n, m, k) = map(int, input().split())
	x = n / k
	maxx = 0
	if x >= m:
		print(m)
	else:
		y = int(x)
		cards = int(m - x)
		players = int(k - 1)
		if cards <= players:
			maxx = 1
		elif cards % players == 0:
			maxx = cards / players
		else:
			z = cards // players
			maxx = z + 1
		print(int(y - maxx))


import math
cases = int(input())
while cases:
	cases -= 1
	(n, m, k) = map(int, input().split())
	cards = n // k
	if cards >= m:
		print(m)
	else:
		rem = math.ceil((m - cards) / (k - 1))
		print(cards - rem)


import math
for _ in range(int(input())):
	(n, m, k) = map(int, input().split())

	def poker(n, m, k):
		x = n // k
		if m <= x:
			return m
		else:
			other_p_j = m - x
			oMax_jocker = math.ceil(other_p_j / (k - 1))
			return x - oMax_jocker
	print(poker(n, m, k))


a = int(input())
for fewfweefw in range(a):
	lst = input().split()
	lst = [int(p) for p in lst]
	n = lst[0]
	m = lst[1]
	k = lst[2]
	card = n / k
	if card >= m:
		print(int(m))
	else:
		m = m - card
		k = k - 1
		if m % k == 0:
			print(int(card - m // k))
		else:
			a = m // k
			print(int(card - a - 1))


from sys import stdin
import math
t = int(input())
for _ in range(t):
	(n, m, k) = list(map(int, stdin.readline().rstrip().split(' ')))
	hand = n // k
	if m <= hand:
		answer = m
	else:
		maxP = hand
		m -= hand
		q = math.ceil(m / (k - 1))
		answer = maxP - q
	print(answer)


import math
for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	val = m - int(n / k)
	if val == 0:
		print(m)
	if val < 0:
		print(m)
	if val > 0:
		left = math.ceil(val / (k - 1))
		nums = int(n / k)
		m = m - val
		if left >= nums:
			print(0)
		else:
			ans = m - left
			if ans >= 0:
				print(ans)
			else:
				print(0)


t = int(input())
for i in range(t):
	(n, m, k) = [int(j) for j in input().split()]
	c = n // k
	q = min(c, m)
	z = m - q
	x = z // (k - 1) + bool(z % (k - 1))
	print(q - x)


import sys
import math

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

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

def input():
	return sys.stdin.readline().strip()
for _ in range(int(input())):
	(n, m, k) = get_ints()
	if n // k >= m:
		print(m)
	else:
		a = n // k
		b = m - a
		print(a - math.ceil(b / (k - 1)))


from sys import stdin, stdout
from math import ceil
t = int(input())
for _ in range(t):
	(n, m, k) = map(int, stdin.readline().split())
	if m == 0:
		print(0)
	elif n == k:
		print(1 if m <= 1 else 0)
	elif n / k >= m:
		print(m)
	else:
		ans = n / k - ceil((m - n / k) / (k - 1))
		print(int(ans))


t = int(input())
x = 1
while x <= t:
	x += 1
	d = 0
	e = 0
	s = False
	(n, m, k) = map(int, input().split())
	if n / k >= m:
		print(m)
	elif n / k < m:
		d = n / k
		c = m - d
		while s == False:
			if c <= k - 1:
				print(int(d - 1))
				s = True
				break
			elif c > k - 1:
				c = c - (k - 1)
				d -= 1
				s = False


test = int(input())
for _ in range(test):
	(n, m, k) = map(int, input().split())
	cards = n // k
	max_joker = min(cards, m)
	rem_joker = m - max_joker
	print(max_joker + -rem_joker // (k - 1))


import math
for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	indcards = n // k
	if m <= indcards:
		print(m)
		continue
	z = m - indcards
	y = math.ceil(z / (k - 1))
	print(indcards - y)


import math
for w in range(int(input())):
	(n, m, k) = list(map(int, input().split()))
	card = n / k
	if card >= m:
		print(m)
	else:
		m -= card
		print(int(card - math.ceil(m / (k - 1))))


t = int(input())
while t > 0:
	(p, q, r) = input().split()
	n = int(p)
	m = int(q)
	k = int(r)
	p1 = n / k
	if n == k and m > 1:
		ans = 0
	elif m > p1:
		m = m - p1
		x = p1
		if m % (k - 1) == 0:
			y = m / (k - 1)
			ans = x - y
		else:
			y = int(m / (k - 1)) + 1
			ans = x - y
	else:
		ans = m
	print(int(ans))
	t -= 1


from sys import stdin as sin
a = int(input())
for _ in range(a):
	data = sin.readline().rstrip()
	(n, m, k) = (int(i) for i in data.split(' '))
	ub = n / k
	if ub > m:
		print(m)
	else:
		left = m - ub
		if not left % (k - 1):
			print(int(ub - left // (k - 1)))
		else:
			print(int(ub - left // (k - 1) - 1))


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(n, m, k) = [int(x) for x in input().split()]
	n_k = n // k
	winner = min(n_k, m)
	other = m - winner
	cnt = 0
	while other > 0:
		other -= k - 1
		cnt += 1
	print(winner - cnt)


def func(n):
	for i in range(n):
		l = list(map(int, input().split()))
		cards = l[0]
		joker = l[1]
		players = l[2]
		if joker == 0:
			print(0)
			continue
		else:
			d = []
			cards_to_give = cards // players
			for i in range(players):
				d.append(0)
			if joker < cards_to_give:
				print(joker)
				continue
			else:
				d[0] += cards_to_give
				joker -= cards_to_give
				j = 1
				while joker > 0:
					d[j] += 1
					joker -= 1
					j += 1
					if j == len(d):
						j = 1
			first = 0
			second = 0
			if len(d) >= 2:
				first += max(d)
				d[d.index(max(d))] = 0
				second += max(d)
				print(first - second)
			else:
				print(max(d))
n = int(input())
func(n)


x = int(input())
for i in range(0, x):
	m = list(map(int, input().split()))[:3]
	p = m[0] // m[2]
	if p >= m[1]:
		print(m[1])
	else:
		d = m[1] - p
		if (m[1] - p) % (m[2] - 1) == 0:
			print(p - d // (m[2] - 1))
		else:
			print(p - (d // (m[2] - 1) + 1))


for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	if m == 0:
		print(0)
	elif k == 1:
		print(m)
	elif m <= n // k:
		print(m)
	else:
		l = list()
		j = m - n // k
		for i in range(k - 1, 0, -1):
			l.append(j // i)
			j -= j // i
		print(n // k - max(l))


import math

def main():
	t = int(input())
	for _ in range(t):
		(n, m, k) = input().split()
		(n, m, k) = (int(n), int(m), int(k))
		pc = n // k
		if pc >= m:
			if m > 0:
				print(m)
			else:
				print(0)
		else:
			rj = m - pc
			tmp = int(math.ceil(rj / (k - 1)))
			print(pc - tmp)
main()


tst = int(input())
while tst > 0:
	ip = input()
	nwt = ip.split()
	(n, m, k) = (int(nwt[0]), int(nwt[1]), int(nwt[2]))
	pp = n / k
	ans = 0
	if m <= pp:
		ans = m
	else:
		rem = m - pp
		tmp = int(rem / (k - 1))
		if rem % (k - 1) != 0:
			tmp = tmp + 1
		ans = int(pp - tmp)
	print(ans)
	tst = tst - 1


from math import ceil
Ans = []
for _ in range(int(input())):
	X = list(map(int, input().split()))
	Max = min(X[0] // X[-1], X[1])
	Ans.append(str(Max - ceil((X[1] - Max) / (X[-1] - 1))))
print('\n'.join(Ans))


t = int(input())
for q in range(t):
	(n, m, k) = list(map(int, input().split(' ')))
	d = n // k
	if d >= m:
		print(m)
	else:
		m -= d
		k -= 1
		res = m // k
		if res == 0:
			print(d - 1)
		elif m % k != 0:
			print(d - (res + 1))
		else:
			print(d - res)


t = int(input(''))
while t > 0:
	(n, m, k) = map(int, input().split())
	ind_cards = n // k
	if ind_cards >= m:
		print(m)
	else:
		ans = ind_cards - (m - ind_cards) // (k - 1)
		if (m - ind_cards) % (k - 1) != 0:
			ans -= 1
		print(ans)
	t -= 1


g = int(input())
for i in range(g):
	testcase = [int(j) for j in input().split()]
	numberOfCards = testcase[0] / testcase[2]
	if testcase[1] <= numberOfCards:
		print(testcase[1])
	else:
		jokersLeft = testcase[1] - numberOfCards
		print(int(numberOfCards - jokersLeft / (testcase[2] - 1)))


import math
t = int(input())
for _ in range(t):
	(n, m, k) = map(int, input().split())
	cards = n // k
	if cards >= m:
		ans = m
	else:
		jokers = m - cards
		spread = math.ceil(jokers / (k - 1))
		ans = cards - spread
	print(ans)


import sys
import math
input = lambda : sys.stdin.readline().strip()
t = int(input())
while t:
	t -= 1
	(n, m, k) = map(int, input().split())
	each = n // k
	player1 = min(each, m)
	m -= player1
	rem = k - 1
	if m != 0:
		ans = player1 - math.ceil(m / rem)
	else:
		ans = player1
	print(ans)


t = int(input())
count = 0
while count < t:
	count += 1
	l = list(map(int, input().split(' ')))
	n = l[0]
	m = l[1]
	k = l[2]
	per = n / k
	M = min(per, m)
	m -= M
	if m == 0:
		print(int(M))
	elif m % (k - 1) == 0:
		print(int(M - m / (k - 1)))
	else:
		print(int(M - int(m / (k - 1)) - 1))


import math

def point(n, m, k):
	ans = n / k
	if m == 0 or n == m:
		return 0
	elif ans >= m:
		return m
	else:
		if (m - ans) % (k - 1) != 0:
			ans1 = int((m - ans) / (k - 1) + 1)
		else:
			ans1 = (m - ans) / (k - 1)
		if ans == ans1:
			return 0
		else:
			return ans - ans1
for i in range(int(input())):
	(n, m, k) = map(int, input().split())
	print(int(point(n, m, k)))


import sys
import string
input = sys.stdin.readline
import math
l = int(input())
for i in range(l):
	n = list(map(int, input().split()))
	x = int(n[0] / n[2])
	if x >= n[1]:
		print(n[1])
	else:
		j_left = n[1] - x
		per = math.ceil(j_left / (n[2] - 1))
		print(x - per)


for i in range(int(input())):
	(n, m, k) = map(int, input().split())
	d = n // k
	FLEX = min(m, d)
	FLEX2 = (m - FLEX + k - 2) // (k - 1)
	print(FLEX - FLEX2)


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
mod = int(pow(10, 9) + 7)
mod2 = 998244353

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

def out(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

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 [l1d(n, val) for j in range(m)]
for _ in range(l()[0]):
	(n, m, k) = l()
	print(min(m, (n - m) // (k - 1)))


import sys
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

def solve():
	(n, m, k) = I()
	ok = n // k
	if m <= ok:
		print(m)
	else:
		print(ok - ceil((m - ok) / (k - 1)))
(t,) = I()
while t:
	t -= 1
	solve()


import math

def main():
	test_cases = int(input())
	for t in range(test_cases):
		(n, m, k) = list(map(int, input().split()))
		c = int(n / k)
		if m <= c:
			print(int(m))
		else:
			print(int(c - math.ceil((m - c) / (k - 1))))
main()


import sys
input = sys.stdin.readline
import math

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

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

def insr():
	s = input().strip()
	return list(s[:len(s)])

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

def from_file(f):
	return f.readline

def solution(n, m, k):
	if m <= n // k:
		return m
	res = n // k - math.ceil((m - n // k) / (k - 1))
	return res
t = inp()
for _ in range(t):
	(n, m, k) = invr()
	print(solution(n, m, k))


import math
t = int(input())
for _ in range(t):
	(n, j, k) = map(int, input().split())
	cpp = n // k
	if j == 0 or j == 1 or j <= cpp:
		print(j)
	elif j > cpp:
		v = math.ceil((j - cpp) / (k - 1))
		print(cpp - v)


import math
t = int(input())
n = 0
m = 0
k = 0
x = 0
y = 0
z = 0
result = []
k = 0
for i in range(t):
	(n, m, k) = [int(a) for a in input().split()]
	x = n / k
	if m == 0:
		result.append('0')
	elif x >= m:
		result.append(m)
	else:
		y = m - x
		z = int(math.ceil(y / (k - 1)))
		result.append(int(x - z))
for j in result:
	print(j)


import sys, math
input = sys.stdin.readline
T = int(input())
for _ in range(T):
	(n, m, k) = map(int, input().split())
	if m <= n // k:
		print(m)
	else:
		print(max(n // k - math.ceil((m - n // k) / (k - 1)), 0))


for _ in range(int(input())):
	(n, m, k) = list(map(int, input().split()))
	each = n // k
	if m == 0:
		print(0)
	else:
		d = n // k
		a1 = min(m, d)
		a2 = (m - a1 + k - 2) // (k - 1)
		print(a1 - a2)


import sys
input = sys.stdin.readline

def ceil(a, b):
	return -(-a // b)
t = int(input())
for _ in range(t):
	(n, m, k) = map(int, input().split())
	j1 = min(m, n // k)
	left = m - j1
	j2 = ceil(left, k - 1)
	print(j1 - j2)


import math
cases = int(input())
for i in range(cases):
	(n, j, k) = [int(p) for p in input().split()]
	nk = n // k
	if nk >= j:
		print(j)
	else:
		print(nk - math.ceil((j - nk) / (k - 1)))


t = int(input())
while t:
	(n, m, k) = input().split()
	n = int(n)
	m = int(m)
	k = int(k)
	if n / k >= m:
		print(m)
	elif m == 0 or n / k == 1:
		print(0)
	else:
		o = n // k
		mx = 0
		r = m - n // k
		for i in range(1, k):
			s = r // (k - i)
			mx = max(mx, s)
			r = r - mx
		print(o - mx)
	t = t - 1


import math

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

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

def instr():
	s = input()
	return list(s[:len(s)])

def invr():
	return map(int, input().split())
t = inp()
while t:
	(n, m, k) = invr()
	p = n // k
	if p >= m:
		print(m)
	elif k == 2:
		p1 = p
		p2 = m - p
		print(p1 - p2)
	else:
		p1 = p
		temp = (m - p1) // (k - 1)
		if (m - p1) % (k - 1) != 0:
			temp += 1
		print(p1 - temp)
	t -= 1


t = int(input())
import math
for _ in range(t):
	(n, m, k) = map(int, input().split())
	if m <= n // k:
		print(m)
		continue
	else:
		tmax = n // k
		other = m - n // k
		othermax = math.ceil(other / (k - 1))
		print(tmax - othermax)


for _ in range(int(input())):
	(n, jo, p) = map(int, input().split())
	n //= p
	if n >= jo:
		print(jo)
		continue
	jo -= n
	p -= 1
	print(n - (jo + p - 1) // p)


t = int(input())
while t:
	t -= 1
	(n, m, k) = map(int, input().split())
	a = n // k
	if a < m:
		b = m - n // k
		if b % (k - 1) > 0:
			b = b // (k - 1)
			b += 1
		else:
			b = b // (k - 1)
		print(a - b)
	else:
		print(min(a, m))


import math
for t in range(int(input())):
	(cards, joker, players) = map(int, input().split())
	maxicards = cards / players
	if maxicards >= joker:
		print(joker)
	else:
		print(int(maxicards - math.ceil((joker - maxicards) / (players - 1))))


import sys, heapq
from collections import *
from functools import lru_cache
import bisect

def main():
	t = int(input())
	for _ in range(t):
		(n, m, k) = map(int, input().split(' '))
		c = n // k
		winner = min(c, m)
		others = m - winner
		others = others // (k - 1) + (others % (k - 1) > 0)
		print(winner - others)
main()


t = int(input())
while t != 0:
	(n, m, k) = map(int, input().split())
	ff = min(n // k, m)
	m -= ff
	k = k - 1
	ss = m // k
	if m % k != 0:
		ss = ss + 1
	print(ff - ss)
	t = t - 1


def solve():
	(n, m, k) = [int(x) for x in input().split()]
	cards = n // k
	if m <= cards:
		print(m)
	else:
		p1 = n // k
		rest = m - n // k
		if k - 1 >= rest:
			print(p1 - 1)
		else:
			if rest / (k - 1) == rest // (k - 1):
				vl = rest // (k - 1)
			else:
				vl = rest // (k - 1) + 1
			print(p1 - vl)
t = int(input())
for i in range(t):
	solve()


from math import ceil, floor
for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	a = n // k
	if a >= m:
		print(m)
		continue
	else:
		k -= 1
		m -= a
		ans = m / k
		if ceil(ans) == floor(ans):
			ans = int(ans)
		else:
			ans = floor(ans) + 1
		print(a - ans)


q = int(input())
for w in range(q):
	(n, m, k) = map(int, input().split())
	c = n // k
	if c >= m:
		print(m)
	elif k == 1:
		print(m)
	else:
		print(c - (m - c + k - 2) // (k - 1))


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


def main():
	import sys
	input = sys.stdin.readline
	sys.setrecursionlimit(10 ** 6)
	t = int(input())
	for _ in range(t):
		(n, m, k) = [int(x) for x in input().strip().split()]
		if m <= n // k:
			print(m)
		elif m <= k * (n // k - 1) + 1:
			print(n // k - ((m - n // k) // (k - 1) + ((m - n // k) % (k - 1) > 0)))
		else:
			print(0)
main()


from collections import defaultdict, Counter
import math

def solve(n, m, k):
	d = n // k
	if d >= m:
		return m
	else:
		c = m - d
		left = math.ceil(c / (k - 1))
		return d - left
t = int(input())
for _ in range(t):
	(n, m, k) = map(int, input().split())
	res = solve(n, m, k)
	print(res)


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


import math
t = int(input())
for _ in range(t):
	(n, m, k) = map(int, input().split())
	temp = n // k
	if m <= temp:
		print(m)
	else:
		m = m - temp
		res = temp - math.ceil(float(m) / float(k - 1))
		print(res)


from math import ceil
t = int(input())
for _ in range(t):
	(n, m, k) = [int(i) for i in input().split(' ')]
	a = n / k
	if m <= a:
		print(m)
	else:
		y = (m - a) / (k - 1)
		print(int(a - ceil(y)))


for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	x = n // k
	if x >= m:
		print(m)
		continue
	print(x - -(-(m - x) // (k - 1)))


import sys
from math import ceil
input = sys.stdin.buffer.readline

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

def sieve(n):
	a = [1] * n
	for i in range(2, n):
		if a[i]:
			for j in range(i * i, n, i):
				a[j] = 0
	return a
for __ in range(int(input())):
	(n, m, k) = I()
	if n // k >= m:
		print(m)
	else:
		left = m - n // k
		print(n // k - ceil(left / (k - 1)))


i = int(input())
for j in range(i):
	s = input().split()
	for k in range(len(s)):
		s[k] = int(s[k])
	maxpoints = 0
	totalcards = s[0]
	totalplayers = s[2]
	cardsperplayer = int(s[0] / s[2])
	jokers = s[1]
	if jokers <= cardsperplayer:
		maxpoints = jokers
	else:
		rem = (jokers - cardsperplayer) % (totalplayers - 1)
		per = (jokers - cardsperplayer - rem) / (totalplayers - 1)
		if rem == 0:
			maxpoints = cardsperplayer - per
		else:
			maxpoints = cardsperplayer - per - 1
	print(int(maxpoints))


import sys
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))
(n,) = I()
for _ in range(n):
	(n, m, k) = I()
	c = n // k
	if m <= c:
		an = m
	else:
		an = c - (m - c) // (k - 1) - bool((m - c) % (k - 1))
	print(an)


from math import ceil
t = int(input())
for caseNr in range(1, t + 1):
	a = list(map(int, input().split()))
	n = a[0]
	m = a[1]
	k = a[2]
	cards_ = n / k
	if cards_ >= m:
		print(m)
	else:
		jokers_left = m - cards_
		players_remaining = k - 1
		max_ = cards_ - ceil(jokers_left / players_remaining)
		print(int(max_))


t = int(input())
for i in range(t):
	inp = input().split()
	(n, m, k) = (int(inp[0]), int(inp[1]), int(inp[2]))
	div = n // k
	if m == 0:
		print(0)
	elif div >= m:
		print(m)
	else:
		if (m - div) % (k - 1) == 0:
			cardsRemaining = (m - div) // (k - 1)
		else:
			cardsRemaining = (m - div) // (k - 1) + 1
		point = div - cardsRemaining
		print(point)


import sys, math, cmath, time
start_time = time.time()

def solve():
	(n, m, k) = invr()
	q = min(n // k, m)
	w = math.ceil((m - q) / (k - 1))
	print(q - w)

def main():
	global tt
	if not ONLINE_JUDGE:
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	t = 1
	t = inp()
	for tt in range(t):
		solve()
	if not ONLINE_JUDGE:
		print('Time Elapsed :', time.time() - start_time, 'seconds')
	sys.stdout.close()

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

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

def insr():
	return input().strip()

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

def counter(a):
	q = [0] * max(a)
	for i in range(len(a)):
		q[a[i] - 1] = q[a[i] - 1] + 1
	return q

def string_counter(a):
	q = [0] * 26
	for i in range(len(a)):
		q[ord(a[i]) - 97] = q[ord(a[i]) - 97] + 1
	return q
ONLINE_JUDGE = __debug__
if ONLINE_JUDGE:
	input = sys.stdin.readline
main()


import math
T = int(input())
for _ in range(T):
	(n, m, k) = map(int, input().split())
	cards = n // k
	ma = min(cards, m)
	rem = m - ma
	mi = math.ceil(rem / (k - 1))
	if ma == mi:
		print(0)
	else:
		print(ma - mi)


t = int(input())
for i in range(t):
	(n, j, k) = [int(_) for _ in input().split()]
	if j <= n // k:
		print(j)
	else:
		print(n // k - (j - n // k + k - 2) // (k - 1))


import sys
import math
cases = int(input())
for c in range(cases):
	(n, m, k) = map(int, input().split())
	if m == 0 or n == m:
		print(0)
	else:
		max_card_each = n / k
		if max_card_each >= m:
			print(m)
		else:
			print(int(max_card_each - math.ceil(abs(max_card_each - m) / (k - 1))))


n = input()
p = []
for i in range(0, int(n)):
	l = input()
	t = [int(i) for i in l.split() if i.isdigit()]
	p.append(t)
for i in range(0, len(p)):
	ply = p[i][0] // p[i][2]
	if p[i][1] <= ply:
		print(p[i][1])
	else:
		lft = p[i][1] - ply
		per = p[i][2] - 1
		if per >= lft:
			print(ply - 1)
		elif lft % per == 0:
			print(ply - lft // per)
		else:
			print(ply - lft // per - 1)


import math
l = int(input())
g = list()
for i in range(l):
	(n, m, k) = map(int, input().split())
	e = n // k
	if e >= m:
		g.append(m)
	else:
		r = e
		m -= e
		while m > 0:
			r -= 1
			m -= k - 1
		g.append(r)
for i in g:
	print(i)


import collections
from math import ceil

def solve(n, m, k):
	cardsPerPlayer = n // k
	if cardsPerPlayer >= m:
		return m
	else:
		return cardsPerPlayer - ceil((m - cardsPerPlayer) / (k - 1))
t = int(input().strip())
for i in range(t):
	[n, m, k] = list(map(int, input().strip().split()))
	print(solve(n, m, k))


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 = 998244353
Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()
for _ in range(int(ri())):
	(n, m, k) = Ri()
	each = n // k
	if each >= m:
		print(m)
	else:
		per = each
		m -= each
		left = k - 1
		oth = ceil(m / left)
		print(per - oth)


def ceil(a, b):
	return -(-a // b)

def answer(n, m, k):
	cpp = n // k
	maxjpw = min(cpp, m)
	if m <= cpp:
		return m
	rem_num_jokers = m - maxjpw
	maxjpl = ceil(rem_num_jokers, k - 1)
	return maxjpw - maxjpl

def main():
	t = int(input())
	n = [0] * t
	m = [0] * t
	k = [0] * t
	for j in range(t):
		(n[j], m[j], k[j]) = [int(i) for i in input().split()]
	for j in range(t):
		print(answer(n[j], m[j], k[j]))
main()


t = int(input())
for i in range(t):
	(m, n, k) = map(int, input().split())
	c = m // k
	if n == 0 or m == n:
		print(0)
		continue
	if c >= n:
		print(n)
		continue
	if c < n:
		r = (n - c) % (k - 1)
		v = (n - c) // (k - 1)
		if r == 0:
			print(c - v)
		else:
			print(c - v - 1)


t = int(input())
for _ in range(t):
	(n, m, k) = [int(i) for i in input().strip().split()]
	each = n // k
	if m <= each:
		print(m)
	else:
		left = m - each
		k -= 1
		rounds = left // k
		if rounds * k != left:
			rounds += 1
		print(each - rounds)


from math import ceil

def poker(n, m, k):
	p = n // k
	if m <= p:
		return m
	m -= p
	q = ceil(m / (k - 1))
	if q <= p:
		return p - q
	return 0
for t in range(int(input())):
	(n, m, k) = map(int, input().split())
	print(poker(n, m, k))


for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	e = n // k
	if e >= m:
		print(m)
	else:
		f = n // k
		m -= e
		k -= 1
		a = m // k
		b = m % k
		s = a
		if b:
			s += 1
		print(f - s)


import math
t = int(input())

def f(n, m, k):
	cards_each = n // k
	if m < cards_each:
		return m
	else:
		rem_cards = m - cards_each
		max_other = math.ceil(rem_cards / (k - 1))
		return cards_each - max_other
for _ in range(t):
	(n, m, k) = map(int, input().split())
	print(f(n, m, k))


import math
t = int(input())
for case in range(t):
	(n, m, k) = list(map(int, input().split()))
	cards = n // k
	if cards >= m:
		print(m)
	else:
		m -= cards
		total = int(math.ceil(m / (k - 1)))
		print(cards - total)


for i in range(int(input())):
	(n, m, k) = [int(i) for i in input().split()]
	card = n // k
	if m <= card:
		print(m)
	elif card == 1:
		print(0)
	else:
		rem = (m - card) // (k - 1)
		if (m - card) % (k - 1) != 0:
			rem += 1
		print(card - rem)


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	d = a // c
	L = min(b, d)
	M = (b - L + c - 2) // (c - 1)
	print(L - M)


import sys, math
I = sys.stdin.readline
ans = ''
for _ in range(int(I())):
	(n, m, k) = map(int, I().split())
	if m == 0:
		ans += '0\n'
	else:
		cards = n // k
		if cards >= m:
			ans += str(m) + '\n'
		else:
			x = m - cards
			if x <= k - 1:
				ans += str(cards - 1) + '\n'
			else:
				i = math.ceil(x / (k - 1))
				max_others = max(i, x - (k - 2) * i)
				ans += str(cards - max_others) + '\n'
print(ans)


t = int(input())
case = []
for _ in range(t):
	case.append(list(map(int, input().split())))
for i in range(t):
	(n, m, k) = (case[i][0], case[i][1], case[i][2])
	max_point = min(n // k, m)
	left = m - max_point
	max_other = left // (k - 1) + (1 if left % (k - 1) else 0)
	print(max_point - max_other)


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


from math import ceil
for i in range(int(input())):
	(n, m, k) = map(int, input().split())
	d = min(n // k, m)
	a = 0
	if k - 1 != 0:
		a = ceil((m - d) / (k - 1))
	print(abs(a - d))


import math
for _ in range(int(input())):
	s = [int(i) for i in input().split()]
	n = s[0]
	m = s[1]
	k = s[2]
	count = n / k
	if count >= m:
		print(m)
	elif k >= 3:
		count2 = math.ceil((m - count) / (k - 1))
		print(int(count - count2))
	else:
		print(n - m)


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


import sys
from math import ceil
TEST = 0
if TEST == 1:
	input_file = open('inputA.txt', 'r')
	input_from_file = input_file.readlines()

def read_int():
	if TEST:
		return int(input_from_file.pop(0))
	else:
		return int(sys.stdin.readline())

def read_ints():
	if TEST:
		return list(map(int, input_from_file.pop(0).rstrip().split()))
	else:
		return list(map(int, sys.stdin.readline().split()))
t = read_int()
for test in range(t):
	(n, m, k) = read_ints()
	if m == 0:
		ans = 0
	elif m <= n / k:
		ans = m
	else:
		first = n / k
		second = ceil((m - n / k) / (k - 1))
		ans = int(first - second)
	print(ans)


import math

def main():
	t = int(input())
	for _ in range(t):
		(n, m, k) = [int(x) for x in input().split()]
		if n == m or m == 0:
			print(0)
			continue
		capacity = n // k
		if m <= capacity:
			print(m)
			continue
		if m > capacity:
			rest = math.ceil((m - capacity) / (k - 1))
			if capacity == rest:
				print(0)
			else:
				print(capacity - rest)
main()


tests = int(input())
for i in range(tests):
	numbers = input().split(' ')
	n = int(numbers[0])
	m = int(numbers[1])
	k = int(numbers[2])
	joker = min(n // k, m)
	player = (m - joker) // (k - 1)
	if (m - joker) % (k - 1) != 0:
		player += 1
	print(joker - player)


t = int(input())
for x in range(t):
	(n, m, k) = map(int, input().split())
	if n % k != 0:
		w = n // k + 1
	else:
		w = n // k
	w = min(w, m)
	m -= w
	if m % (k - 1) == 0:
		l = m // (k - 1)
	else:
		l = m // (k - 1) + 1
	print(max(0, w - l))


n = int(input())
for i in range(0, n):
	ls = list(map(int, input().rstrip().split()))
	n = ls[0]
	m = ls[1]
	k = ls[2]
	a = n // k
	if a > m:
		print(m)
	else:
		b = m - a
		if b % (k - 1) == 0:
			d = b // (k - 1)
			print(a - d)
		else:
			d = b // (k - 1)
			d = d + 1
			print(a - d)


import math
t = int(input())
for i in range(t):
	(n, m, k) = map(int, input().split())
	x = n / k
	if x >= m:
		print(m)
	else:
		y = math.ceil((m - x) / (k - 1))
		ans = x - y
		print(int(ans))


from sys import stdin
T = int(stdin.readline().strip())

def ceil(x, y):
	s = x // y
	if x % y != 0:
		s += 1
	return s
for caso in range(T):
	(n, m, k) = map(int, stdin.readline().strip().split())
	z = n // k
	x = min(z, m)
	y = m - x
	print(x - ceil(y, k - 1))


def solve(n, m, k):
	if m == 0:
		print(0)
	elif n == k and m == 1:
		print(1)
	elif n == k:
		print(0)
	elif n // k >= m:
		print(m)
	else:
		c = 0 if (m - n // k) % (k - 1) == 0 else 1
		print(n // k - (m - n // k) // (k - 1) - c)
t = int(input())
for _ in range(t):
	(n, m, k) = map(int, input().split())
	solve(n, m, k)


t = int(input())
for _ in range(t):
	(n, m, k) = map(int, input().rstrip().split(' '))
	player_c = n // k
	if m <= player_c:
		print(m)
	elif m == 0:
		print(0)
	else:
		ma = player_c
		joker_l = m - ma
		if k - 1 < joker_l:
			if joker_l % (k - 1):
				next_max = joker_l // (k - 1) + 1
			else:
				next_max = joker_l // (k - 1)
		else:
			next_max = 1
		total_p = ma - next_max
		print(total_p)


for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	if n // k >= m:
		print(m)
	else:
		a = [0] * (k - 1)
		al = n // k
		m = m - n // k
		while m != 0:
			for i in range(k - 1):
				if m == 0:
					break
				a[i] += 1
				m -= 1
		print(al - max(a))


from sys import stdin, stdout
import math
t = int(input())
for _ in range(t):
	(n, m, k) = map(int, input().split())
	z = n // k
	if m > z:
		m -= z
		ans = int(math.ceil(m / (k - 1)))
		stdout.write(str(z - ans) + '\n')
	else:
		stdout.write(str(m) + '\n')


testCase = int(input())
for _ in range(testCase):
	(n, m, k) = map(int, input().split())
	if n / k >= m:
		maxjoker = m
	else:
		maxjoker = n / k
	print(int(maxjoker - (m - maxjoker) / (k - 1)))


from math import ceil
t = int(input())
for i in range(t):
	(n, m, k) = map(int, input().split(' '))
	card = n // k
	if card >= m:
		print(m)
	else:
		left = m - card
		print(card - ceil(left / (k - 1)))


for ttt in range(int(input())):
	(n, m, k) = map(int, input().split())
	x = min(m, n // k)
	t = (m - x + k - 2) // (k - 1)
	print(x - t)


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

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

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

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

def seive():
	l = 100002
	c = [1, 1] + [0] * l
	for i in range(2, l):
		if 1 - c[i]:
			for j in range(i * i, l, i):
				c[j] = 1

def binarySearch(arr, l, r, x):
	if r >= l:
		mid = l + (r - l) // 2
		if arr[mid] == x:
			return mid
		elif arr[mid] > x:
			return binarySearch(arr, l, mid - 1, x)
		else:
			return binarySearch(arr, mid + 1, r, x)
	else:
		return -1
P = 1000000007

def main():
	for t in range(I()):
		(n, m, k) = In()
		if m == 0:
			print(0)
		else:
			v = n // k
			if v == m:
				print(v)
			elif v > m:
				print(m)
			else:
				val = (m - v) // (k - 1)
				if val >= v:
					print(0)
				else:
					if (m - v) % (k - 1) != 0:
						val += 1
					print(v - val)
main()


import math
t = int(input())
for i in range(t):
	(n, m, k) = list(map(int, input().split()))
	per = n / k
	max_o = min(per, m)
	min_o = 0
	duplicate = 0
	rem = m - max_o
	k = k - 1
	pic = math.ceil(rem / k)
	if pic == max_o:
		duplicate = 1
	elif pic < max_o:
		min_o = pic
	if duplicate == 1:
		print(0)
	else:
		print(int(max_o - min_o))


from sys import stdin
from math import gcd, sqrt
from collections import deque
input = stdin.readline
R = lambda : map(int, input().split())
I = lambda : int(input())
S = lambda : input().rstrip('\n')
for _ in range(I()):
	(n, m, k) = R()
	p = n // k
	t = min(p, m)
	r = m - t
	k -= 1
	mn = (r + k - 1) // k
	print(t - mn)


import math
t = int(input())
for _ in range(t):
	(n, m, k) = map(int, input().split())
	if n // k >= m:
		print(m)
	elif n // k < m:
		q = m - n // k
		z = math.ceil(q / (k - 1))
		print(n // k - z)


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


from sys import stdin, stdout
import math
T = int(stdin.readline())
for i in range(T):
	(n, m, k) = map(int, stdin.readline().split())
	hand_size = n // k
	if m <= hand_size:
		out = m
	else:
		out = hand_size - math.ceil((m - hand_size) / (k - 1))
	stdout.write(str(out) + '\n')


t = int(input())
for i in range(t):
	(n, m, k) = map(int, input().split())
	a = n // k
	if a >= m:
		print(m)
	else:
		m = m - a
		if m / (k - 1) == m // (k - 1) and m >= k - 1:
			print(a - m // (k - 1))
		elif m < k - 1:
			print(a - 1)
		else:
			print(a - m // (k - 1) - 1)


t = int(input())
p = []
for i in range(t):
	j = list(map(int, input().split()))
	p.append(j)

def cardsss(n, m, k):
	r = n // k
	if r >= m:
		return m
	elif r < m:
		if m > k * r or m == n:
			return 0
		else:
			m = m - r
			if m % (k - 1) == 0:
				h = m // (k - 1)
			else:
				h = m // (k - 1) + 1
			return r - h
for i in range(t):
	g = cardsss(p[i][0], p[i][1], p[i][2])
	print(g)


def max_joker(n, m, k):
	if m == 0:
		return 0
	j = n // k
	if j >= m:
		return m
	else:
		maxx = j
		sec_maxx = (m - j) // (k - 1) + 1 if (m - j) % (k - 1) != 0 else (m - j) // (k - 1)
		return maxx - sec_maxx
T = int(input())
for t in range(T):
	numbers = list(map(int, input().split()))
	(n, m, k) = (numbers[0], numbers[1], numbers[2])
	ans = max_joker(n, m, k)
	print(ans)


for __ in range(int(input())):
	(n, m, k) = [int(num) for num in input().split()]
	c = n // k
	if m < c:
		print(m)
	else:
		g = m - c
		if g % (k - 1) == 0:
			print(c - g // (k - 1))
		else:
			print(c - g // (k - 1) - 1)


tt = int(input())
while tt > 0:
	(n, m, k) = map(int, input().split())
	x = n // k
	if x >= m or m == 0:
		print(m)
	else:
		max_cards = x
		m -= x
		c = 0
		k -= 1
		c = m // k
		if m % k != 0:
			c += 1
		print(max_cards - c)
	tt -= 1


from math import ceil
from sys import stdin
input = stdin.readline

def main():
	test = int(input())
	for _ in range(test):
		(cards, jokers, players) = map(int, input().split())
		each_hand = cards // players
		winners_joker = min(jokers, each_hand)
		second_max_joker = ceil((jokers - winners_joker) / (players - 1))
		points = winners_joker - second_max_joker
		print(points)
main()


t = int(input())
for u in range(t):
	(n, m, k) = map(int, input().split())
	maxj = min(n // k, m)
	jok = m - maxj
	x = jok // (k - 1)
	if jok % (k - 1) > 0:
		x += 1
	print(maxj - x)


ipnl = lambda n: [int(input()) for _ in range(n)]
inp = lambda : int(input())
ip = lambda : [int(w) for w in input().split()]
for _ in range(inp()):
	(n, m, k) = ip()
	if m == 0:
		print(0)
		continue
	each = n // k
	if m <= each:
		print(m)
		continue
	y = (m - each - 1) // (k - 1) + 1
	print(each - y)


for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	c = n // k
	if m <= c:
		print(m)
	else:
		q = (m - c) // (k - 1)
		if (m - c) % (k - 1):
			q += 1
		print(c - q)


t = int(input())
while t > 0:
	l = [int(x) for x in input().strip().split()]
	(n, m, k) = (l[0], l[1], l[2])
	startNumber = n // k
	if m <= startNumber:
		print(m)
	else:
		x = startNumber
		m -= x
		y = m // (k - 1)
		if m % (k - 1) != 0:
			y += 1
		print(x - y)
	t -= 1


from math import ceil
t = int(input())
results = []
for case in range(t):
	(n, m, k) = map(int, input().split())
	cards = n // k
	winner = min(cards, m)
	other = m - winner
	each = ceil(other / (k - 1))
	if each >= winner:
		results.append(0)
	else:
		results.append(winner - each)
for result in results:
	print(result)


for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	r = n // k
	if m <= r:
		print(m)
		continue
	print(r - (m - r) // (k - 1)) if (m - r) % (k - 1) == 0 else print(r - (m - r) // (k - 1) - 1)


t = int(input())
import math
for _ in range(t):
	(n, m, k) = map(int, input().split())
	c = n // k
	x = min(c, m)
	y = math.ceil((m - x) / (k - 1))
	print(x - y)


import math

def process_test_case(i_t):
	(n, m, k) = map(int, input().split())
	x = min(m, n // k)
	y = math.ceil((m - x) / (k - 1))
	print(x - y)
	return None
n_tests = int(input())
for i_test in range(1, n_tests + 1):
	process_test_case(i_test)


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


nt = int(input())
for i in range(nt):
	(n, m, k) = map(int, input().split())
	one_max = min(m, n // k)
	m -= one_max
	two_max = (m + k - 2) // (k - 1)
	print(one_max - two_max)


t = int(input())
for _ in range(t):
	(cards, jokers, players) = tuple(map(int, input().split()))
	hand = cards // players
	if cards == jokers:
		response = 0
	elif cards == players:
		response = 1 if jokers == 1 else 0
	elif jokers < hand:
		response = jokers
	else:
		winning_hand = hand
		jokers = jokers - hand
		losing_hand = jokers // (players - 1) + 1 if jokers % (players - 1) > 0 else jokers // (players - 1)
		response = winning_hand - losing_hand
	print(response)


import os
import sys
from math import *
from collections import *
from bisect import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
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')

def value():
	return tuple(map(int, input().split()))

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

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
t = Int()
for _ in range(t):
	(n, m, k) = value()
	cards = n // k
	if cards >= m:
		print(m)
		continue
	m -= cards
	k -= 1
	rest = m // k
	if m % k:
		rest += 1
	print(cards - rest)


import math
t = int(input())
while t:
	(n, m, k) = map(int, input().split())
	if n // k >= m:
		print(m)
	else:
		get = n // k
		rem = m - get
		get -= math.ceil(rem / (k - 1))
		print(get)
	t -= 1


t = int(input())
for i in range(t):
	(n, m, k) = list(map(int, input().split()))
	(total, l) = (0, [0 for i in range(k - 1)])
	while m > 0:
		if total < int(n / k):
			total += 1
			m -= 1
		else:
			for i in range(k - 1):
				l[i] += 1
				m -= 1
	print(total - max(l))


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


casos = int(input())
for x in range(casos):
	(numC, numJok, jugadores) = map(int, input().split())
	x = min(numJok, int(numC / jugadores))
	y = int((numJok - x + jugadores - 2) / (jugadores - 1))
	print(int(x - y))


def ceil(a, b):
	return a // b + bool(a % b)

def solve(n, m, k):
	c = n // k
	j1 = min(c, m)
	m -= j1
	return j1 - ceil(m, k - 1)
for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	print(solve(n, m, k))


from collections import *
from bisect import *
from math import *
from heapq import *
import sys
input = sys.stdin.readline
t = int(input())
while t:
	t -= 1
	(n, m, k) = list(map(int, input().split()))
	x = n // k
	if x >= m:
		print(m)
		continue
	else:
		s = x
		re = m - x
		d = ceil(re / (k - 1))
		print(x - d)


import math
t = int(input())
for i in range(t):
	l = list(map(int, input().split()))
	n = l[0]
	m = l[1]
	k = l[2]
	if n / k >= m:
		print(m)
	else:
		x = math.ceil((m - n // k) / (k - 1))
		print(n // k - x)


def answer():
	nk = input().split()
	(n, m, k) = (int(nk[0]), int(nk[1]), int(nk[2]))
	if n // k >= m or m == 0:
		return m
	else:
		ost = 1 if (m - n // k) % (k - 1) else 0
		return n // k - ((m - n // k) // (k - 1) + ost)
for _ in range(int(input())):
	print(answer())


from math import *
for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	d = n // k
	p = min(m, d)
	q = (m - p + k - 2) // (k - 1)
	print(p - q)


from math import ceil
for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	noc = n // k
	if m <= noc:
		print(m)
	else:
		rem = m - noc
		div = ceil(rem / (k - 1))
		print(max(0, noc - div))


def solve():
	(n, m, k) = map(int, input().split())
	c = n // k
	if m < c:
		print(m)
	else:
		print(c - (m - c + k - 2) // (k - 1))
for i in range(int(input())):
	solve()


import sys
pprint = lambda s: print(' '.join(map(str, s)))
input = lambda : sys.stdin.readline().strip()
ipnut = input
for i in range(int(input())):
	(n, m, k) = map(int, input().split())
	suk = n // k
	if m <= suk:
		print(m)
	else:
		print(suk - (m - suk + k - 2) // (k - 1))


import math
for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	cards = n // k
	if cards >= m:
		print(m)
	elif k == 1:
		print(cards)
	else:
		rem = m - cards
		if rem < k - 1:
			print(cards - 1)
		else:
			print(cards - math.ceil(rem / (k - 1)))


import math as mh
h = 0
l = 0
t = int(input())
for _ in range(t):
	(n, m, k) = [int(x) for x in input().split()]
	h = min(n // k, m)
	m -= min(n // k, m)
	l = h - mh.ceil(m / (k - 1))
	if l < 0:
		print(0)
	else:
		print(l)


import math
for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	eachpl = n // k
	if m <= eachpl:
		print(m)
	else:
		m -= eachpl
		othr = math.ceil(m / (k - 1))
		print(eachpl - othr)


from sys import stdin, stdout
from math import *
from heapq import *
from collections import *

def main():
	ntest = int(stdin.readline())
	for testcase in range(ntest):
		(n, m, k) = [int(x) for x in stdin.readline().split()]
		h = n // k
		f = min(h, m)
		k -= 1
		m -= f
		n -= h
		s = (m + (k - 1)) // k
		stdout.write('%d\n' % (f - s))
	return 0
main()


for i in range(int(input())):
	(n, m, k) = map(int, input().split())
	hand = int(n / k)
	if hand >= m:
		print(m)
	else:
		hands = [0 for x in range(k)]
		hands[0] = hand
		m -= hand
		for index in range(1, k):
			while m > 0:
				for index in range(1, k):
					hands[index] += 1
					m -= 1
			hands.sort()
			print(hands[-1] - hands[-2])
			break


from sys import stdin
for case in range(int(stdin.readline())):
	(n, m, k) = [int(x) for x in stdin.readline().split()]
	hand = n // k
	maxHand = min(m, hand)
	m -= maxHand
	k -= 1
	others = m // k
	if m % k > 0:
		others += 1
	print(maxHand - others)


import sys
import math
input = sys.stdin.readline
from collections import deque
from queue import LifoQueue

def binary_search(a, n):
	L = 0
	R = len(a) - 1
	while L <= R:
		mid = L + (R - L) // 2
		if a[mid] == n:
			return mid
		elif a[mid] < n:
			L = mid + 1
		else:
			R = mid - 1
	return -1
for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	maxi = n // k
	if maxi >= m:
		print(m)
	else:
		rem = m - maxi
		if rem % (k - 1) == 0:
			print(maxi - rem // (k - 1))
		else:
			print(maxi - rem // (k - 1) - 1)


t = int(input())
for i in range(t):
	(n, m, k) = map(int, input().split())
	h = n // k
	mp = min(m, n // k)
	other = (m - mp) // (k - 1)
	if (m - mp) % (k - 1) != 0:
		other += 1
	print(mp - other)


s = []
for i in range(int(input())):
	(n, m, k) = map(int, input().split())
	import math
	if m <= n / k:
		x = m
		y = 0
	else:
		x = n / k
		l = m - x
		y = math.ceil(l / (k - 1))
	s.append(abs(int(x - y)))
for elm in s:
	print(elm)


from math import ceil
for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	max1 = min(m, n // k)
	m -= min(m, n // k)
	m2 = ceil(m / (k - 1))
	print(max1 - m2)


t = int(input())
for i in range(t):
	(nCards, nJokers, nPlayers) = map(int, input().split())
	nCardsInOnesShare = nCards // nPlayers
	ans = 0
	if nJokers > nCardsInOnesShare:
		iHave = nCardsInOnesShare
		remaining = nJokers - iHave
		howManyRoundDivided = remaining // (nPlayers - 1)
		stillLeft = remaining % (nPlayers - 1)
		if stillLeft != 0:
			toMinus = 1
		else:
			toMinus = 0
		ans = iHave - howManyRoundDivided - toMinus
	else:
		ans = nJokers
	print(ans)


import math
t = int(input())
for _ in range(t):
	(n, m, k) = map(int, input().split())
	c = int(n / k)
	if m < c:
		print(m)
	else:
		rj = m - c
		s = int(math.ceil(rj / (k - 1)))
		print(c - s)


import io
import os
from collections import Counter, defaultdict, deque

def solve(N, M, K):
	winner = min(M, N // K)
	remaining = M - winner
	player = remaining // (K - 1)
	if remaining % (K - 1) != 0:
		player += 1
	return winner - player
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
T = int(input())
for t in range(T):
	(N, M, K) = [int(x) for x in input().split()]
	ans = solve(N, M, K)
	print(ans)


from sys import stdin
input = stdin.buffer.readline
for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	g = min(m, n // k)
	print(g - (m - g + k - 2) // (k - 1))


t = int(input())
for _ in range(t):
	(n, m, k) = map(int, input().split())
	x = min(m, n // k)
	ost = m - x
	if ost % (k - 1) == 0:
		print(x - ost // (k - 1))
	else:
		print(x - ost // (k - 1) - 1)


import math
t = int(input())
for _ in range(t):
	(n, m, k) = map(int, input().split())
	w = min(n // k, m)
	m -= w
	v = math.ceil(m / (k - 1))
	print(w - v)


for _ in range(int(input())):
	(n, m, k) = [int(s) for s in input().split()]
	if k == 1:
		print(m)
		continue
	if n // k == 1:
		if m == 1:
			print(1)
		else:
			print(0)
		continue
	winner = min(n // k, m)
	m -= winner
	second = min(1, m % (k - 1)) + m // (k - 1)
	print(winner - second)


import sys
from collections import defaultdict
import math
input = sys.stdin.readline

def print_result(l):
	return print(' '.join(map(str, l)))

def timer(function):
	import time

	def wrapper(*args, **kwargs):
		t1 = time.time()
		val = function()
		t2 = time.time()
		print('Executed \\{}\\ in {:.2f} seconds.'.format(function.__name__, t2 - t1))
		return val
	return wrapper

def solve():
	(n, m, k) = map(int, input().split(' '))
	cards_each = n // k
	if cards_each >= m:
		res = m
	else:
		m -= cards_each
		others = math.ceil(m / (k - 1))
		res = cards_each - others
	print(res)
t = int(input())
for _ in range(t):
	solve()


import sys
input = sys.stdin.readline
t = int(input())
for tests in range(t):
	(n, m, k) = map(int, input().split())
	J = min(n // k, m)
	m -= J
	print(J - (m + (k - 2)) // (k - 1))


import math
n = int(input())
for i in range(n):
	line = input()
	value = line.split()
	value[0] = int(value[0])
	value[1] = int(value[1])
	value[2] = int(value[2])
	x = value[0] / value[2]
	if x >= value[1]:
		print(value[1])
	if x < value[1]:
		y = math.ceil((value[1] - x) / (value[2] - 1))
		print(int(x - y))


t = int(input())
for iteration in range(t):
	[n, m, k] = list(map(int, input().split()))
	hand = n // k
	if m <= hand:
		print(m)
	elif (m - hand) % (k - 1) == 0:
		print(hand - (m - hand) // (k - 1))
	else:
		print(hand - (m - hand) // (k - 1) - 1)


from math import *
sInt = lambda : int(input())
mInt = lambda : map(int, input().split())
lInt = lambda : list(map(int, input().split()))
t = sInt()
for _ in range(t):
	(n, m, k) = mInt()
	if m < n // k:
		print(m)
	else:
		x = n // k
		print(x - ceil((m - x) / (k - 1)))


import math
t = int(input())
for _ in range(t):
	(n, m, k) = list(map(int, input().split()))
	if int(n / k) >= m:
		print(m)
	else:
		x = int(n / k)
		y = math.ceil((m - int(n / k)) / (k - 1))
		print(x - y)


import math
for ii in range(int(input())):
	(n, m, k) = map(int, input().split())
	e = n // k
	if e >= m:
		print(m)
	else:
		x = math.ceil((m - e) / (k - 1))
		print(e - x)


import sys
from collections import defaultdict as dd
import heapq
import math
try:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
except:
	pass
input = sys.stdin.readline
for i in range(int(input())):
	(n, m, k) = map(int, input().split())
	l = n // k
	if m <= l:
		print(m)
	elif (m - l) % (k - 1) == 0:
		print(l - (m - l) // (k - 1))
	else:
		print(l - ((m - l) // (k - 1) + 1))


from math import ceil

def f(n, k):
	return ceil(n / k)
for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	z = n // k
	if m <= z:
		print(m)
		continue
	else:
		print(z - f(m - z, k - 1))


import math
t = int(input())
alist = []
for i in range(t):
	a = input().split()
	alist.append(a)
for a in alist:
	n = int(a[0])
	m = int(a[1])
	k = int(a[2])
	if n == k:
		if m == 1:
			max = 1
		else:
			max = 0
	elif m > n / k:
		x = n / k
		roc = n - n / k
		los = k - 1
		roj = m - x
		if roj % los == 0:
			y = roj / los
		else:
			z = math.floor(roj / los)
			y = z + 1
		max = x - y
	elif m == n / k:
		max = n / k
	elif m < n / k:
		max = m
	print(int(max))


numCases = int(input())
while numCases > 0:
	(n, m, k) = input().split(' ')
	jokersWinner = int(min(int(n) / int(k), int(m)))
	otherJokers = int((int(m) - jokersWinner + int(k) - 2) / (int(k) - 1))
	print(int(max(jokersWinner - otherJokers, 0)))
	numCases -= 1


for test in range(int(input())):
	(n, m, k) = map(int, input().split())
	s = n // k
	a = s
	if s >= m:
		print(m)
	else:
		k = k - 1
		if (m - s) % k == 0:
			if s == (m - s) // k:
				print(0)
			else:
				print(s - (m - s) // k)
		elif s - 1 == (m - s) // k:
			print(0)
		else:
			m = (m - s) // k
			print(s - (m + 1))


for _ in range(int(input())):
	(n, m, k) = [int(x) for x in input().split()]
	print(min(m, (n - m) // (k - 1)))


from sys import stdin, stdout
import bisect
from bisect import bisect_left as bl
from bisect import bisect_right as br
import itertools
from collections import Counter
import collections
import math
import heapq
import re

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())

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 most_frequent(list):
	return max(set(list), key=list.count)

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

def ncr(n, r, p):
	t = fact[n] * (ifact[r] * ifact[n - r] % p) % p
	return t

def Convert(string):
	li = list(string.split(''))
	return li

def SieveOfEratosthenes(n):
	global prime
	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
	f = []
	for p in range(2, n):
		if prime[p]:
			f.append(p)
	return f
prime = []
q = []

def dfs(n, d, v, c):
	global q
	v[n] = 1
	x = d[n]
	q.append(n)
	j = c
	for i in x:
		if i not in v:
			f = dfs(i, d, v, c + 1)
			j = max(j, f)
	return j

def main():
	for _ in range(inin()):
		(n, m, k) = map(int, input().split())
		temp = n // k
		count = 0
		if m > temp:
			count = temp
			m -= count
			k -= 1
			if m % k == 0:
				print(count - m // k)
			else:
				print(count - m // k - 1)
		else:
			print(m)
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')
main()


t = int(input())
for _ in range(t):
	(n, m, k) = map(int, input().split())
	hand_size = n // k
	my_hand = min(hand_size, m)
	m -= my_hand
	if m % (k - 1) == 0:
		next_hand = m // (k - 1)
	else:
		next_hand = m // (k - 1) + 1
	print(my_hand - next_hand)


for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	cards = n // k
	if cards > m:
		print(m)
	elif cards == m:
		print(cards)
	elif cards < m:
		m -= cards
		rem = m % (k - 1)
		div = m // (k - 1)
		if rem == 0:
			player = div
		else:
			player = div + 1
		print(cards - player)


from collections import Counter

def check(n, jokers, k):
	cards = n // k
	if jokers <= cards:
		return jokers
	else:
		bigger = cards
		remPlayers = k - 1
		remJokers = jokers - cards
		if remJokers <= remPlayers:
			return bigger - 1
		elif remJokers % remPlayers == 0:
			return bigger - remJokers // remPlayers
		else:
			return bigger - (remJokers // remPlayers + 1)
t = int(input())
while t:
	(n, m, k) = list(map(int, input().split()))
	print(check(n, m, k))
	t -= 1


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


from sys import stdin, stdout

def solve(n, m, k):
	if m == 0:
		return 0
	if n // k >= m:
		return m
	else:
		most = n // k
		m -= most
		if m // (k - 1) == m / (k - 1):
			return most - m // (k - 1)
		else:
			return most - (m // (k - 1) + 1)
t = int(stdin.readline())
for _ in range(t):
	(n, m, k) = map(int, stdin.readline().split())
	stdout.write(f'{solve(n, m, k)}\n')


from sys import stdin, stdout
input = lambda : stdin.readline().strip()
fast_print = stdout.write
from math import sqrt, floor, ceil
from bisect import bisect_right
T = int(input())
for _ in range(T):
	(n, m, k) = map(int, input().split())
	if m <= n // k:
		fast_print(str(m) + '\n')
	else:
		fast_print(str(n // k - ceil((m - n // k) / (k - 1))) + '\n')


num = int(input())
for _ in range(num):
	(n, m, k) = [int(i) for i in input().split()]
	if n // k >= m:
		print(m)
	else:
		m -= n // k
		if m % (k - 1) > 0:
			print(n // k - (m // (k - 1) + 1))
		else:
			print(n // k - m // (k - 1))


t = int(input())
while t > 0:
	(n, m, k) = map(int, input().split())
	card = n // k
	if card == 1 and m != 1:
		print('0')
	elif card >= m:
		print(m)
	else:
		ans = 0
		pp = m - card
		while pp != 0:
			if pp >= k - 1:
				pp -= k - 1
				ans += 1
			else:
				ans += 1
				pp = 0
		print(card - ans)
	t -= 1


t = int(input())
while t:
	(n, m, k) = map(int, input().split())
	a = n // k
	if m == 0:
		print(0)
		t -= 1
		continue
	if m <= a:
		print(m)
		t -= 1
		continue
	if m > a:
		x = m - a
		b = k - 1
		c = x // b
		if x % b == 0:
			c = c
		else:
			c = c + 1
		print(a - c)
	t -= 1


import math
t = int(input())
for _ in range(t):
	(n, m, k) = [int(c) for c in input().split()]
	if n // k >= m:
		print(m)
	else:
		rest = m - n // k
		u = math.ceil(rest / (k - 1))
		print(n // k - u)


from math import ceil
t = int(input())
int(t)
for test in range(t):
	(n, m, k) = input().split()
	n = int(n)
	m = int(m)
	k = int(k)
	cardsPerPlayer = int(n / k)
	points = 0
	if cardsPerPlayer >= m:
		points = m
	else:
		secondPlayerJokers = (m - cardsPerPlayer) / (k - 1)
		secondPlayerJokers = ceil(secondPlayerJokers)
		points = int(cardsPerPlayer - secondPlayerJokers)
	print(points)


import math
t = int(input())
for i in range(t):
	(n, m, k) = map(int, input().split())
	e = n / k
	if m == 0 or (n == k and m >= 2):
		print(0)
	elif e >= m:
		print(m)
	elif m > e:
		print(int(e - math.ceil((m - e) / (k - 1))))


from math import ceil as c
for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	each = n // k
	if m <= each:
		print(m)
	else:
		a = []
		a.append(each)
		m -= each
		k -= 1
		a.append(c(m / k))
		print(a[0] - a[1])


from pprint import pprint
import sys
input = sys.stdin.readline
q = int(input())
for _ in range(q):
	(n, m, k) = map(int, input().split())
	percard = n // k
	if m == n:
		print(0)
	elif m == 0:
		print(0)
	else:
		myjoker = min(percard, m)
		nokori = m - myjoker
		import math
		ojoker = math.ceil(nokori / (k - 1))
		print(myjoker - ojoker)


t = int(input())
ans = []
for i in range(t):
	ar = input().split(' ')
	n = int(ar[0])
	m = int(ar[1])
	k = int(ar[2])
	if n // k >= m:
		ans.append(m)
		continue
	else:
		array = [0 for i in range(k)]
		array[0] = n // k
		m = m - n // k
		i = 1
		while m > 0:
			array[i] += 1
			m -= 1
			i += 1
			if i == k:
				i = i % k + 1
		ans.append(array[0] - array[1])
for i in range(len(ans)):
	print(ans[i])


def main():
	t = int(input())
	for _ in range(t):
		(n, m, k) = map(int, input().split())
		b = n // k
		l = max(0, m - b)
		x = l // (k - 1) + (1 if l % (k - 1) else 0)
		print(min(m, b) - x)
	return
main()


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


from sys import stdin
from collections import deque
mod = 10 ** 9 + 7
import sys
import random
from queue import PriorityQueue
from bisect import bisect_right
from bisect import bisect_left
from collections import defaultdict
from math import sqrt, factorial, gcd, log2, inf, ceil
import heapq
input = lambda : sys.stdin.readline().rstrip()
from sys import stdin, stdout
from heapq import heapify, heappush, heappop
from itertools import permutations
from math import factorial as f

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p
import sys
t = int(input())
for _ in range(t):
	(n, m, k) = map(int, input().split())
	z = n // k
	if z >= m:
		print(m)
	else:
		m -= z
		print(z - ceil(m / (k - 1)))


for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	l = []
	average = n // k
	if average >= m:
		ans = m
	else:
		l.append(average)
		m -= average
		k -= 1
		if m > k and m % k == 0:
			for i in range(k):
				l.append(m // k)
		elif m > k and m % k != 0:
			for i in range(m % k):
				l.append(m // k + 1)
			for i in range(k - m % k):
				l.append(m // k)
		else:
			l.append(1)
		if l.count(max(l)) > 1:
			ans = 0
		else:
			l.sort(reverse=True)
			ans = l[0] - l[1]
	print(ans)


import math
n = int(input())

def cal(total, jokers, players):
	if jokers == 0:
		return jokers
	perhand = total // players
	if perhand >= jokers:
		return jokers
	biggest_hand = perhand
	jokers_left = jokers - perhand
	second_hand = math.ceil(jokers_left / (players - 1))
	return biggest_hand - second_hand
for i in range(n):
	(total, jokers, players) = map(int, input().split())
	print(cal(total, jokers, players))


def solve():
	(n, m, k) = [int(i) for i in input().split()]
	if m == 0:
		print('0')
		return
	CardsPerPlayer = n // k
	MaxPlayerJoker = min(m, CardsPerPlayer)
	RemJokers = m - MaxPlayerJoker
	if RemJokers == 0:
		print(MaxPlayerJoker)
		return
	if RemJokers <= k - 1:
		print(MaxPlayerJoker - 1)
		return
	if RemJokers % (k - 1) != 0:
		print(MaxPlayerJoker - (RemJokers // (k - 1) + 1))
		return
	print(MaxPlayerJoker - RemJokers // (k - 1))
t = int(input())
while t:
	solve()
	t -= 1


t = int(input())
for i in range(t):
	(n, m, k) = map(int, input().split())
	q = n // k
	if m <= q:
		print(m)
	elif m - q >= 1:
		m = m - q
		qq = m // (k - 1)
		y = m - qq * (k - 1)
		if y > 0:
			qq = qq + 1
		print(q - qq)
	else:
		print(q - (m - q))


import sys
from collections import deque, defaultdict as dd
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from itertools import permutations
from datetime import datetime
from math import ceil, sqrt, log, gcd

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

def si():
	return input()

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

def li():
	return list(mi())
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 read():
	tc = 0
	if tc:
		input = sys.stdin.readline
	else:
		sys.stdin = open('input1.txt', 'r')
		sys.stdout = open('output1.txt', 'w')

def solve():
	for _ in range(ii()):
		(n, m, k) = mi()
		x = n // k
		if m <= x:
			print(m)
			continue
		m -= x
		y = ceil(m / (k - 1))
		if x == y:
			print(0)
		else:
			print(x - y)
solve()


for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	ans = min(n // k, m)
	m -= ans
	ans -= m // (k - 1)
	if m % (k - 1):
		ans -= 1
	print(ans)


t = int(input())
for i in range(t):
	(a, b, c) = map(int, input().split())
	avg = a // c
	i_get = min(avg, b)
	avg -= 1
	b -= i_get
	c -= 1
	if b == 0:
		print(i_get)
		continue
	another_guy = b // c
	if b % c:
		another_guy += 1
	if another_guy >= i_get:
		print(0)
	else:
		print(i_get - another_guy)


def point(n, m, k):
	ans = n / k
	if m in (0, n):
		return 0
	if ans >= m:
		return m
	if (m - ans) % (k - 1) != 0:
		ans1 = int((m - ans) / (k - 1) + 1)
	else:
		ans1 = (m - ans) / (k - 1)
	if ans == ans1:
		return 0
	return ans - ans1
for i in range(int(input())):
	(n, m, k) = map(int, input().split())
	print(int(point(n, m, k)))


n = int(input())
for i in range(n):
	x = input().split()
	x = list(map(int, x))
	a = x[0] / x[2]
	if x[1] >= a:
		x[1] -= a
	else:
		a = x[1]
		x[1] = 0
	b = x[1] // (x[2] - 1)
	if x[1] % (x[2] - 1) != 0:
		b += 1
	print(int(a - b))


from math import ceil
cases = int(input())
for _ in range(cases):
	(cards, jokers, players) = map(int, input().split())
	card_amt = cards // players
	if card_amt >= jokers:
		print(jokers)
	else:
		winc = jokers - card_amt
		resc = ceil(winc / (players - 1))
		print(card_amt - resc)


import math

def solve():
	(n, m, k) = map(int, input().split())
	p = n // k
	if p >= m:
		print(m)
	else:
		mx = p
		m -= p
		sm = m // (k - 1) + (m % (k - 1) != 0)
		print(p - sm)
	return
t = 1
t = int(input())
while t > 0:
	t -= 1
	solve()


import math
import sys
import os.path
if os.path.isfile('in.txt'):
	sys.stdin = open('in.txt', 'r', encoding='utf-8')
t = int(input())
for i in range(t):
	(n, m, k) = map(int, input().split())
	each = n // k
	winner_king = min(each, m)
	m -= winner_king
	other_king = math.ceil(m / (k - 1))
	print(winner_king - other_king)


import math
for _ in range(int(input())):
	(n, m, k) = map(int, input().strip().split())
	pc = n // k
	wj = min(pc, m)
	lj = int(math.ceil((m - wj) / (k - 1)))
	print(wj - lj)


def solve():
	(n, m, k) = [int(x) for x in input().split()]
	if m <= n // k:
		print(m)
	else:
		print(n // k - (m - n // k + k - 2) // (k - 1))
t = int(input())
for _ in range(t):
	solve()


def read_ints():
	temp = input()
	ints = [int(t) for t in temp.split(' ')]
	return ints
N = int(input())
for _ in range(N):
	(n, m, k) = read_ints()
	per_player = n // k
	if per_player >= m:
		print(m)
	else:
		m -= per_player
		minmax = m // (k - 1)
		if m % (k - 1):
			minmax += 1
		print(per_player - minmax)


import math
for i in range(int(input())):
	(n, m, k) = map(int, input().split())
	if k == 1:
		print(m)
	elif m == 0:
		print(0)
	else:
		g = n // k
		cnt = k
		if m > g:
			m = m - g
			cnt = math.ceil(m / (cnt - 1))
			ans = g - cnt
			print(ans)
		else:
			print(m)


import math
t = int(input())
for test in range(t):
	(n, j, p) = map(int, input().split())
	q = n // p
	if q >= j:
		print(j)
	else:
		l = math.ceil((j - q) / (p - 1))
		print(q - l)


t = int(input())
while t:
	(n, m, k) = map(int, input().split())
	cards = n // k
	if m <= cards:
		print(m)
	elif (m - cards) % (k - 1) == 0:
		print(cards - (m - cards) // (k - 1))
	else:
		print(cards - (m - cards) // (k - 1) - 1)
	t = t - 1


from math import *

def r1(t):
	return t(input().strip())

def r2(t):
	return [t(i) for i in input().strip().split()]

def r3(t):
	return [t(i) for i in input().strip()]
for _ in range(int(input())):
	(n, m, k) = r2(int)
	ans = m
	t = n // k
	if ans <= t:
		print(ans)
	else:
		print(t - int(ceil((m - t) / (k - 1))))


import math
a = int(input())
for i in range(a):
	b = [int(x) for x in input().split()]
	c = b[0] / b[2]
	joker = min(b[1], c)
	left = math.ceil((b[1] - joker) / (b[2] - 1))
	print(int(joker - left))


from sys import stdin
import math

def inp():
	return stdin.readline().strip()
t = int(inp())
for _ in range(t):
	(n, m, k) = [int(x) for x in inp().split()]
	if n / k >= m:
		print(m)
	else:
		print(int(n / k - math.ceil((m - n / k) / (k - 1))))


t = int(input())
while t > 0:
	t = t - 1
	(n, m, k) = map(int, input().split())
	if m == 0:
		print(0)
	else:
		x = n // k
		if x >= m:
			print(m)
		else:
			b = m - x
			y = 0
			if b >= k - 1:
				while b >= k - 1:
					y = y + b // (k - 1)
					b = b - b // (k - 1) * (k - 1)
				if b > 0:
					y = y + 1
			else:
				y = 1
			print(max(0, x - y))


from collections import defaultdict as dd
from collections import deque
import bisect
import heapq
import math

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

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

def solve():
	(n, m, k) = rl()
	hand = n // k
	if hand >= m:
		print(m)
		return
	M = hand
	m -= hand
	print(M - math.ceil(m / (k - 1)))
mode = 'T'
if mode == 'T':
	t = ri()
	for i in range(t):
		solve()
else:
	solve()


t = int(input())
lis = []
out = []
for j in range(t):
	lis.append([int(i) for i in input().split()])
	(n, m, k) = lis[j]
	if n // k >= m:
		out.append(m)
	elif (m - n // k) % (k - 1) == 0:
		out.append(n // k - (m - n // k) // (k - 1))
	else:
		out.append(n // k - ((m - n // k) // (k - 1) + 1))
for i in out:
	print(i)


import math
t = int(input())
for case in range(t):
	(n, m, k) = [int(x) for x in input().split(' ')]
	j = min(m, n // k)
	ans = math.ceil((m - j) / (k - 1))
	print(j - ans)


import math
for _ in range(int(input())):
	(cards, joker, players) = list(map(int, input().split()))
	percard = cards // players
	mini = min(percard, joker)
	remaning = joker - mini
	ma = math.ceil(remaning / (players - 1))
	print(mini - ma)


import math
for _ in range(int(input())):
	(n, m, k) = list(map(int, input().split()))
	r = n // k
	x = min(r, m)
	y = max(m - r, 0)
	y = math.ceil(y / (k - 1))
	print(x - y)


from math import ceil, sqrt
t = int(input())
for _ in range(t):
	(cards, jokers, players) = [int(i) for i in input().split()]
	cards_per_player = cards // players
	max_jks_player = min(cards_per_player, jokers)
	remaining_jks = jokers - max_jks_player
	print(max_jks_player - ceil(remaining_jks / (players - 1)))


def main():
	from sys import stdin
	from sys import stdout
	from math import ceil
	input = stdin.readline
	print = stdout.write
	t = int(input())
	for _ in range(t):
		(n, m, k) = list(map(int, input().split()))
		cards_per_gamer = n // k
		if cards_per_gamer <= m:
			jokers_win = cards_per_gamer
			min_joker_per_gamer = ceil((m - jokers_win) / (k - 1))
			print('{0}\n'.format(jokers_win - min_joker_per_gamer))
		else:
			print('{0}\n'.format(m))
main()


import math
for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	if n / k > m:
		print(m)
	else:
		card = n // k
		m1 = card
		m2 = math.ceil((m - card) / (k - 1))
		print(m1 - m2)


import sys
input = sys.stdin.readline

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

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

def nCr(n, k):
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

def upper_bound(a, x, lo=0):
	hi = len(a)
	while lo < hi:
		mid = (lo + hi) // 2
		if a[mid] < x:
			lo = mid + 1
		else:
			hi = mid
	return lo

def primefs(n):
	primes = {}
	while n % 2 == 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

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

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	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
	return prime
MAXN = int(1000000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def factoriazation(x):
	ret = {}
	while x != 1:
		ret[spf[x]] = ret.get(spf[x], 0) + 1
		x = x // spf[x]
	return ret

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

def str_array():
	return input().strip().split()
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
for _ in range(int(input())):
	(n, m, k) = int_array()
	x = n // k
	if m <= x:
		print(m)
	else:
		m -= x
		others = m // (k - 1) + (m % (k - 1) > 0)
		print(abs(x - others))


from math import floor, ceil

def solve():
	(n, m, k) = map(int, input().split())
	if m <= floor(n / k):
		print(m)
	else:
		j = min(floor(n / k), m)
		m -= j
		m = ceil(m / (k - 1))
		print(j - m)
t = int(input())
for _ in range(t):
	solve()


from sys import stdin, stdout

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

def MI():
	return map(int, stdin.readline().split())
import math
t = II()
for _ in range(t):
	(n, m, k) = MI()
	ans = 0
	c = n // k
	if m <= c:
		p1 = m
		p2 = 0
	else:
		p1 = c
		p2 = (m - c) / (k - 1)
		p2 = int(math.ceil(p2))
	ans = p1 - p2
	stdout.write(str(ans) + '\n')


from math import ceil
t = int(input())
for testCase in range(t):
	(n, m, k) = [int(x) for x in input().split()]
	handSize = n // k
	if m <= handSize:
		print(m)
		continue
	jokerLeft = m - handSize
	print(handSize - ceil(jokerLeft / (k - 1)))


def get_point(n, m, k):
	if n // k >= m:
		return m
	else:
		cards = n // k
		m -= cards
		point = m // (k - 1)
		if m % (k - 1) != 0:
			point += 1
		return cards - point
t = int(input())
while t > 0:
	(n, m, k) = [int(x) for x in input().split()]
	print(get_point(n, m, k))
	t = t - 1


import sys
import math
input = sys.stdin.readline
t = int(input().strip())
while t:
	t -= 1
	(n, m, k) = map(int, input().split())
	d = n // k
	x = min(m, d)
	y = math.ceil((m - x) / (k - 1))
	print(x - y)


import collections, heapq, itertools, math, functools
groupby = itertools.groupby
rs = lambda : input()
ri = lambda : int(input())
rm = lambda : map(int, input().split())
rai = lambda : [int(x) for x in input().split()]

def solve():
	if m <= n // k:
		return m
	(q, r) = divmod(m - n // k, k - 1)
	if r == 0:
		return n // k - q
	else:
		return n // k - (q + 1)
for t in range(ri()):
	(n, m, k) = rm()
	print(solve())


def poker(n, m, k):
	c = n // k
	a = min(c, m)
	b = (m - a) / (k - 1)
	if b > int(b):
		bi = int(b) + 1
	else:
		bi = int(b)
	return a - bi

def solve():
	case = int(input())
	for i in range(case):
		(n, m, k) = list(map(int, input().split()))
		r = poker(n, m, k)
		print(r)
solve()


tc = int(input())
for ii in range(tc):
	(n, m, k) = map(int, input().split())
	dis = n // k
	first = min(dis, m)
	m1 = m - first
	others = k - 1
	second = m1 // others
	if m1 % others != 0:
		second += 1
	ans = first - second
	print(ans)


x = int(input())
arr = []
for _ in range(x):
	y = list(map(int, input().split()))
	arr.append(y)
arr2 = []
for i in arr:
	if i[1] == 0:
		arr2.append(0)
	elif i[0] // i[2] >= i[1]:
		arr2.append(i[1])
	else:
		x = i[0] // i[2]
		playerLeft = i[2] - 1
		cardLeft = i[1] - x
		y = 0
		while cardLeft > playerLeft:
			cardLeft = cardLeft - playerLeft
			y = y + 1
		y = y + 1
		arr2.append(x - y)
for j in arr2:
	print(j)


from math import ceil
for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	per = a // c
	if per >= b:
		print(b)
	else:
		print(per - ceil((b - per) / (c - 1)))


import math
t = int(input())
for i in range(t):
	(n, m, k) = map(int, input().split())
	per = n // k
	if per > m:
		print(m)
	else:
		if k == 2:
			win = 2 * per - m
		else:
			win = per - math.ceil((m - per) / (k - 1))
		print(win)


for gfhua in range(int(input())):
	(n, m, k) = list(map(int, input().split()))
	mk = min(m, n // k)
	m -= mk
	if m == 0:
		print(mk)
	else:
		print(mk - (m + k - 2) // (k - 1))


t = int(input())
for x in range(t):
	(n, m, k) = map(int, input().split())
	c = n // k
	if m <= c:
		print(m)
		continue
	if m == n or m == 0:
		print(0)
		continue
	m -= c
	k -= 1
	while k > 0 and m > 0:
		m -= k
		c -= 1
	print(c)


import sys
import math
input = sys.stdin.readline
t = int(input())
left = 0
for q in range(t):
	(n, m, k) = map(int, input().split())
	if n // k > m:
		print(m)
	else:
		m -= n // k
		left = math.ceil(m / (k - 1))
		print(n // k - left)


t = int(input())
n = []
m = []
k = []
for i in range(t):
	(n1, m1, k1) = input().split()
	n.append(int(n1))
	m.append(int(m1))
	k.append(int(k1))
for i in range(t):
	d = n[i] / k[i]
	if d >= m[i]:
		print(m[i])
	else:
		o = m[i] - d
		d2 = o // (k[i] - 1)
		d3 = o - d2 * (k[i] - 1)
		if d3 > 0:
			print(int(d - (d2 + 1)))
		else:
			print(int(d - d2))


t = int(input())
for _ in range(t):
	(n, m, k) = map(int, input().split())
	if m <= n // k:
		print(m)
		continue
	res = 0
	res += n // k
	m -= n // k
	res -= (m + k - 2) // (k - 1)
	print(res)


T = int(input())
for _ in range(T):
	(n, m, k) = map(int, input().split())
	a = n // k
	q = -((a - m) // (k - 1))
	print([a - q, m][a >= m])


import math

def solve():
	(n, m, k) = map(int, input().split())
	each = int(n / k)
	if m <= each:
		print(m)
		return 0
	rem = m - each
	print(each - math.ceil(rem / (k - 1)))
t = int(input())
for _ in range(t):
	solve()


q = int(input())
for _ in range(q):
	(n, m, k) = map(int, input().split())
	ans = 0
	for a in range(min(m, n // k), -1, -1):
		d = m - a
		f = min(d // (k - 1), n // k)
		if d % (k - 1) == 0:
			if f < a:
				ans = max(ans, a - f)
		elif f + 1 < a:
			ans = max(ans, a - f - 1)
	print(ans)


from collections import deque, defaultdict, Counter
from bisect import bisect_left, bisect
import math

def test_case():
	info = list(map(int, input().split()))
	(n, m, k) = info
	maxjokerposs = min(m, n // k)
	left = m - maxjokerposs
	if left % (k - 1) == 0:
		return maxjokerposs - left // (k - 1)
	else:
		return maxjokerposs - left // (k - 1) - 1
for _ in range(int(input())):
	ret = test_case()
	if ret != None:
		print(ret)


num_cases = int(input())
for _ in range(num_cases):
	(n, m, k) = [int(i) for i in input().split()]
	if m == 0:
		print(0)
	elif n == k:
		if m == 1:
			print(1)
		else:
			print(0)
	else:
		num_cards = n / k
		if m < num_cards:
			print(m)
		else:
			jokes = num_cards
			m -= num_cards
			daude = m % (k - 1)
			num_jokers = m // (k - 1)
			if daude:
				print(int(jokes - num_jokers - 1))
			else:
				print(int(jokes - num_jokers))


from collections import Counter, defaultdict, deque
from math import *
import sys
input = sys.stdin.readline

def solve():
	(n, m, k) = [int(x) for x in input().split()]
	p = n // k
	d = p - m
	if d >= 0:
		print(m)
	else:
		m -= p
		k -= 1
		print(p - ceil(m / k))
tt = int(input())
for test in range(tt):
	solve()


import math

def sol(n, m, k):
	if n // k >= m:
		return m
	else:
		r = m - n // k
		v = math.ceil(r / (k - 1))
		if v == n // k:
			return 0
		else:
			return n // k - v
t = int(input())
for _ in range(t):
	l = list(map(int, input().split()))
	v = sol(l[0], l[1], l[2])
	print(v)


import math
getn = lambda : int(input())
getlist = lambda : list(map(int, input().split(' ')))

def solve():
	(n, m, k) = getlist()
	cards = n / k
	if cards > m:
		return m
	else:
		return int(cards - math.ceil((m - cards) / (k - 1)))
	return
t = getn()
while t > 0:
	print(solve())
	t -= 1


def main():
	t = int(input())
	for _ in range(t):
		(n, m, k) = map(int, input().split())
		h = n // k
		if h >= m:
			print(m)
		else:
			ra = n - h
			rj = m - h
			q = rj // (k - 1)
			if q == 0:
				print(h - 1)
			elif rj % (k - 1) == 0:
				print(h - q)
			else:
				print(h - q - 1)
main()


import math

def solve():
	cards = n // k
	if m <= cards:
		print(m)
	else:
		rest = m - cards
		print(cards - math.ceil(rest / float(k - 1)))
	return
t = int(input())
for _ in range(t):
	(n, m, k) = [int(i) for i in input().split()]
	solve()


t = int(input())
for q in range(t):
	ch = input()
	L = [int(i) for i in ch.split()]
	(n, m, k) = (L[0], L[1], L[2])
	x = min(n // k, m)
	m -= x
	if m % (k - 1) == 0:
		m = m // (k - 1)
	else:
		m = 1 + m // (k - 1)
	print(x - m)


t = int(input())
for i in range(t):
	a = []
	a = list(map(int, input().split()))
	n = a[0]
	m = a[1]
	k = a[2]
	ans = 0
	if m <= n / k:
		ans = m
	else:
		ans = n // k - max(m - n // k, 0) // (k - 1)
		if max(m - n // k, 0) % (k - 1) != 0:
			ans -= 1
	if ans < 0:
		ans = 0
	print(ans)


for t in range(int(input())):
	(n, m, k) = map(int, input().split())
	if m <= n // k:
		ans = m
	else:
		winner = n // k
		m -= winner
		others = []
		for i in range(k - 1):
			others.append(0)
		i = 0
		while m > 0:
			others[i] += 1
			m -= 1
			i += 1
			if i == k - 1:
				i = 0
		ans = winner - max(others)
	print(ans)


import math
import sys
input = sys.stdin.readline
output = sys.stdout

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

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

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

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

def solve(n, m, k):
	if m == 0:
		return 0
	elif n == m:
		return 0
	elif n / k >= m:
		return m
	elif n / k < m:
		max_jok = n // k
		var = k - 1
		rem_jok = m - max_jok
		return max_jok - math.ceil(rem_jok / var)
n = inp()
for i in range(n):
	l = inlt()
	output.write(str(solve(l[0], l[1], l[2])) + '\n')


import math
T = int(input())
for t in range(T):
	(N, M, K) = [int(_) for _ in input().split()]
	if M <= N // K:
		print(M)
		continue
	M -= N // K
	m = math.ceil(M / (K - 1))
	print(N // K - m)


t = int(input())
while t:
	t = t - 1
	(n, m, k) = map(int, input().split())
	c = int(n / k)
	if c >= m:
		print(m)
	else:
		sp = m - c
		if int(sp / (k - 1)) - sp / (k - 1) == 0.0:
			print(c - int(sp / (k - 1)))
		else:
			print(c - int(sp / (k - 1)) - 1)


def main():
	t = int(input())
	for _ in range(t):
		(n, m, k) = map(int, input().split())
		v = n // k
		p1 = min(v, m)
		p2 = (m - p1 + k - 2) // (k - 1)
		print(abs(p1 - p2))
main()


import math
t = int(input())
for i in range(t):
	(n, m, k) = map(int, input().split())
	x = int(n / k)
	if x >= m:
		print(m)
	else:
		a = x
		b = m - x
		d = a - math.ceil(b / (k - 1))
		print(d)


def solv():
	(x, y, z) = map(int, input().split())
	if y == 0 or z == 0:
		print(0)
		return
	ppc = x // z
	if ppc >= y:
		print(y)
		return
	p = y - ppc
	v = p // (z - 1)
	if v == ppc:
		print(0)
		return
	if p % (z - 1) != 0:
		v += 1
	print(ppc - v)
for n in range(int(input())):
	solv()


for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	cap = n // k
	ans = [0] * n
	ans[0] = min(cap, m)
	m -= min(cap, m)
	lef = rem = 0
	if m != 0:
		lef = m // (k - 1)
		if m % (k - 1) != 0:
			rem = 1
	lef += rem
	an = ans[0] - lef
	print(an)


t = int(input())
for ck in range(t):
	(n, m, k) = map(int, input().split())
	if m <= n // k:
		print(m)
	else:
		a = (m - n // k) // (k - 1)
		if (m - n // k) % (k - 1):
			print(n // k - a - 1)
		else:
			print(n // k - a)


t = int(input())
for _ in range(t):
	(n, m, k) = map(int, input().split())
	if not m:
		print(m)
		continue
	cards = n // k
	jokers = min(cards, m)
	remJokers = m - jokers
	if not remJokers:
		print(jokers)
		continue
	mx = (remJokers + k - 1 - 1) // (k - 1)
	print(jokers - mx)


def xx(n, m, k):
	x = n // k
	if m == 0:
		print(0)
	elif x > m:
		print(m)
	else:
		print(int(x - (m - x) / (k - 1)))
t = int(input())
for x in range(t):
	(n, m, k) = map(int, input().split())
	xx(n, m, k)


import math
import sys
for _ in range(int(sys.stdin.readline())):
	(n, m, k) = map(int, sys.stdin.readline().split())
	if m <= n / k:
		print(m)
	else:
		remaining = math.ceil((m - n / k) / (k - 1))
		print(n // k - remaining)


tc = int(input())
while tc > 0:
	(n, m, k) = map(int, input().split())
	if m == 0:
		print(0)
	elif m <= n // k:
		print(m)
	else:
		h = n // k
		assert m > h
		(q, r) = divmod(m - h, k - 1)
		h -= q
		if r > 0:
			h -= 1
		print(max(h, 0))
	tc -= 1


tests = int(input())
for i in range(tests):
	(n, m, k) = map(int, input().split())
	cards = n / k
	diff = m - cards
	if diff <= 0:
		print(m)
	elif k == 1:
		print(diff)
	elif int(diff / (k - 1)) == diff / (k - 1):
		print(int(cards - int(diff / (k - 1))))
	else:
		print(int(cards - int(diff / (k - 1)) - 1))


for _ in range(int(input())):
	(n, m, k) = list(map(int, input().split()))
	if m == 0 or m == n:
		print(0)
	else:
		c = n // k
		if c >= m:
			print(m)
		else:
			u = m - c
			k -= 1
			if u % k == 0 and u > 0:
				print(c - u // k)
			else:
				print(c - u // k - 1)


from math import ceil

def solve():
	(n, m, k) = map(int, input().split(' '))
	c = n // k
	l = m - c
	if l <= 0:
		print(m)
	else:
		print(min(c, m) - ceil(l / (k - 1)))
t = int(input())
while t:
	solve()
	t -= 1


from math import ceil
t = int(input())
while t:
	t -= 1
	(n, m, k) = [int(i) for i in input().split()]
	noc = n // k
	if m <= noc:
		print(m)
	else:
		maxjok = ceil((m - noc) / (k - 1))
		print(noc - maxjok)


import math

def codeforces(n, m, k):
	if m == 0:
		return 0
	perman = n // k
	if perman >= m:
		return m
	m = m - perman
	k = k - 1
	se = int(math.ceil(m / k))
	return perman - se
n = int(input())
for i in range(n):
	(n, m, k) = [int(ele) for ele in input().split()]
	print(codeforces(n, m, k))


from math import ceil
t = int(input())
A = []
for i in range(0, t):
	s = input()
	split = s.split(' ')
	A.append(split)
for i in range(0, t):
	n = int(A[i][0])
	m = int(A[i][1])
	k = int(A[i][2])
	B = []
	for j in range(0, min(n // k, m) + 1):
		y = ceil((m - j) / (k - 1))
		B.append(j - y)
	print(max(B))


for _ in range(int(input())):
	(n, m, k) = tuple(map(int, input().split()))
	max_j = min(n // k, m)
	m -= max_j
	min_j = m // (k - 1)
	if m % (k - 1) != 0:
		min_j += 1
	print(max_j - min_j)


from math import *
t = int(input())
while t:
	t -= 1
	(n, m, k) = map(int, input().split())
	max_cards = n // k
	if m == 0:
		print('0')
	elif max_cards >= m:
		print(m)
	else:
		x = max_cards
		if (m - x) / (k - 1) == (m - x) // (k - 1):
			print(x - (m - x) // (k - 1))
		else:
			y = int(ceil((m - x) / (k - 1)))
			print(x - y)


import math
t = int(input())
for i in range(t):
	(n, m, k) = input().split()
	ma = int(int(n) / int(k))
	if ma >= int(m):
		print(m)
	elif int(m) != 0:
		c = int(m) - ma
		d = math.ceil(c / (int(k) - 1))
		if ma - d < 0:
			print(0)
		else:
			print(ma - d)
	else:
		print(0)


import math
for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	points = 0
	if m == 0:
		print(0)
	else:
		total_in_each = n // k
		if m <= total_in_each:
			print(m)
		else:
			points = total_in_each - math.ceil((m - total_in_each) / (k - 1))
			print(points)


test = int(input())
for i in range(test):
	(n, m, k) = map(int, input().strip().split(' '))
	if n / k == 1 and m == 0:
		print(0)
	else:
		result = n / k
		p = m - n / k
		dicti = dict({})
		if p <= 0:
			print(m)
		else:
			i = 1
			while i < k:
				if p != 0:
					if i in dicti.keys():
						dicti[i] += 1
					else:
						dicti[i] = 1
				else:
					break
				p -= 1
				if i == k - 1:
					i = 0
				i += 1
			print(int(result - dicti[1]))


for _ in range(int(input())):
	(n, m, k) = [int(x) for x in input().split()]
	if m <= n // k:
		print(m)
	else:
		mx = n // k
		print(mx - ((m - mx - 1) // (k - 1) + 1))


t = int(input())
for _ in range(t):
	(n, m, k) = [int(i) for i in input().split()]
	cpp = n / k
	if m <= cpp:
		print(m)
	else:
		remaining = m - cpp
		mn = remaining // (k - 1)
		if remaining % (k - 1) > 0:
			mn += 1
		print(int(cpp - mn))


n1 = int(input())
for x in range(n1):
	a = input().split(' ')
	cards = int(a[0])
	joker = int(a[1])
	players = int(a[2])
	e_card = cards // players
	if e_card == joker:
		print(joker)
	elif e_card > joker:
		print(joker)
	else:
		y = joker - e_card
		i = 0
		while y > 0:
			y = y - (players - 1)
			i = i + 1
		print(e_card - i)


for _ in range(int(input())):
	(card, joker, player) = map(int, input().split())
	get = card // player
	if joker <= get:
		print(joker)
	else:
		left = joker - get
		(num, div) = (left, player - 1)
		ans = [num // div + (1 if x < num % div else 0) for x in range(div)]
		print(get - max(ans))


import math
for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	n //= k
	k -= 1
	result = 0
	if n > m:
		result = m
	else:
		m = m - n
		if k > 0 and m:
			if m >= k:
				m = math.ceil(m / k)
			else:
				m = 1
		else:
			m = 0
		result = n - m
	print(result)


import sys
import math
input = sys.stdin.readline
for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	w = min(n // k, m)
	m -= w
	k -= 1
	l = int(math.ceil(m / k))
	if l == w:
		print(0)
	else:
		print(w - l)


import math
x = int(input())
while x != 0:
	inp = input()
	inp = inp.split()
	n = int(inp[0])
	m = int(inp[1])
	k = int(inp[2])
	inhand = n / k
	if m == 0:
		print(0)
		x -= 1
		continue
	if (inhand == 1) & (m > inhand):
		print(0)
		x -= 1
		continue
	if (inhand == 1) & (m == inhand):
		print(1)
		x -= 1
		continue
		x -= 1
		continue
	if m <= inhand:
		print(m)
		x -= 1
		continue
	if m > inhand:
		m_left = m - inhand
		val = float(m_left) / float(k - 1)
		sub = math.ceil(val)
		sub = int(sub)
		print(int(inhand - sub))
		x -= 1
		continue
	print('fail')


for i in range(int(input())):
	(n, m, k) = map(int, input().split())
	p = n // k
	if m > p:
		m1 = p
		m = m - p
	elif m <= p:
		m1 = m
		m = 0
	m2 = 0
	if k > 1:
		if m % (k - 1) == 0:
			m2 = m // (k - 1)
		else:
			m2 = m // (k - 1) + 1
	print(m1 - m2)


t = int(input())
while t > 0:
	(n, m, k) = map(int, input().split())
	if m == 0:
		print('0')
	elif n // k >= m:
		print(m)
	else:
		count = n // k
		rem_cards = m - count
		stor = rem_cards // (k - 1)
		if k - 1 >= rem_cards:
			print(max(0, count - 1))
		elif rem_cards % (k - 1) > 0:
			print(max(0, count - stor - 1))
		else:
			print(max(0, count - stor))
	t -= 1


import sys

def solve(n, m, k):
	each = n // k
	if m > each:
		rem = m - each
		op = k - 1
		min_other = rem // op + (1 if not rem % op == 0 else 0)
		max_pts = each - min_other
		return max_pts
	else:
		return m
IN = [x.strip() for x in sys.stdin.readlines()]
T = int(IN[0])
for i in range(T):
	(n, m, k) = [int(x) for x in IN[1 + i].split(' ')]
	result = solve(n, m, k)
	print(result)


from math import ceil
t = int(input())
for _ in range(t):
	(n, m, k) = map(int, input().split())
	p = min(m, n // k)
	left = m - p
	q = ceil(left / (k - 1))
	print(p - q)


for i in range(int(input())):
	(n, m, k) = map(int, input().split())
	if m <= n // k:
		print(m)
		continue
	max_2 = 0
	qu = 0
	while m > n // k:
		qu += 1
		m -= 1
	max_2 = (qu + k - 2) // (k - 1)
	print(m - max_2)


import sys
import math
for _ in range(int(sys.stdin.readline())):
	(n, m, k) = map(int, sys.stdin.readline().split())
	ours = min(int(n / k), m)
	theirs = math.ceil((m - ours) / (k - 1))
	print(ours - theirs)


t = int(input())
for _ in range(t):
	(n, m, k) = input().split()
	n = int(n)
	m = int(m)
	k = int(k)
	p = n // k
	if m - p < 0:
		print(m)
	else:
		left = m - p
		x = left / (k - 1)
		if int(x) == x:
			print(int(p - x))
		else:
			print(p - int(x) - 1)


import math as mt
for _ in range(int(input())):
	(n, m, k) = [int(i) for i in input().split()]
	x = n // k
	if m == 0:
		print(0)
	elif x >= m:
		print(m)
	else:
		m -= x
		k -= 1
		y = mt.ceil(m / k)
		print(x - y)


import math
t = int(input())
for i in range(t):
	(n, m, k) = map(int, input().split())
	if n // k >= m:
		print(m)
	else:
		y = int(math.ceil(n / k))
		y1 = m - y
		y2 = int(math.ceil(y1 / (k - 1)))
		print(y - y2)


from math import ceil
for _ in range(int(input())):
	(n, m, k) = list(map(int, input().split()))
	mx = min(n // k, m)
	left = m - mx
	mx2 = ceil(left / (k - 1))
	print(mx - mx2)


for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	x = n // k
	arr = [0] * (k - 1)
	if m <= x:
		print(m)
		continue
	maxi = x
	rem = m - maxi
	i = 0
	while rem != 0:
		arr[i] += 1
		i += 1
		rem -= 1
		if i == len(arr):
			i = 0
	z = max(arr)
	if arr.count(z) == len(arr) and z == maxi:
		print(0)
		continue
	print(maxi - z)


import os
import sys
from io import BytesIO, IOBase
from math import ceil

def solution(n, m, k):
	if m == 0 or n == m:
		write(0)
		return
	if n // k >= m:
		write(m)
	else:
		cards = n // k
		winner = cards
		left = m - cards
		res = winner - ceil(left / (k - 1))
		write(res)

def main():
	for _ in range(r_int()):
		(n, m, k) = r_array()
		solution(n, m, 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')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

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

def write(*args, end='\n'):
	for x in args[:-1]:
		sys.stdout.write(str(x) + ' ')
	sys.stdout.write(str(args[-1]))
	sys.stdout.write(end)

def r_array():
	return [int(x) for x in input().split()]

def r_int():
	return int(input())
main()


cantidad_de_casos = int(input())
for _ in range(cantidad_de_casos):
	linea = input().split(' ')
	cartas_totales = int(linea[0])
	cantidad_jokers = int(linea[1])
	cantidad_jugadores = int(linea[2])
	if cartas_totales / cantidad_jugadores < cantidad_jokers:
		aux1 = int(cartas_totales / cantidad_jugadores)
		aux2 = int((cantidad_jokers - cartas_totales / cantidad_jugadores + cantidad_jugadores - 2) / (cantidad_jugadores - 1))
		print(aux1 - aux2)
	else:
		aux2 = int((cantidad_jugadores - 2) / (cantidad_jugadores - 1))
		print(cantidad_jokers - aux2)


from sys import stdin

def readline():
	return stdin.readline()
tests = int(readline())

def solve(n, m, k):
	if m == 0:
		return 0
	step = n // k
	if step >= m:
		return m
	else:
		c = [0] * (k - 1)
		m1 = m - step
		for i in range(0, m1):
			c[i % (k - 1)] += 1
		maxim = max(c)
		return max(step - maxim, 0)
for t in range(0, tests):
	(n, m, k) = list(map(int, readline().rstrip('\n').split(' ')))
	print(solve(n, m, k))


import math
t = int(input())
for q in range(t):
	(n, m, k) = list(map(int, input().split(' ')))
	d = n // k
	if d >= m:
		print(m)
	else:
		m -= d
		k -= 1
		res = math.ceil(m / k)
		print(d - res)


from sys import stdin, stdout
import heapq as hq
from collections import defaultdict
from math import ceil
t = int(input())
for tc in range(t):
	(n, m, k) = list(map(int, stdin.readline().split()))
	each = n // k
	if m == 0:
		res = 0
	elif each >= m:
		res = m
	else:
		remain = m - each
		res = each - ceil(remain / (k - 1))
	stdout.write(str(res) + '\n')


PI = 3.141592653589793
INF = float('inf')
MOD = 1000000007

def bin32(num):
	return '{0:032b}'.format(num)

def add(x, y):
	return (x + y) % MOD

def sub(x, y):
	return (x - y + MOD) % MOD

def mul(x, y):
	return x * y % MOD

def gcd(x, y):
	if y == 0:
		return x
	return gcd(y, x % y)

def lcm(x, y):
	return x * y // gcd(x, y)

def power(x, y):
	res = 1
	x %= MOD
	while y != 0:
		if y & 1:
			res = mul(res, x)
		y >>= 1
		x = mul(x, x)
	return res

def mod_inv(n):
	return power(n, MOD - 2)

def prob(p, q):
	return mul(p, power(q, MOD - 2))

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

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

def ls():
	return [i for i in input().split()]
for t in range(ii()):
	t += 1
	(n, m, k) = li()
	x = n // k
	a = min(x, m)
	m -= a
	b = (m + k - 2) // (k - 1)
	print(a - b)


def f(a, b):
	if a % b == 0:
		return a // b
	return a // b + 1

def solve(n, m, k):
	d = n // k
	if m <= d:
		return m
	a1 = d
	a2 = f(m - a1, k - 1)
	return a1 - a2

def main():
	inp = lambda : [int(x) for x in input().split()]
	inn = lambda : int(input())
	t = inn()
	for _ in range(t):
		(n, m, k) = inp()
		print(solve(n, m, k))
main()


import math

def main(n, m, k):
	b = n // k
	if m <= b:
		return m
	r = m - b
	(dv, md) = divmod(r, k - 1)
	return b - dv - (1 if md else 0)
n = int(input())
tests = [list(map(int, input().split(' '))) for _ in range(n)]
for t in tests:
	print(main(*t))


from sys import stdin
for _ in range(int(stdin.readline())):
	(n, m, k) = map(int, stdin.readline().split())
	x = n // k
	if x >= m:
		print(m)
	else:
		y = m - n // k
		z = y // (k - 1) + (y % (k - 1) != 0)
		print(n // k - z)


import math
t = int(input())
for _ in range(t):
	(n, m, k) = list(map(int, input().split()))
	if n // k >= m:
		print(m)
	else:
		sth = m - n // k
		res = math.ceil(sth / (k - 1))
		print(n // k - res)


t = int(input())
res = [] = {}
card = int()
joker = int()
player = int()
i = int(0)
for i in range(0, t):
	(card, joker, player) = map(int, input().split())
	if joker <= card // player:
		res[i] = joker
	if joker > card // player:
		if (joker - card // player) % (player - 1) != 0:
			res[i] = card // player - ((joker - card // player) // (player - 1) + 1)
		else:
			res[i] = card // player - (joker - card // player) // (player - 1)
for i in range(0, t):
	print(res[i])


import sys
for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	cnt = n // k
	x = min(cnt, m)
	m -= x
	kek = (m + k - 2) // (k - 1)
	print(x - kek)


t = int(input())
while t:
	(n, m, k) = map(int, input().split())
	n1 = n // k
	if n1 >= m:
		print(m)
	else:
		m = m - n1
		t1 = m / (k - 1)
		if t1 == 0:
			res = n1 - 1
		elif t1 == int(t1):
			res = n1 - int(t1)
		else:
			res = n1 - int(t1) - 1
		print(res)
	t -= 1


import sys
strInp = lambda : input().strip().split()
intInp = lambda : list(map(int, strInp()))
for t in range(int(input())):
	(n, m, k) = intInp()
	cfe = n // k
	if cfe > m:
		print(m)
	else:
		mx = cfe
		re = m - mx
		if re % (k - 1) == 0:
			md = re // (k - 1)
		else:
			md = re // (k - 1)
			md += 1
		print(mx - md)


t = int(input())
while t > 0:
	tsets = 0
	(n, m, k) = list(map(int, input().split()))
	if n / k >= m:
		print(m)
	else:
		tosets = (n - n / k) / (k - 1)
		for i in range(n // k + 1, n + 1, k - 1):
			if m >= i:
				tsets += 1
		if tosets - tsets == 0:
			print(0)
		else:
			print(int(n / k - tsets))
	t -= 1


from sys import stdin, stdout

def find(N, M, K):
	Z = N // K
	X = min(Z, M)
	Y = max(0, M - X)
	return X + -Y // (K - 1)

def main():
	for _ in range(int(stdin.readline())):
		(N, M, K) = list(map(int, stdin.readline().split()))
		print(find(N, M, K))
main()


from sys import stdin
t = int(stdin.readline())
for j in range(t):
	(n, m, k) = map(int, stdin.readline().split())
	each_get = n // k
	if each_get >= m:
		if m == 0:
			print(0)
		else:
			print(m)
	else:
		left_joker = m - each_get
		if left_joker % (k - 1) == 0:
			print(each_get - left_joker // (k - 1))
		elif left_joker < k - 1:
			print(each_get - 1)
		else:
			print(each_get - left_joker // (k - 1) - 1)


T = int(input())
from math import ceil
for _ in range(T):
	(N, M, K) = map(int, input().split())
	G = min(M, N // K)
	P = ceil((M - G) / (K - 1))
	print(G - P)


from sys import stdin, stdout
import math
input = stdin.readline

def print(x):
	stdout.write(str(x) + '\n')

def solve():
	(n, m, k) = map(int, input().split())
	if n // k >= m:
		print(m)
	else:
		print(n // k - math.ceil((m - n // k) / (k - 1)))
t = 1
t = int(input())
for _ in range(t):
	solve()


from collections import defaultdict as dd

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

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

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

def ar(element, size):
	return [element for i in range(size)]

def digitsum(num):
	su = 0
	while num:
		su += num % 10
		num //= 10
	return su

def yes():
	print('YES')

def no():
	print('NO')
Testcase = inin()
for _ in range(Testcase):
	(n, m, k) = inar()
	if m <= n // k:
		print(m)
	else:
		wget = n // k
		if (m - wget) % (k - 1) == 0:
			print(wget - (m - wget) // (k - 1))
		else:
			print(wget - 1 - (m - wget) // (k - 1))


import sys
input = sys.stdin.readline
import math
for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	res = n // k
	if res >= m:
		print(m)
	else:
		ANS2 = m - res
		ANS1 = math.ceil(ANS2 / (k - 1))
		print(res - ANS1)


import math

def maxpoint(l):
	[n, m, k] = l
	cpp = int(n / k)
	if m >= cpp:
		mxj = cpp
		left = m - cpp
	else:
		mxj = m
		left = 0
	mxj2 = math.ceil(left / (k - 1))
	return int(mxj - mxj2)
import sys
msg = sys.stdin.readlines()
for i in msg:
	ls = list(map(int, i.split()))
	if len(ls) != 1:
		print(maxpoint(ls))


t = int(input())
while t:
	t = t - 1
	(n, m, k) = map(int, input().split())
	if m == 0 or m == 1:
		print(m)
	elif k == 1:
		print('0')
	else:
		d = n // k
		if d >= m:
			print(m)
		else:
			ans = d
			m = m - d
			z = m % (k - 1)
			z1 = m // (k - 1)
			if z != 0:
				z = 1
			ans = d - z1 - z
			print(ans)


def solve(n, m, k):
	cpp = n // k
	first = min(cpp, m)
	rest = m - first
	second = rest // (k - 1)
	if rest % (k - 1):
		second += 1
	return first - second
t = int(input())
for i in range(t):
	[n, m, k] = list(map(int, input().split(' ')))
	print(solve(n, m, k))


t = int(input())
for _ in range(t):
	(n, m, k) = map(int, input().split())
	a = n // k
	c = 0
	if a >= m:
		c = m
	else:
		s = a
		m = m - a
		if m % (k - 1) == 0:
			d = m // (k - 1)
			c = s - d
		else:
			d = m // (k - 1)
			d = d + 1
			c = s - d
	print(c)


from sys import stdin, exit
input = stdin.readline

def i():
	return input()

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

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

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

def print_array(a):
	print(' '.join(map(str, a)))
t = ii()
for _ in range(t):
	(n, m, k) = iis()
	venc = min(n // k, m)
	m -= venc
	resto = m // (k - 1)
	if m % (k - 1) != 0:
		resto += 1
	print(venc - resto)


r = int(input())
for i in range(r):
	(n, m, k) = map(lambda x: int(x), input().split())
	c = int(n / k)
	if c >= m:
		print(m)
	elif m > n - k + 1:
		print(0)
	else:
		d = (m - c) // (k - 1)
		e = (m - c) % (k - 1)
		if e == 0:
			print(c - d)
		else:
			print(c - d - 1)


t = int(input())
cnt = 0
for cnt in range(t):
	(n, m, k) = map(int, input().split())
	z = n / k
	if z >= m:
		print(m)
	else:
		p = 0
		a = [0] * k
		while m > 0:
			if p == 0:
				a[p] = z
				m -= z
			else:
				a[p] += 1
				m -= 1
			p += 1
			if p == len(a):
				p = 1
		print(int(a[0] - a[1]))
		a.clear()


for i in range(int(input())):
	(n, m, k) = map(int, input().split())
	r = 0
	if m > n / k:
		m -= n // k
		if m % (k - 1) != 0:
			r = 1
		o = m // (k - 1) + r
		print(n // k - o)
	elif m <= n / k:
		print(m)


import sys
sys.setrecursionlimit(10 ** 5)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')

def II():
	return int(sys.stdin.readline())

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

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

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def SI():
	return sys.stdin.readline()[:-1]

def main():
	for _ in range(II()):
		(n, m, k) = MI()
		mx = min(n // k, m)
		mn = (m - mx + k - 2) // (k - 1)
		print(mx - mn)
main()


test = int(input())
while test > 0:
	(n, m, k) = map(int, input().split(' '))
	p = n // k
	if p >= m:
		print(m)
	else:
		x = p
		m -= p
		k -= 1
		y = m // k
		if m % k != 0:
			y += 1
		print(x - y)
	test -= 1


t = int(input())
for i in range(t):
	(n, m, k) = list(map(int, input().split()))
	nc = n // k
	if m == 0:
		print(0)
	elif m >= nc:
		m = m - nc
		s = m // (k - 1)
		if m % (k - 1) != 0:
			s = s + 1
		print(nc - s)
	else:
		print(m)


import sys
import math
import collections
from sys import stdin, stdout, setrecursionlimit
import bisect as bs
setrecursionlimit(2 ** 20)
M = 10 ** 9 + 7

def solve():
	(n, m, k) = list(map(int, stdin.readline().split()))
	each_max = n / k
	if m < each_max:
		print(m)
		return
	else:
		x1 = each_max
		x2 = m - each_max
		x3 = x2 // (k - 1)
		x4 = x2 % (k - 1)
		if x4 > 0:
			x3 += 1
		print(int(x1 - x3))
		return
t = 1
t = int(stdin.readline())
for _ in range(t):
	solve()


import math
t = int(input())
for _ in range(t):
	(n, m, k) = map(int, input().split())
	if m == 0:
		print(0)
		continue
	c = n / k
	if m <= c:
		print(int(m))
	else:
		m = m - c
		if m <= k - 1:
			print(int(c - 1))
		else:
			ans = c - math.ceil(m / (k - 1))
			print(int(ans))


import math
from sys import stdin, stdout
import sys
import fractions
mod = 1000000007
F = fractions.Fraction
t = int(stdin.readline())
while t > 0:
	(n, m, k) = list(map(int, stdin.readline().split()))
	tmp = n // k
	if tmp >= m:
		stdout.write(f'{m}\n')
	else:
		stdout.write(f'{tmp - (m - tmp) // (k - 1) - ((m - tmp) % (k - 1) != 0)}\n')
	t -= 1


import sys
import math
from collections import defaultdict, deque
import heapq
t = int(sys.stdin.readline())
for _ in range(t):
	(n, m, k) = map(int, sys.stdin.readline().split())
	cards = n // k
	if cards > m:
		ans = m
	else:
		rem = m - cards
		y = math.ceil(rem / (k - 1))
		ans = cards - y
	print(ans)


t = int(input())
for _ in range(t):
	(n, m, k) = list(map(int, input().split()))
	div = n // k
	j = 0
	f = 0
	ff = 0
	if m == 0:
		print('0')
	elif div >= m:
		print(m)
	else:
		j = m - div
		f = j / (k - 1)
		ff = int(f)
		if ff == f:
			print(div - ff)
		else:
			print(div - ff - 1)


n_tests = int(input())
for i in range(n_tests):
	(n_cards, n_jokers, n_players) = [int(i) for i in input().split()]
	if n_jokers == 0:
		print('0')
		continue
	cards_per_player = n_cards / n_players
	if cards_per_player >= n_jokers:
		print(n_jokers)
		continue
	winner_jokers = n_jokers - cards_per_player
	result = cards_per_player - winner_jokers / (n_players - 1)
	print(int(result))


from math import ceil
for i in range(int(input())):
	(n, m, k) = map(int, input().split())
	if m == 0:
		print('0')
		continue
	x = min(n // k, m)
	y = ceil((m - x) / (k - 1))
	print(x - y)


n = int(input())
rri = lambda : int(input())
rrm = lambda : list(map(int, input().split()))

def solve(n, m, k):
	hand = n // k
	if hand >= m:
		return m
	else:
		return hand - ((m - hand) // (k - 1) + +((m - hand) % (k - 1) != 0))
for _ in range(n):
	(n, m, k) = rrm()
	print(solve(n, m, k))


import math
t = int(input())
for i in range(t):
	(n, m, k) = map(int, input().split())
	d = n // k
	a1 = min(m, d)
	a2 = math.ceil((m - a1) / (k - 1))
	print(a1 - a2)


import math
for nt in range(int(input())):
	(n, m, k) = map(int, input().split())
	if k == 1:
		print(m)
		continue
	s = n // k
	print(min(m, s) - math.ceil((m - min(m, s)) / (k - 1)))


t = int(input())
for _ in range(t):
	(n, m, k) = input().split()
	n = int(n)
	m = int(m)
	k = int(k)
	per = int(n / k)
	if per >= m:
		print(m)
	else:
		b = int((m - per) / (k - 1))
		if (m - per) % (k - 1) != 0:
			b += 1
		print(per - b)


for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	c = n // k
	t1 = min(m, c)
	t2 = (m - t1 + k - 2) // (k - 1)
	print(t1 - t2)


test = int(input())
for i in range(test):
	(n, m, k) = [int(i) for i in input().split()]
	cards = n // k
	if cards >= m:
		print(m)
	else:
		rem = m - cards
		if rem % (k - 1) == 0:
			ans = cards - rem // (k - 1)
		else:
			ans = cards - (rem // (k - 1) + 1)
		print(ans)


import sys
input = sys.stdin.buffer.readline

def main():
	t = int(input())
	for _ in range(t):
		(n, m, k) = map(int, input().split())
		v = min(n // k, m)
		m -= v
		ans = v
		ans -= (m + k - 2) // (k - 1)
		print(ans)
main()


import math, sys
from sys import stdin, stdout
from collections import Counter, defaultdict, deque
input = stdin.readline
I = lambda : int(input())
li = lambda : list(map(int, input().split()))

def solve():
	(n, m, k) = li()
	if m <= n // k:
		print(m)
	else:
		m -= n // k
		print(n // k - int(math.ceil(m / (k - 1))))
for _ in range(I()):
	solve()


import math
t = int(input())
for i in range(t):
	(n, m, k) = map(int, input().split())
	p = n // k
	if p >= m:
		print(m)
	elif m == 0:
		print(0)
	elif p < m:
		c = m - p
		b = int(math.ceil(c / (k - 1)))
		print(p - b)


for _ in range(int(input())):
	(n, m, k) = [int(num) for num in input().split()]
	c_p_player = n // k
	winner = 0
	r_up = 0
	if c_p_player >= m:
		winner = m
	else:
		winner = c_p_player
		m -= c_p_player
		if m % (k - 1) == 0:
			r_up = m // (k - 1)
		else:
			r_up = m // (k - 1) + 1
	if winner - r_up < 0:
		print(0)
	else:
		print(winner - r_up)


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')

def fact(x):
	if x == 0:
		return 1
	else:
		return x * fact(x - 1)

def lower_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] >= num:
			answer = middle
			end = middle - 1
		else:
			start = middle + 1
	return answer

def upper_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] <= num:
			answer = middle
			start = middle + 1
		else:
			end = middle - 1
	return answer

def abs(x):
	return x if x >= 0 else -x

def binary_search(li, val, lb, ub):
	ans = 0
	while lb <= ub:
		mid = (lb + ub) // 2
		if li[mid] > val:
			ub = mid - 1
		elif val > li[mid]:
			lb = mid + 1
		else:
			ans = 1
			break
	return ans
for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	each = n // k
	pl = [0] * k
	if m <= each:
		print(m)
	else:
		pl[0] = each
		m -= pl[0]
		for i in range(1, k):
			pl[i] = m // (k - i)
			m -= pl[i]
		pl.sort()
		print(pl[-1] - pl[-2])


import math
t = int(input())
for _ in range(t):
	(n, m, k) = [int(i) for i in input().split()]
	n1 = int(n / k)
	if m <= n1:
		print(m)
	else:
		m1 = m - n1
		m2 = math.ceil(m1 / (k - 1))
		print(n1 - m2)


t = int(input())
ans = []
for g in range(t):
	(n, m, k) = map(int, input().split())
	x = min(n // k, m)
	y = (m - x + k - 2) // (k - 1)
	ans += [x - y]
for i in ans:
	print(i)


import math

def ques1(n, m, k):
	if m == n:
		print(0)
	elif n // k >= m:
		print(m)
	else:
		m = m - n // k
		tmp = math.ceil(m / (k - 1))
		print(n // k - tmp)
t = int(input())
for i in range(t):
	(n, m, k) = [int(i) for i in input().split()]
	ans = ques1(n, m, k)
	ans


import math
t = int(input())
for _ in range(t):
	(n, m, k) = map(int, input().split())
	var = n // k
	if var >= m:
		print(m)
	else:
		m -= var
		nia = math.ceil(m / (k - 1))
		print(var - nia)


from math import *
for u in range(int(input())):
	(n, m, k) = map(int, input().split())
	if m == 0:
		print(0)
	else:
		x = n // k
		if x >= m:
			print(m)
		elif (m - x) % (k - 1) == 0:
			print(x - (m - x) // (k - 1))
		else:
			print(x - ((m - x) // (k - 1) + 1))


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


for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	deck = n // k
	print(min(deck - ((m - deck - 1) // (k - 1) + 1), m))


z = input
from math import *
for lk in range(int(z())):
	(n, m, k) = map(int, z().split())
	nc = n // k
	wp = min(m, n // k)
	op = m - wp
	opm = ceil(op / (k - 1))
	print(wp - opm)


import math as mt
import sys
from collections import *
inf = float('inf')

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

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

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

def gmat(n, m):
	return [[0] * m for _ in range(n)]

def imat(n):
	return [list(mii()) for _ in range(n)]
try:
	sys.stdin = open('a.in', 'r')
	input = sys.stdin.readline
except:
	pass
for _ in range(ii()):
	(n, m, k) = mii()
	t = min(n // k, m)
	t1 = (m - t + k - 2) // (k - 1)
	print(t - t1)


import math
t = int(input())
for _ in range(t):
	(n, m, k) = map(int, input().split())
	ans = 0
	if n // k >= m:
		ans = m
	elif n // k < m:
		x = n // k
		a1 = m - n // k
		y = math.ceil(a1 / (k - 1))
		ans = x - y
	print(ans)


from math import ceil
for _ in range(0, int(input())):
	(n, m, k) = map(int, input().split())
	hand = round(n / k)
	if hand > m:
		print(m)
		continue
	else:
		answer = hand - ceil((m - hand) / (k - 1))
		print(answer)


for i in range(int(input())):
	(n, m, k) = map(int, input().split())
	c = n // k
	if m == 0:
		d = 0
	elif m <= c:
		d = m
	else:
		d = (m - c) // (k - 1)
		if (m - c) % (k - 1) != 0:
			d += 1
		d = c - d
	print(d)


def calculate_the_points(n, m, k):
	x = n // k
	if m <= x:
		return m
	else:
		r = m - x
		if r % (k - 1) == 0:
			y = r // (k - 1)
		else:
			y = r // (k - 1) + 1
		return x - y
from sys import stdin as f
t = int(f.readline().strip())
for _ in range(t):
	(n, m, k) = [int(i) for i in f.readline().strip().split()]
	print(calculate_the_points(n, m, k))


def points(n, m, k):
	if m == 0:
		return 0
	if m <= n / k:
		return m
	m -= n / k
	cont = 0
	while m > 0 and cont < n / k:
		cont += 1
		m -= k - 1
	return n / k - cont
t = int(input())
for i in range(0, t):
	(n, m, k) = map(int, input().split())
	print(int(points(n, m, k)))


t = int(input())
for i in range(t):
	(n, m, k) = map(int, input().split())
	ans = 0
	d = n // k
	for a1 in range(m + 1):
		for a2 in range(a1 + 1):
			if a1 > d:
				continue
			if a1 + a2 > m:
				continue
			if a1 + (k - 1) * a2 < m:
				continue
			ans = max(ans, a1 - a2)
	print(ans)


for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	per = n // k
	if per >= m:
		print(m)
	else:
		win = per
		left = m - win
		if m - win < k - 1:
			print(win - 1)
		elif left % (k - 1) != 0:
			print(win - left // (k - 1) - 1)
		else:
			print(win - left // (k - 1))


from math import *
from collections import *
from itertools import *
from bisect import *
from heapq import *
from operator import *
from sys import *
setrecursionlimit(1000000)
d = defaultdict(lambda : 0, {})

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

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

def o():
	return int(input())

def l(x):
	return len(x)

def r(x):
	if type(x) == int:
		return range(x)
	else:
		return range(len(x))

def kl(con, x=0):
	if x == 0:
		print('Yes') if con else print('No')
	elif x == 1:
		print('yes') if con else print('no')
	elif x == 2:
		print('YES') if con else print('NO')
MOD = 1000000007
MAX = float('inf')
MIN = -float('inf')
p = input
for _ in range(o()):
	(n, m, k) = io()
	if m == 0 or m == n:
		print(0)
		continue
	c = n // k
	x1 = min(c, m)
	m -= x1
	x2 = ceil(m / (k - 1))
	print(x1 - x2) if x1 - x2 > 0 else print(0)


for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	j = n // k
	if m <= j:
		print(m)
	else:
		n -= j
		m -= j
		k -= 1
		n -= m
		if n >= k:
			zx = m // k
			if m % k:
				zx += 1
			print(j - zx)
		else:
			print(0)


rw = int(input())
for ewqr in range(rw):
	(n, m, k) = map(int, input().split())
	if n // k >= m:
		print(m)
	else:
		f = m - n // k
		print(n // k - (f + k - 1 - 1) // (k - 1))


from __future__ import division, print_function
import os, sys
import math
import collections
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, reverse=True)

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 ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(n - r))

def binary_search(arr, low, high, x):
	if high >= low:
		mid = (high + low) // 2
		if arr[mid] == x:
			return mid
		elif arr[mid] > x:
			return binary_search(arr, low, mid - 1, x)
		else:
			return binary_search(arr, mid + 1, high, x)
	else:
		return -1

def ceil(x, y):
	if x % y == 0:
		return x // y
	else:
		return x // y + 1

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 padded_bin_with_complement(x):
	if x < 0:
		return bin(2 ** 16 - abs(x))[2:].zfill(16)
	else:
		return bin(x)[2:].zfill(16)

def binaryToDecimal(binary):
	binary1 = binary
	(decimal, i, n) = (0, 0, 0)
	while binary != 0:
		dec = binary % 10
		decimal = decimal + dec * pow(2, i)
		binary = binary // 10
		i += 1
	print(decimal)

def CountFrequency(arr):
	return collections.Counter(arr)

def pos(a):
	b = [0] * len(a)
	c = sorted(a)
	for i in range(len(a)):
		for j in range(len(a)):
			if c[j] == a[i]:
				b[i] = j
				break
	return b

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

def main():
	for _ in range(ii()):
		(n, m, k) = mi()
		if m == 0:
			print(0)
			continue
		x = min(n // k, m)
		y = min(n // k, math.ceil((m - x) / (k - 1)))
		print(x - y)
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())
ans = []
for ti in range(t):
	(n, m, k) = list(map(int, input().split()))
	x = n // k
	if x >= m:
		ans.append(m)
	elif n == m:
		ans.append(0)
	else:
		left_m = m - x
		y = x - left_m // (k - 1)
		if left_m % (k - 1):
			y -= 1
		ans.append(y)
for a in ans:
	print(a)


t = int(input())
for i in range(t):
	(n, m, k) = map(int, input().split())
	d = n // k
	a1 = min(m, d)
	a2 = (m - a1) // (k - 1)
	t = 1 if (m - a1) % (k - 1) else 0
	a2 += t
	print(a1 - a2)


t = int(input())
for _ in range(t):
	(a, b, c) = map(int, input().split())
	if b <= a // c:
		print(b)
	else:
		m = a // c
		y = (b - m) // (c - 1)
		if (b - m) % (c - 1) != 0:
			y += 1
		print(abs(m - y))


for T in range(int(input())):
	(n, m, k) = list(map(int, input().split()))
	if m == 0:
		print(0)
	else:
		val = n // k
		if val >= m:
			print(m)
		else:
			d = m - val
			q = d // (k - 1)
			r = d % (k - 1)
			if r == 0:
				print(val - q)
			else:
				print(val - (q + 1))


import math
t = int(input())
for i in range(t):
	(n, m, k) = map(int, input().split())
	if k == 1:
		print(m)
	elif m == 0 or n == m:
		print(0)
	elif n // k >= m:
		print(m)
	elif math.ceil((m - n // k) / (k - 1)) == n // k:
		print(0)
	else:
		j = n // k - math.ceil((m - n // k) / (k - 1))
		print(j)


def solve():
	from math import ceil
	t = int(input())
	while t > 0:
		(n, m, k) = map(int, input().strip().split())
		x = n // k
		if m == 0:
			print(0)
		elif x > m:
			print(m)
		elif x <= m:
			b = ceil((m - x) / (k - 1))
			print(x - b)
		t -= 1
solve()


import math
case = int(input())
for i in range(case):
	(n, m, k) = map(int, input().split())
	if n // k >= m and m > 0:
		print(m)
	elif n // k < m:
		print(n // k - math.ceil((m - n // k) / (k - 1)))
	else:
		print(0)


for _ in [0] * int(input()):
	(n, m, k) = map(int, input().split())
	w = n // k if m >= n // k else m
	m -= w
	print(w - (m + k - 2) // (k - 1))


import math
for _ in range(int(input())):
	lis = list(map(int, input().split()))
	(cards, jokers, plrs) = (lis[0], lis[1], lis[2])
	cards_p_plr = cards // plrs
	if cards_p_plr > jokers:
		print(jokers)
	else:
		print(cards_p_plr - math.ceil((jokers - cards_p_plr) / (plrs - 1)))


import math
test = int(input())
for i in range(test):
	(n, m, k) = map(int, input().split())
	noofcards = int(n / k)
	if m <= noofcards:
		ans = m
	else:
		m = m - noofcards
		remplay = k - 1
		max2 = int(math.ceil(m / remplay))
		ans = noofcards - max2
	print(ans)


def poker(n, m, k):
	card = n // k
	a1 = min(m, card)
	a2 = (m - a1 + k - 2) // (k - 1)
	return a1 - a2
test = int(input())
for i in range(test):
	(n, m, k) = map(int, input().split())
	print(poker(n, m, k))


test_cases = int(input())
for z in range(test_cases):
	(n, m, k) = list(map(int, input().split()))
	each_player = n // k
	plain_card = n - m
	if m == 0:
		print(0)
	elif each_player >= m:
		print(m)
	elif each_player < m:
		if plain_card < k - 1:
			print(0)
		else:
			print(each_player - (each_player - plain_card // (k - 1)))


import math
for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	if m <= n // k:
		print(m)
	else:
		max1 = n // k
		k -= 1
		max2 = math.ceil((m - max1) / k)
		print(max1 - max2)


for i in range(int(input())):
	(n, m, k) = map(int, input().split())
	card_per_person = n // k
	score = min(card_per_person, m)
	m -= score
	score -= (m + k - 2) // (k - 1)
	print(score)


n1 = int(input())
for _ in range(n1):
	n = list(map(int, input().split(' ')))
	points = 0
	rem_card = 0
	point = 1
	max_cards = n[0] // n[2]
	if max_cards >= n[1]:
		points = n[1]
		print(points)
	elif n[1] == 0:
		points = 0
		print(points)
	elif max_cards < n[1]:
		rem_card = n[1] - max_cards
		d = rem_card / (n[2] - 1)
		if d == int(d):
			points = max_cards - int(d)
			print(points)
		else:
			points = max_cards - int(d) - 1
			print(points)


from math import ceil
for ttt in range(int(input())):
	(n, m, k) = map(int, input().split())
	if m < n // k:
		print(m)
	else:
		left = m - n // k
		kk = ceil(left / (k - 1))
		print(n // k - kk)


from math import ceil
for _ in range(int(input())):
	(n, m, k) = [int(i) for i in input().split()]
	x = min(m, n // k)
	y = ceil((m - x) / (k - 1))
	print(x - y)


import math
t = int(input())
for tt in range(t):
	(n, m, k) = map(int, input().split())
	temp = min(n // k, m)
	ans = temp
	xx = math.ceil((m - temp) / (k - 1))
	print(ans - xx)


tests = int(input())
for i in range(tests):
	line = list(map(int, input().split()))
	nCard = line[0]
	nJoker = line[1]
	nPlayer = line[2]
	cardByPlayer = nCard // nPlayer
	nJokerWinner = nJoker if nJoker <= cardByPlayer else cardByPlayer
	nJokerAllLooser = nJoker - nJokerWinner
	maxJokerLooser = nJokerAllLooser // (nPlayer - 1) + (nJokerAllLooser % (nPlayer - 1) != 0)
	print(nJokerWinner - maxJokerLooser)


def main():
	(n, m, k) = map(int, input().split())
	h = n // k
	d = min(h, m)
	dd = m - d
	if k == 2:
		res = d - dd
	else:
		r = dd // (k - 1)
		if dd % (k - 1):
			r += 1
		res = d - r
	print(res)
for _ in range(int(input())):
	main()


t = int(input())
while t:
	t -= 1
	(n, m, k) = input().split()
	n = int(n)
	m = int(m)
	k = int(k)
	if n // k > m:
		print(m)
	else:
		maxi = n // k
		mini = (m - maxi) / (k - 1)
		if mini - int(mini) > 0:
			mini = int(mini) + 1
		mini = int(mini)
		print(maxi - mini)


import math
t = int(input())
for _ in range(t):
	(n, m, k) = map(int, input().split())
	x = n // k
	if x >= m:
		print(m)
		continue
	print(x - math.ceil((m - x) / (k - 1)))


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	k = a // c
	if k >= b:
		print(b)
	else:
		print(k - ((b - k - 1) // (c - 1) + 1))


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


for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	c = abs(n - m)
	d = int(c / (k - 1))
	print(min(m, d))


t = int(input())
for fd in range(t):
	(n, m, k) = [int(x) for x in input().split()]
	if n // k >= m:
		print(m)
	else:
		print(n // k - (m - n // k + k - 2) // (k - 1))


import math
t = int(input())
while t:
	(n, m, k) = list(map(int, input().split()))
	p = n // k
	if p >= m:
		print(m)
	else:
		x = p
		m = m - p
		y = m // (k - 1)
		if m % (k - 1) > 0:
			y += 1
		print(x - y)
	t -= 1


from collections import Counter
import math
import sys
from bisect import bisect, bisect_left, bisect_right

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

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 mod():
	return 10 ** 9 + 7
for _ in range(INT()):
	(n, m, k) = MAP()
	a = n // k
	if a >= m:
		print(m)
	else:
		y = m - a
		p = k - 1
		z = math.ceil(y / p)
		print(a - z)


import math
for i in range(int(input())):
	(n, m, k) = map(int, input().split())
	x = min(m, n // k)
	print(x - math.ceil((m - x) / (k - 1)))


n = int(input())
for x in range(n):
	(a, m, k) = [int(x) for x in input().split()]
	ans1 = a // k
	ans2 = min(ans1, m)
	ans = (m - ans2 + k - 2) // (k - 1)
	print(ans2 - ans)


import math, sys, bisect
from collections import defaultdict, Counter, deque
from itertools import groupby, accumulate
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
ilele = lambda : map(int, input().split())
alele = lambda : list(map(int, input().split()))

def Y(c):
	print(['NO', 'YES'][c])

def y(c):
	print(['no', 'yes'][c])
for _ in range(int(input())):
	(n, m, k) = ilele()
	x = n // k
	if m == 0:
		print(0)
	elif m == 1:
		print(1)
	elif x == 1:
		if m == 1:
			print(1)
		else:
			print(0)
	elif m <= x:
		print(m)
	else:
		e = m - x
		print(x - math.ceil(e / (k - 1)))


import math
for i in range(int(input())):
	(n, m, k) = map(int, input().split())
	j = min(n // k, m)
	hgr = m - j
	if hgr <= k - 1:
		if hgr > 0:
			print(j - 1)
		else:
			print(j - 0)
	else:
		print(j - math.ceil(hgr / (k - 1)))


x = input()
y = int(x)
win = list()
while y > 0:
	(n, m, k) = input().split()
	n1 = int(n)
	m1 = int(m)
	k1 = int(k)
	each = n1 / k1
	if each >= m1:
		win.append(m1)
	else:
		xh = m1 - each
		if k1 - 1 > xh:
			z = int(each - 1)
			win.append(z)
		else:
			l = xh % (k1 - 1)
			m = int(xh / (k1 - 1))
			if l == 1:
				sh = l + m
				z = int(each - sh)
				win.append(z)
			else:
				d = l / (k1 - 1)
				sh = d + m
				z = int(each - sh)
				win.append(z)
	y = y - 1
for i in win:
	print(i)


for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	ma = min(m, n // k)
	mi = 0 - -(m - ma) // (k - 1)
	print(ma - mi)


import sys
import math
from collections import defaultdict

def solve(test):
	(n, m, k) = map(int, input().split())
	ans = min(n // k, m)
	rem = math.ceil((m - ans) / (k - 1))
	print(ans - rem)
test_cases = int(input())
for t in range(1, test_cases + 1):
	solve(t)


import sys

def read():
	return list(map(int, sys.stdin.readline().split()))
for i in range(int(input())):
	(n, m, k) = read()
	if m < n / k:
		print(m)
	else:
		print(int(n / k - (m - n / k + k - 2) // (k - 1)))


import math
t = int(input())
for ij in range(t):
	(n, j, p) = map(int, input().split())
	c = n // p
	if j == 0:
		print(0)
	elif c >= j:
		print(j)
	elif j - c <= p - 1:
		print(c - 1)
	else:
		k = math.ceil((j - c) / (p - 1))
		print(c - k)


time = int(input())
for i in range(time):
	(n, m, k) = map(int, input().split())
	n_hand = n // k
	if m <= n_hand:
		print(m)
		continue
	elif m - n_hand <= (k - 1) * (n_hand - 1):
		if (m - n_hand) % (k - 1):
			print(n_hand - (m - n_hand) // (k - 1) - 1)
		else:
			print(n_hand - (m - n_hand) // (k - 1))
	else:
		print(0)
		continue


import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
import sys
from math import ceil

def solve(n, m, k):
	max_j = min(n // k, m)
	remain = m - max_j
	other_j = ceil(remain / (k - 1))
	return max_j - other_j

def main():
	t = int(input())
	for _ in range(t):
		(n, m, k) = map(int, input().split())
		ans = solve(n, m, k)
		sys.stdout.write(str(ans) + '\n')
main()


for query in range(int(input())):
	nmk = input().split()
	n = int(nmk[0])
	m = int(nmk[1])
	k = int(nmk[2])
	if n // k >= m:
		print(m)
	else:
		other = (m - n // k) / (k - 1)
		if other > int(other):
			print(n // k - (int(other) + 1))
		else:
			print(n // k - int(other))


import math
t = int(input())
for _ in range(t):
	(n, m, k) = map(int, input().split())
	if m <= n // k:
		print(m)
	elif n == k or m == 0:
		print(0)
	else:
		ma1 = n // k
		rem = m - ma1
		print(ma1 - math.ceil(rem / (k - 1)))


import sys
import math

def II():
	return int(sys.stdin.readline())

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

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

def SI():
	return sys.stdin.readline().strip()
t = II()
for q in range(t):
	(n, m, k) = MI()
	a = n // k
	if a >= m:
		print(m)
	else:
		print(a - math.ceil((m - a) / (k - 1)))


T = int(input())
for t in range(T):
	(n, m, k) = map(int, input().rstrip().split())
	card1 = min(m, n // k)
	card2 = (max(0, m - n // k) + k - 2) // (k - 1)
	print(card1 - card2)


t = int(input())
while t != 0:
	t -= 1
	(n, m, k) = map(int, input().split())
	if m == 0:
		print(0)
	elif m <= n // k:
		print(m)
	else:
		p = n // k
		q = m
		q -= p
		l = q // (k - 1)
		if q % (k - 1) == 0:
			print(p - l)
		else:
			print(p - l - 1)


for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	t = min(n // k, m)
	print(t - (m - t) // (k - 1) - ((m - t) % (k - 1) > 0))


import itertools
t = int(input())
while t:
	nmk = list(map(int, input().split()))
	n = nmk[0]
	m = nmk[1]
	k = nmk[2]
	if m == 0:
		print(0)
		t -= 1
		continue
	else:
		nums = [i for i in range(n // k + 1)]
		max = 0
		for i in itertools.combinations_with_replacement(nums, k):
			if sum(i) == m:
				nmax = 0
				for j in i[:-1]:
					if j > nmax:
						nmax = j
				diff = i[-1] - j
				if diff > max:
					max = diff
		print(max)
	t -= 1


def solve(n, m, k):
	p1 = n // k
	if p1 >= m:
		return m
	rest = (m - p1) // (k - 1)
	rest += int((m - p1) % (k - 1) != 0)
	return max(p1 - rest, 0)
t = int(input())
for _ in range(t):
	(n, m, k) = list(map(int, input().split()))
	print(solve(n, m, k))


t = int(input())
import math
for _ in range(t):
	(n, m, k) = list(map(int, input().split(' ')))
	jokers = m
	cards = n // k
	a = cards
	jokers -= cards
	if jokers <= 0:
		print(m)
	else:
		print(a - math.ceil(jokers / (k - 1)))


for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	mcard = n // k
	if m == 0:
		print(0)
		continue
	elif m <= mcard:
		print(m)
	else:
		a = [0] * k
		a[0] = mcard
		i = 1
		m = m - mcard
		while m > 0:
			a[i] += 1
			m -= 1
			i += 1
			if i == k:
				i = 1
		m1 = max(a[1:])
		if a[0] == m1:
			print(0)
		else:
			print(a[0] - m1)


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(n, m, k) = map(int, input().split())
	if n // k >= m:
		print(m)
	else:
		mod = m - n // k
		modp = k - 1
		print(n // k - (mod + modp - 1) // modp)


from __future__ import division, print_function
import itertools
import sys
import os
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	input = raw_input
	range = xrange
	filter = itertools.ifilter
	map = itertools.imap
	zip = itertools.izip

def is_it_local():
	script_dir = str(os.getcwd()).split('/')
	username = 'dipta007'
	return username in script_dir

def READ(fileName):
	if is_it_local():
		sys.stdin = open(f'./{fileName}', 'r')
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')
if not is_it_local():
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
	input = lambda : sys.stdin.readline().rstrip('\r\n')

def input1(type=int):
	return type(input())

def input2(type=int):
	[a, b] = list(map(type, input().split()))
	return (a, b)

def input3(type=int):
	[a, b, c] = list(map(type, input().split()))
	return (a, b, c)

def input_array(type=int):
	return list(map(type, input().split()))

def input_string():
	s = input()
	return list(s)

def main():
	t = input1()
	for ci in range(t):
		(n, m, k) = input3()
		card = n // k
		mx = min(m, card)
		m -= mx
		baki_players = k - 1
		baki_mx = m // baki_players
		if m % baki_players:
			baki_mx += 1
		print(mx - baki_mx)
	pass
READ('in.txt')
main()


import math
t = int(input())
while t != 0:
	(n, m, k) = map(int, input().split())
	if m == 0:
		print(0)
	else:
		cards = n // k
		if cards >= m:
			print(m)
		else:
			maxx = m - cards
			leftmaxx = math.ceil(maxx / (k - 1))
			print(cards - leftmaxx)
	t = t - 1


t = int(input())
for i in range(t):
	(n, m, k) = map(int, input().split())
	d = n // k
	maxJ = min(m, d)
	max2J = (m - maxJ + k - 2) // (k - 1)
	print(maxJ - max2J)


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


t = int(input())
for i in range(t):
	(n, m, k) = list(map(int, input().split()))
	a = n // k
	if m <= a:
		ans = m
	else:
		m = m - a
		k -= 1
		d = m // k
		if d * k != m:
			d += 1
		ans = a - d
	print(ans)


t = int(input())
for i in range(t):
	nmk = list(map(int, input().split()))
	n = nmk[0]
	m = nmk[1]
	k = nmk[2]
	arr = []
	each = n // k
	if m == 0:
		print(0)
	elif each == m:
		print(m)
	elif each > m:
		print(m)
	elif each < m:
		arr.append(each)
		m = m - each
		while m > 0:
			k -= 1
			each = m // k
			arr.append(each)
			m = m - each
		arr.sort(reverse=True)
		print(arr[0] - arr[1])


import sys
input = sys.stdin.readline
from collections import defaultdict
import math
for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	c = n // k
	if c >= m:
		print(m)
	else:
		left = m - c
		each = math.ceil(left / (k - 1))
		print(c - each)


def solve():
	(n, m, k) = map(int, input().split())
	winner = min(m, n // k)
	m -= winner
	m = m // (k - 1) + (1 if m % (k - 1) != 0 else 0)
	print(winner - m)
t = int(input())
for tt in range(t):
	solve()


import math
t = int(input())
for i in range(t):
	(n, m, k) = map(int, input().split())
	cards_per_player = n // k
	ans = 0
	if m == 0:
		ans = 0
	if cards_per_player >= m:
		ans = m
	else:
		ans = cards_per_player - math.ceil((m - cards_per_player) / (k - 1))
	print(ans)


def solve(n, m, k):
	cards = int(n / k)
	if m == 0:
		return 0
	if m <= cards:
		return m
	if n * k == m:
		return 0
	if k > 2:
		if m > k * (cards - 1) + 1:
			return 0
	x = cards
	y = (m - cards) // (k - 1)
	c = (m - cards) % (k - 1)
	if c > 0:
		y += 1
	return max(0, x - y)
t = int(input())
for we in range(t):
	(n, m, k) = map(int, input().split())
	print(solve(n, m, k))


import math
import math
for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	n = a // c
	if b <= n:
		print(b)
		continue
	b = b - n
	ans1 = 0
	while b >= c - 1:
		b = b - (c - 1)
		ans1 += 1
	if b > 0:
		ans1 += 1
	print(n - ans1)


import math
t = int(input())
for i in range(t):
	(n, m, k) = map(int, input().split())
	p = n // k
	if m <= p:
		print(m)
	else:
		r = math.ceil((m - p) / (k - 1))
		if r >= p:
			print(0)
		else:
			print(p - r)


t = int(input())
while t > 0:
	(n, m, k) = list(map(int, input().strip(' ').split()))
	if m == 0:
		print('0')
	else:
		j = n // k
		if m <= j:
			print(m)
		else:
			l = []
			m = m - j
			for i in range(100):
				l.append(0)
			r = 0
			ma = 0
			while m != 0:
				l[r] = l[r] + 1
				if l[r] > ma:
					ma = l[r]
				m = m - 1
				r = r + 1
				if r == k - 1:
					r = 0
			print(j - ma)
	t = t - 1


a = int(input())
for i in range(a):
	(n, m, k) = map(int, input().split())
	temp = m
	if m >= n // k:
		m = m - n // k
		if m == 0:
			print(temp)
		elif m % (k - 1) == 0:
			print(n // k - m // (k - 1))
		else:
			print(n // k - m // (k - 1) - 1)
	else:
		print(m)


from math import ceil

def cards(n, m, k):
	q = n // k
	if m <= q:
		return m
	m -= q
	p = ceil(m / (k - 1))
	if p <= q:
		return q - p
	return 0
for _ in range(int(input())):
	(n, m, k) = list(map(int, input().split()))
	print(cards(n, m, k))


from math import sqrt
t = int(input())
for qq in range(t):
	(n, m, k) = [int(i) for i in input().split()]
	p = n // k
	j = max(m - p, 0)
	ma = j // (k - 1)
	if j % (k - 1):
		ma += 1
	print(min(p, m) - ma)


import math
t = int(input())
for i in range(t):
	(n1, m1, k1) = input().split(' ')
	n = int(n1)
	m = int(m1)
	k = int(k1)
	if m <= n // k:
		print(m)
	else:
		x = n // k
		y = math.ceil((m - n // k) / (k - 1))
		print(x - y)


import sys
input = sys.stdin.readline
import heapq
import copy
import math

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

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

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

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

class Node:

	def _init_(self, val):
		self.data = val
		self.left = None
		self.right = None

class fen_tree:

	def __init__(self, list):
		self.array = [0] + list
		for idx in range(1, len(self.array)):
			idx2 = idx + (idx & -idx)
			if idx2 < len(self.array):
				self.array[idx2] += self.array[idx]

	def prefix_query(self, idx):
		result = 0
		while idx:
			result += self.array[idx]
			idx -= idx & -idx
		return result

	def prints(self):
		print(self.array)
		return

	def range_query(self, from_idx, to_idx):
		return self.prefix_query(to_idx) - self.prefix_query(from_idx - 1)

	def update(self, idx, add):
		while idx < len(self.array):
			self.array[idx] += add
			idx += idx & -idx

def pre_sum(arr):
	p = [0]
	for i in arr:
		p.append(p[-1] + i)
	p.pop(0)
	return p

def pre_back(arr):
	p = [0]
	for i in arr:
		p.append(p[-1] + i)
	p.pop(0)
	return p

def bin_search(arr, l, r, val):
	if arr[r] <= val:
		return r + 1
	if r - l < 2:
		if arr[l] > val:
			return l
		else:
			return r
	mid = int((l + r) / 2)
	if arr[mid] <= val:
		return bin_search(arr, mid, r, val)
	else:
		return bin_search(arr, l, mid, val)

def search_leftmost(arr, val):

	def helper(arr, l, r, val):
		print(l, r)
		if arr[l] == val:
			return l
		if r - l <= 1:
			if arr[r] == val:
				return r
			else:
				print('not found')
				return
		mid = int((r + l) / 2)
		if arr[mid] >= val:
			return helper(arr, l, mid, val)
		else:
			return helper(arr, mid, r, val)
	return helper(arr, 0, len(arr) - 1, val)

def search_rightmost(arr, val):

	def helper(arr, l, r, val):
		print(l, r)
		if arr[r] == val:
			return r
		if r - l <= 1:
			if arr[l] == val:
				return r
			else:
				print('not found')
				return
		mid = int((r + l) / 2)
		if arr[mid] > val:
			return helper(arr, l, mid, val)
		else:
			return helper(arr, mid, r, val)
	return helper(arr, 0, len(arr) - 1, val)

def preorder_postorder(root, paths, parent, left, level):
	l = 0
	queue = [root]
	while queue != []:
		node = queue[-1]
		flag = 0
		for i in paths[node]:
			if i != parent[node] and level[i] == sys.maxsize:
				parent[i] = node
				level[i] = level[node] + 1
				flag = 1
				queue.append(i)
		if flag == 0:
			left[parent[node]] += 1 + left[node]
			queue.pop()
	return [parent, left, level]

def pr_list(a):
	print(*a, sep=' ')

def main():
	tests = inp()
	mod = 1000000007
	limit = 10 ** 18
	for test in range(tests):
		[cards, joker, player] = inlt()
		n = int(cards / player)
		if n >= joker:
			print(joker)
		else:
			j_l = joker - n
			mini = math.ceil(j_l / (player - 1))
			print(n - mini)
main()


for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	x = n // k
	if m == 0:
		print(0)
	elif x >= m:
		print(m)
	elif x == 1 and m > 1:
		print(0)
	elif m == n:
		print(0)
	elif (m - x) % (k - 1) != 0:
		print(x - (m - x) // (k - 1) - 1)
	elif (m - x) % (k - 1) == 0:
		print(x - (m - x) // (k - 1))


import math
for case in range(int(input())):
	(n, m, k) = [int(x) for x in input().split()]
	cards_per_player = n // k
	y = min(cards_per_player, m)
	m -= y
	x = math.ceil(m / (k - 1))
	print(y - x)


import math
try:
	t = int(input())
	while t:
		t -= 1
		(n, m, k) = tuple(map(int, input().split()))
		if k == 0:
			print(0)
			continue
		max_joker = min(m, n // k)
		if k == 1:
			print(max_joker)
			continue
		rem = m - max_joker
		rem = math.ceil(rem / (k - 1))
		print(max(0, max_joker - rem))
except Exception as e:
	print(str(e))


from math import ceil
t = int(input())
for _ in range(t):
	(n, m, k) = map(int, input().split())
	max_cartas = n / k
	if m < max_cartas:
		ans = m
	else:
		j = ceil((m - max_cartas) / (k - 1))
		ans = round(max_cartas - j)
	print(ans)


from sys import stdin
input = lambda : stdin.readline().strip()
char = [chr(i) for i in range(97, 123)]
CHAR = [chr(i) for i in range(65, 91)]
mp = lambda : list(map(int, input().split()))
INT = lambda : int(input())
rn = lambda : range(INT())
from math import ceil, sqrt, factorial, gcd
for _ in rn():
	(n, m, k) = mp()
	h = n // k
	if m <= h:
		print(m)
	else:
		l = ceil((m - h) / (k - 1))
		print(h - l)


import sys
[t] = [int(i) for i in sys.stdin.readline().split()]
for i in range(t):
	(n, m, k) = [int(i) for i in sys.stdin.readline().split()]
	cardsperplayer = n // k
	winningjokers = min(m, cardsperplayer)
	otherjokers = m - winningjokers
	if otherjokers % (k - 1) == 0:
		otherjokersperplayer = otherjokers // (k - 1)
	else:
		otherjokersperplayer = otherjokers // (k - 1) + 1
	print(winningjokers - otherjokersperplayer)


for i in range(int(input())):
	(n, m, k) = map(int, input().split())
	card = n // k
	if card == 1 and m != 1:
		print('0')
	elif card >= m:
		print(m)
	else:
		count = 0
		va = m - card
		while va != 0:
			if va >= k - 1:
				va -= k - 1
				count += 1
			else:
				count += 1
				va = 0
		print(card - count)


from sys import stdin
t = int(input())
for _ in range(0, t):
	(n, m, k) = [int(c) for c in stdin.readline().split()]
	card_each = n // k
	extra_joker = m - card_each
	max_joker = extra_joker // (k - 1) + (extra_joker % (k - 1) != 0)
	if card_each >= m:
		print(m)
	elif card_each == max_joker:
		print(0)
	else:
		print(card_each - max_joker)


from math import ceil
t = int(input())
while t:
	t -= 1
	data = list(map(int, input().split()))
	ec = int(data[0] / data[2])
	if ec >= data[1]:
		print(data[1])
	else:
		print(ec - ceil((data[1] - ec) / (data[2] - 1)))


import math
t = int(input())
for _ in range(t):
	(cartas, jokers, players) = list(map(int, input().split()))
	maxCartas = cartas / players
	if jokers <= maxCartas:
		print(jokers)
	else:
		jokersAt = jokers - maxCartas
		print(int(maxCartas - jokersAt / (players - 1)))


from sys import stdout, stdin
(_input, _print) = (stdin.buffer.readline, stdout.write)
(_int, _range) = (int, range)

def solution():
	for _ in _range(_int(_input())):
		(n, m, k) = [_int(i) for i in _input().split()]
		card = n // k
		if m <= card:
			print(m)
		elif card < m:
			l = (m - card) // (k - 1) if (m - card) % (k - 1) == 0 else (m - card) // (k - 1) + 1
			print(card - l)
solution()


counter = int(input())
for i in range(counter):
	(cards, jokers, players) = map(int, input().split())
	cards_per_player = int(cards / players)
	max_jokers_of_winner = min(cards_per_player, jokers)
	jokers_left = jokers - max_jokers_of_winner
	jokers_of_loser = jokers_left // (players - 1)
	if jokers_left % (players - 1) != 0:
		jokers_of_loser += 1
	points_of_winner = max_jokers_of_winner - jokers_of_loser
	print(points_of_winner)


from sys import stdin, stdout
import math, sys
from itertools import permutations, combinations
from collections import defaultdict, deque, OrderedDict
from os import path
import bisect as bi
import heapq

def yes():
	print('YES')

def no():
	print('NO')
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

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

	def In():
		return map(int, input().split())
else:

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

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

def main():
	try:
		(n, m, k) = In()
		t1 = n // k
		if m <= t1:
			print(m)
		elif n == m:
			print(0)
		else:
			t = math.ceil((m - t1) / (k - 1))
			print(t1 - t)
	except:
		pass
M = 998244353
P = 1000000007
for _ in range(I()):
	main()


import math
t = int(input())
for _ in range(t):
	(n, m, k) = list(map(int, input().split(' ')))
	highest = int(min(m, n / k))
	nextHighest = int(math.ceil((m - highest) / (k - 1)))
	print(int(highest - nextHighest))


import math
for t in range(int(input())):
	(n, m, k) = list(map(int, input().split()))
	x = min(m, math.floor(n / k))
	y = (m - x + k - 2) // (k - 1)
	print(x - y)


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	t = a // c
	if t >= b:
		print(b)
	else:
		r = b - t
		if r % (c - 1) == 0:
			p = r // (c - 1)
		else:
			p = r // (c - 1) + 1
		print(t - p)


import io
import os
t = int(input())
while t:
	t -= 1
	(n, m, k) = [int(x) for x in input().split()]
	if n / k >= m:
		print(m)
	else:
		h = m - n // k
		if h % (k - 1) == 0:
			print(n // k - h // (k - 1))
		else:
			print(n // k - (h // (k - 1) + 1))


for i in range(int(input())):
	(n, m, k) = map(int, input().split())
	c = n // k
	if c >= m:
		print(m)
	if c < m:
		x = c
		m -= c
		k -= 1
		if m <= k:
			print(x - 1)
		else:
			z = m // k
			r = m % k
			if r != 0:
				print(x - z - 1)
			else:
				print(x - z)


for _ in range(int(input())):
	(n, m, k) = [int(x) for x in input().split()]
	if m <= n / k:
		print(m)
	else:
		diff = m - n // k
		if diff % (k - 1) != 0:
			print(n // k - (diff // (k - 1) + 1))
		else:
			print(n // k - diff // (k - 1))


def ceil(a, b):
	if a % b == 0:
		return a // b
	else:
		return a // b + 1
t = int(input())
for i in range(t):
	(n, m, k) = map(int, input().split())
	maxx = min(m, n // k)
	minn = ceil(m - maxx, k - 1)
	print(maxx - minn)


def solve():
	(n, m, k) = map(int, input().split())
	if m == 0:
		return 0
	if n // k == 1:
		if m > 1:
			return 0
		else:
			return 1
	ans = 0
	for i in range(n // k, 0, -1):
		if i > m:
			continue
		if i > (m - i + (k - 2)) // (k - 1):
			if i - (m - i + (k - 2)) // (k - 1) > ans:
				ans = i - (m - i + (k - 2)) // (k - 1)
	return ans

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


import sys
file_name = ''
if file_name:
	f = open(file_name, 'r')
else:
	f = sys.stdin
line = f.readline()
t = int(line)
for _ in range(t):
	(n, m, k) = [int(x) for x in f.readline().split()]
	if m > n - k + 1:
		print(0)
	else:
		cards = int(n / k)
		x = min(m, cards)
		m -= x
		if m % (k - 1) == 0:
			delta = 0
		else:
			delta = 1
		print(x - (int(m / (k - 1)) + delta))


t = int(input())
while t > 0:
	t -= 1
	(n, m, k) = map(int, input().split())
	card = n // k
	if card >= m:
		print(m)
	else:
		rem = k - 1
		temp = m - card
		maxm = temp // rem
		if temp % rem:
			maxm += 1
		print(card - maxm)


from sys import stdin, stdout
import collections
import heapq
import itertools
import functools
import math
import operator
import string
ALPHABET = string.ascii_lowercase
DIGITS = string.digits

def read_line():
	return stdin.readline().strip()

def read_int():
	return int(read_line())

def read_arr():
	return read_line().split(' ')

def read_int_arr():
	return [int(x) for x in read_arr()]

def query_interactive(s):
	print(s)
	stdout.flush()

def solve():
	(n, m, k) = read_int_arr()
	cards_per = n // k
	if m <= cards_per:
		print(m)
		return
	take = cards_per
	holes = [0] * (k - 1)
	for i in range(m - take):
		holes[i % (k - 1)] += 1
	max_rest = max(holes)
	if max_rest == take:
		print(0)
		return
	print(take - max_rest)

def main():
	T = 1
	T = read_int()
	for _ in range(T):
		solve()
main()


t = int(input())
for q in range(t):
	(n, m, k) = map(int, input().split())
	if m > n // k:
		x = m - n // k
		Max = n // k
		Max_2 = x // (k - 1) + int(x % (k - 1) > 0)
		print(Max - Max_2)
	else:
		print(m)


for _ in range(int(input())):
	(card, joker, player) = map(int, input().split())
	hand = card // player
	if hand >= joker:
		print(joker)
	elif (joker - hand) % (player - 1) == 0:
		print(hand - (joker - hand) // (player - 1))
	else:
		print(hand - (joker - hand) // (player - 1) - 1)


from sys import stdin, stdout
for _ in range(int(stdin.readline())):
	(n, m, k) = map(int, stdin.readline().split())
	each = n // k
	if m <= each:
		stdout.write(str(m) + '\n')
	else:
		k -= 1
		rem = m - each
		if rem % k == 0:
			ans = each - rem // k
		else:
			ans = each - (rem // k + 1)
		stdout.write(str(ans) + '\n')


import sys
import heapq

def main():
	t = int(input())
	for _ in range(t):
		(n, m, k) = map(int, sys.stdin.readline().split())
		if n // k >= m:
			print(m)
		else:
			maxVal = max(0, n // k)
			remain = max(m - n // k, 0)
			div = remain // (k - 1)
			if remain % (k - 1):
				div += 1
			print(maxVal - div)
	return
main()


from sys import stdin, stdout

def input():
	return stdin.readline()
t = int(input())
for _ in range(t):
	(n, m, k) = map(int, input().split())
	z = n // k
	if z >= m:
		print(m)
	else:
		w1 = abs(z - m)
		w = w1 % (k - 1)
		y = w1 // (k - 1)
		if w == 0:
			print(z - y)
		else:
			print(z - y - 1)


import sys
import math
t = int(sys.stdin.readline().strip())
for i in range(t):
	(n, m, k) = list(map(int, sys.stdin.readline().strip().split(' ')))
	c = n // k
	if c >= m:
		print(m)
	else:
		m = m - c
		j = m // (k - 1)
		if m % (k - 1) == 0:
			print(c - j)
		else:
			print(c - (j + 1))


for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	each = n // k
	first = min(m, each)
	rem = m - first
	if rem <= 0:
		print(first)
	else:
		res = first - rem // (k - 1)
		if rem % (k - 1) != 0:
			res -= 1
		print(res)


def updiv(a, b):
	if a % b == 0:
		return a // b
	else:
		return a // b + 1
t = int(input())
for loop in range(t):
	(n, m, k) = map(int, input().split())
	if n // k >= m:
		print(m)
	else:
		rem = updiv(m - n // k, k - 1)
		print(n // k - rem)


import math
t = int(input())
ltot = []
for k in range(t):
	ltot.append(list(map(int, input().split())))
for i in range(len(ltot)):
	l = ltot[i]
	n = l[0]
	m = l[1]
	k = l[2]
	cards = n // k
	lans = []
	count = 0
	lout1 = []
	for j in range(k):
		if j == 0:
			if m >= cards:
				lans.append(cards)
				count += cards
				tm = m - cards
			if m < cards:
				lout1.append(m)
				break
			if tm <= 0:
				lout1.append(cards)
				break
			ocards = tm // (k - 1)
			if ocards >= cards:
				lout1.append(0)
				break
			if ocards == 0:
				ocards = 1
		elif j != k - 1 and j != 0:
			lans.append(ocards)
			count += ocards
		else:
			lans.append(m - count)
			ma = lans[0]
			lt = lans[1:]
			ma2 = max(lt)
			if ma - ma2 >= 0:
				lout1.append(ma - ma2)
			else:
				lout1.append(0)
	lout2 = []
	lans2 = []
	count2 = 0
	for f in range(k):
		if f == 0:
			if m >= cards:
				lans2.append(cards)
				count2 += cards
				tm2 = m - cards
			if m < cards:
				lout2.append(m)
				break
			if tm2 <= 0:
				lout2.append(cards)
				break
			ocards2 = math.ceil(tm2 / (k - 1))
			if ocards2 >= cards:
				lout2.append(0)
				break
			if ocards2 == 0:
				ocards2 = 1
		elif f != k - 1 and f != 0:
			lans2.append(ocards2)
			count2 += ocards2
		else:
			lans2.append(m - count2)
			ma2 = lans2[0]
			lt2 = lans2[1:]
			ma3 = max(lt2)
			if ma2 - ma3 >= 0:
				lout2.append(ma2 - ma3)
			else:
				lout2.append(0)
	print(max(lout2[0], lout1[0]))


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


a = int(input())
for i in range(0, a):
	(b, c, d) = map(int, input().split())
	if b // d >= c:
		print(c)
	else:
		f = c - b // d
		if f % (d - 1) == 0:
			a = f // (d - 1)
		else:
			a = f // (d - 1) + 1
		print(b // d - a)


t = int(input())
for _ in range(t):
	(n, m, k) = map(int, input().split())
	M = min(n // k, m)
	m -= M
	n -= M
	k -= 1
	each = m // k
	p = m % k
	top = each + (1 if p else 0)
	print(M - top)


from math import ceil
T = int(input())
for t in range(T):
	(n, m, k) = [int(x) for x in input().split()]
	if int(round(n / k)) >= m:
		print(m)
	else:
		N = int(n / k)
		e = m - N
		ep = ceil(e / (k - 1))
		print(round(max(0, N - ep)))


for i in range(int(input())):
	(a, b, c) = map(int, input().split())
	if b == 0:
		print(0)
	elif b <= a // c:
		print(b)
	else:
		d = a // c
		p = b - d
		z = p // (c - 1)
		q = p % (c - 1)
		if q > 0:
			z += 1
		print(d - z)


from __future__ import division, print_function
import sys
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
import os, sys, bisect, copy
from collections import defaultdict, Counter, deque
if os.path.exists('in.txt'):
	sys.stdin = open('in.txt', 'r')
if os.path.exists('out.txt'):
	sys.stdout = open('out.txt', 'w')

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

def mapi(arg=0):
	return map(int if arg == 0 else str, input().split())
for _ in range(int(input())):
	(n, m, k) = mapi()
	print(min(n // k, m) - (m - min(n // k, m) + k - 2) // (k - 1))


t = int(input())
for _ in range(t):
	(n, m, k) = map(int, input().split())
	max_m = min(m, n // k)
	nokori_m = m - max_m
	nokori_m = -(-nokori_m // (k - 1))
	print(max_m - nokori_m)


MOD = 10 ** 9 + 7
INT_MAX = 10 ** 20 + 7

def INPUT():
	return list((int(i) for i in input().split()))

def LIST_1D_ARRAY(n):
	return [0 for _ in range(n)]

def LIST_2D_ARRAY(m, n):
	return [[0 for _ in range(n)] for _ in range(m)]

def power(a, x):
	res = 1
	while x > 0:
		if x & 1:
			res = res * a % MOD
		a = a * a % MOD
		x //= 2
	return res % MOD

def NCR_MOD(n, r):
	num = 1
	for i in range(n, n - r, -1):
		num = num * i % MOD
	for j in range(1, r + 1):
		num = num * power(j, MOD - 2) % MOD
	return num
import math

def F(h, c, t, y):
	return abs((c + h - 2 * t) * y + (h - t)) / (2 * y + 1)

def calc(n, m, k):
	if m == 0:
		return 0
	if n // k >= m:
		return m
	return int(n // k - int(math.ceil((m - n // k) / (k - 1))))
for i in range(int(input())):
	(h, c, t) = INPUT()
	print(calc(h, c, t))


import math

def dict_sort(ans):
	ans = sorted(ans.items(), reverse=True, key=lambda kv: kv[1])

def is_prime(n, k):
	if n == 1:
		return 0
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0:
			res = i
			break
	return res

def inp():
	ls = list(map(int, input().split()))
	return ls
t = int(input())
for ii in range(t):
	(n, m, k) = map(int, input().split())
	if n // k < m:
		print(n // k - math.ceil((m - n // k) / (k - 1)))
	else:
		print(m)


t = int(input())
for i in range(t):
	(n, m, k) = map(int, input().split())
	a = int(n / k)
	if a >= m:
		print(m)
	elif m > a and m < n:
		r = m - a
		p = int(r / (k - 1))
		re = r % (k - 1)
		if re == 0:
			print(a - p)
		else:
			print(a - p - 1)
	elif m == n:
		print(0)


from math import ceil
from collections import deque
for tt in range(int(input())):
	(n, m, k) = map(int, input().split())
	res = deque()
	if m == 0:
		res.append(0)
	else:
		v = n // k
		if v >= m:
			v = m
			m = 0
		else:
			m -= v
		k2 = k - 1
		v2 = ceil(m / k2)
		res.append(v - v2)
	for i in res:
		print(i)


import math
t = int(input())
for _ in range(t):
	(n, m, k) = [int(i) for i in input().split()]
	q = int(n / k)
	if m == 0:
		print(0)
	elif q >= m:
		print(m)
	else:
		ans = q - math.ceil((m - q) / (k - 1))
		print(ans)


import math

def solve():
	(totcards, jocker, player) = list(map(int, input().split()))
	per_play_card = totcards // player
	if jocker <= per_play_card:
		return jocker
	max_candi = per_play_card
	rem_player = player - 1
	rem_cards = totcards - per_play_card
	rem_jocker = jocker - per_play_card
	minmax_candi = math.ceil(rem_jocker / rem_player)
	return max_candi - minmax_candi
for t in range(0, int(input())):
	print(solve())


from math import ceil, floor, sqrt
cases = int(input())
for _ in range(cases):
	(n, m, k) = map(int, input().split())
	each_player_card = n // k
	if each_player_card >= m:
		print(m)
	else:
		player_joker = each_player_card
		rem_joker = m - player_joker
		plain_card = n - m
		m = ceil(rem_joker / (k - 1))
		print(player_joker - m)


import math

def solve(n, m, k):
	if k == 0 or m == 0:
		return m
	each = n // k
	win_joker = min(m, each)
	other_joker = math.ceil((m - win_joker) / (k - 1))
	if other_joker == win_joker:
		return 0
	return win_joker - other_joker

def main():
	t = int(input())
	for i in range(t):
		d = input()
		d = [int(i) for i in d.split()]
		n = d[0]
		a = d[1]
		b = d[2]
		ans = solve(n, a, b)
		print(ans)
main()


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


from collections import defaultdict as dfd
import math
import sys
import heapq

def II():
	return int(sys.stdin.readline())

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

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

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def main():
	for _ in range(int(input())):
		(n, m, k) = MI()
		if m == 0:
			print(0)
		else:
			val = n // k
			if val >= m:
				print(m)
			else:
				m -= val
				var = val - math.ceil(m / (k - 1))
				print(var)
main()


def answer(n, m, k):
	if m <= n // k:
		return m
	elif (m - n // k) % (k - 1) == 0:
		return n // k - (m - n // k) // (k - 1)
	else:
		return n // k - (m - n // k) // (k - 1) - 1
t = int(input())
for i in range(t):
	(n, m, k) = map(int, input().split())
	print(answer(n, m, k))


T = int(input())
for t in range(0, T):
	(n, m, k) = map(int, input().split())
	c = int(n / k)
	if m == 0:
		print(0)
	elif c == 1 and m > 1:
		print(0)
	elif c >= m:
		print(m)
	else:
		r = (m - c) % (k - 1)
		if r == 0:
			print(c - int((m - c) / (k - 1)))
		else:
			print(c - int((m - c + k - 1 - r) / (k - 1)))


from math import ceil
t = int(input())
for _ in range(t):
	(n, m, k) = [int(x) for x in input().strip().split()]
	avg_num = ceil(n / k)
	max_num = m if avg_num >= m else avg_num
	left_jokers = m - max_num
	second_max_num = ceil(left_jokers / (k - 1))
	print(max_num - second_max_num)


def solve(n, m, k):
	x = min(m, n // k)
	y_temp = (m - x) // (k - 1)
	left = 1
	if (m - x) % (k - 1) == 0:
		left = 0
	y = y_temp + left
	print(x - y)
test = 1
test = int(input())
for t in range(0, test):
	(n, m, k) = [int(x) for x in input().split()]
	solve(n, m, k)


from sys import stdin
from math import ceil
input = stdin.readline

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

def sep_input():
	return map(int, input().split())
for _ in range(int(input())):
	(n, m, k) = sep_input()
	if m == 0:
		print(0)
	elif m <= n // k:
		print(m)
	else:
		k1 = n // k
		c = ceil((m - k1) / (k - 1))
		print(k1 - c)


import math
t = int(input())
for test in range(t):
	(n, m, k) = map(int, input().split())
	if m == 0:
		print(0)
	else:
		each = n // k
		mx = min(each, m)
		m -= mx
		rem = math.ceil(m / (k - 1))
		if mx == rem:
			print(0)
		else:
			print(mx - rem)


from math import ceil
cases = int(input())
for i in range(cases):
	input_list = input().split()
	input_list = [int(n) for n in input_list]
	deck_size = input_list[0]
	num_jokers = input_list[1]
	num_players = input_list[2]
	hand_size = deck_size / num_players
	jokers = min(hand_size, num_jokers)
	num_jokers -= jokers
	jokers_per = ceil(num_jokers / (num_players - 1))
	print(int(jokers - jokers_per))


import math

def solve():
	(n, m, k) = list(map(int, input().split()))
	temp = n // k
	if temp >= m:
		print(m)
	else:
		p = m - temp
		x = m - p
		print(x - math.ceil((m - x) / (k - 1)))

def main():
	T = int(input())
	while T:
		T -= 1
		solve()
main()


t = int(input())
while t != 0:
	t -= 1
	(n, m, k) = map(int, input().split())
	k1 = k - 1
	m1 = n // k
	if m1 >= m:
		res = m
	else:
		p = (m - m1) // k1
		if (m - m1) % k1 != 0:
			p += 1
		res = m1 - p
	print(res)


from math import ceil
t = int(input())
for i in range(t):
	(n, m, k) = map(int, input().split())
	if n // k >= m:
		ans = m
	elif m == 0:
		ans = 0
	elif n == k:
		ans = 0
	else:
		ans = round(n / k - ceil((m - n / k) / (k - 1)))
	print(ans)


t = int(input())
for _ in range(t):
	(n, m, k) = [int(i) for i in input().split()]
	each_player = n // k
	tot = m
	m = max(0, m - each_player)
	first_max = tot - m
	rem = k - 1
	second_max = m // rem
	if m % rem != 0:
		second_max += 1
	print(first_max - second_max)


t = int(input())
for x in range(t):
	temp = [int(i) for i in input().split()]
	(n, m, k) = temp
	arr = [0] * k
	card = m - n // k
	if n // k >= m:
		print(m)
	else:
		while card > 0:
			for i in range(k - 1):
				arr[i] += 1
				card -= 1
		print(n // k - max(arr))


import math
for i in range(int(input())):
	(n, m, k) = map(int, input().split())
	if m == 0:
		print(0)
		continue
	else:
		per_hand = n // k
		if per_hand >= m:
			print(m)
			continue
		else:
			win = per_hand
			rest = int(math.ceil((m - per_hand) / (k - 1)))
		print(win - rest)


(T,) = map(int, input().split())
for _ in range(T):
	(a, b, c) = map(int, input().split())
	if a // c > b:
		print(b)
	else:
		d = b - a // c
		x = a // c
		y = -(-(b - x) // (c - 1))
		print(x - y)


t = int(input())
for i in range(t):
	(n, m, a) = map(int, input().split())
	c = n // a
	ar1 = min(m, c)
	ar2 = (m - ar1 + a - 2) // (a - 1)
	print(ar1 - ar2)


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf, log, pi, sin
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
mod = pow(10, 9) + 7
mod2 = 998244353

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

def out(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

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 [l1d(n, val) for j in range(m)]
for _ in range(int(data())):
	(n, m, k) = sp()
	temp = n // k
	if m <= temp:
		out(m)
		continue
	m -= temp
	answer = temp - ceil(m / (k - 1))
	out(answer)


from sys import stdin, stdout, setrecursionlimit
from math import floor, gcd, fabs, factorial, fmod, sqrt, inf, log, log2
from random import seed, randint
from datetime import datetime
from collections import defaultdict as dd, deque
from heapq import merge, heapify, heappop, heappush, nsmallest
from bisect import bisect_left as bl, bisect_right as br, bisect
from collections import defaultdict as dd
mod = pow(10, 9) + 7
mod2 = 998244353

def inp():
	return stdin.readline().strip()

def iinp():
	return int(inp())

def out(var, end='\n'):
	stdout.write(str(var) + '\n')

def outa(*var, end='\n'):
	stdout.write(' '.join(map(str, var)) + end)

def lmp():
	return list(mp())

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

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

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

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

def remadd(x, y):
	return 1 if x % y else 0

def ceil(a, b):
	return (a + b - 1) // b

def def_value():
	return 0
for _ in range(iinp()):
	(n, m, k) = mp()
	t = n // k
	x = min(m, t)
	y = ceil(m - x, k - 1)
	print(int(x - y))


import math as p
for i in range(int(input())):
	(n, m, k) = map(int, input().split())
	ans = n // k
	if m == 0:
		print('0')
	elif ans >= m:
		print(m)
	elif ans == 1:
		if m == 1:
			print('1')
		else:
			print('0')
	elif m > ans:
		jok = m - ans
		x = p.ceil(jok / (k - 1))
		if x == ans:
			print('0')
		else:
			print(ans - x)


def maxdivide(players, jokers):
	if jokers % players == 0:
		return jokers // players
	return jokers // players + 1

def maxscore(n, m, k):
	if m == 0:
		return 0
	cards = n // k
	if cards >= m:
		return m
	left = m - cards
	maxother = maxdivide(k - 1, left)
	if maxother == cards:
		return 0
	return cards - maxother
t = int(input())
for i in range(t):
	(n, m, k) = map(int, input().split())
	print(maxscore(n, m, k))


for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	cards = n // k
	x = min(m, cards)
	y = __import__('math').ceil((m - x) / (k - 1))
	print(x - y)


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


import math
t = int(input())
for w in range(t):
	(n, m, k) = (int(i) for i in input().split())
	if m == 0:
		print(0)
	elif m <= n // k:
		print(m)
	else:
		m -= n // k
		print(n // k - math.ceil(m / (k - 1)))


def solve():
	(n, m, k) = map(int, input().split())
	player_card_cnt = n // k
	if player_card_cnt >= m:
		print(m)
	else:
		remaining_jokers = m - player_card_cnt
		remaining_players_max_jokers_cnt = remaining_jokers // (k - 1) + (1 if remaining_jokers % (k - 1) else 0)
		print(player_card_cnt - remaining_players_max_jokers_cnt)
for _ in range(int(input())):
	solve()


import math
t = int(input())
for i in range(t):
	a = list(map(int, input().split()))
	(n, m, k) = (a[0], a[1], a[2])
	p = min(n // k, m)
	r = m - p
	t = math.ceil(r / (k - 1))
	print(p - t)


a = int(input())
for _ in range(a):
	(n, m, k) = map(int, input().split())
	if n // k >= m:
		print(m)
	else:
		b = n // k
		for i in range(m - b + 1):
			if i * (k - 1) >= m - b:
				print(b - i)
				break


_ = int(input())
for __ in range(_):
	(n, m, k) = map(int, input().split())
	x = n // k
	if x >= m:
		print(m)
	elif m == 0 or m == n:
		print(0)
	else:
		m -= x
		players = [0] * (k - 1)
		i = 0
		while m > 0:
			players[i] += 1
			i += 1
			if i == k - 1:
				i = 0
			m -= 1
		y = players[0]
		print(x - y)


def main():
	(n, m, k) = map(int, input().split())
	in_hand = n // k
	if m <= in_hand:
		print(m)
	else:
		diff = (m - in_hand) // (k - 1)
		if (m - in_hand) % (k - 1) != 0:
			diff += 1
		print(in_hand - diff)
t = int(input())
for i in range(t):
	main()


from math import floor, ceil
from queue import LifoQueue

def print_sol(c, sol):
	print('Case #{}: {}'.format(c, sol))

def rd_int():
	return int(input())

def rd_str():
	return input()

def rd_str_lst():
	return input().split(' ')

def sp_str_lst():
	return list(input())

def rd_int_lst():
	return [int(i) for i in rd_str_lst()]

def sp_int_lst():
	return [int(i) for i in sp_str_lst()]

def dfs(g, i, v):
	v[i] = True
	for j in g[i]:
		if not v[j]:
			dfs(g, j, v)
	print(i)

def dfs_iter(g, i, n):
	v = [False] * n
	stack = LifoQueue()
	stack.put(i)
	while stack.not_empty:
		u = stack.get()
		v[u] = True
		print(u)
		for i in g[u]:
			if not v[i]:
				stack.put(i)

def main():
	t = rd_int()
	for c in range(1, t + 1):
		(n, m, k) = rd_int_lst()
		w = min(m, n // k)
		r = m - w
		l = ceil(r / (k - 1))
		print(w - l)
main()


t = int(input())
for i in range(t):
	(n, m, k) = [int(i) for i in input().split()]
	numCards = n / k
	if m > numCards:
		print(int(numCards - (m - numCards) / (k - 1)))
	else:
		print(int(m))


t = int(input())
for i in range(t):
	(n, m, k) = map(int, input().split())
	if m == 0:
		print(0)
	elif n // k >= m:
		print(m)
	else:
		max_gamer = n // k
		ost = m - max_gamer
		if ost % (k - 1) == 0:
			ans = ost // (k - 1)
		else:
			ans = ost // (k - 1) + 1
		print(max_gamer - ans)


import math

def solution(n, m, k):
	cards = n // k
	if cards >= m:
		return m
	else:
		jokers = m - cards
		spread = math.ceil(jokers / (k - 1))
		return cards - spread
t = int(input())
for _ in range(t):
	(n, m, k) = map(int, input().split(' '))
	print(solution(n, m, k))


import sys
import math
input = sys.stdin.readline
t = int(input())
for test in range(t):
	(n, m, k) = list(map(int, input().split()))
	per = n / k
	if m <= per:
		print(m)
	else:
		ans = per - math.ceil((m - per) / (k - 1))
		print(int(ans))


for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	if m == 0 or (n == k and m > 1):
		print(0)
	else:
		c = n // k
		if c >= m:
			print(m)
		else:
			r = m - c
			if r % (k - 1) == 0:
				i = r // (k - 1)
				print(c - i)
			else:
				i = int(r / (k - 1)) + 1
				print(c - i)


for i in range(int(input())):
	a = list(map(int, input().split()))
	n = a[0]
	m = a[1]
	k = a[2]
	aux = int(n / k)
	if m <= aux:
		print(m)
	else:
		supp = (m - aux) / (k - 1)
		if supp > int(supp):
			supp = int(supp) + 1
		else:
			supp = int(supp)
		print(aux - supp)


def poker(n, m, k):
	if k == 0:
		return 0
	if k == 1:
		return 1
	number = n / k
	if number >= m:
		return m
	jokers = m - number
	if jokers % (k - 1) == 0:
		per = jokers / (k - 1)
		return number - per
	return number - jokers // (k - 1) - 1
n = int(input())
answer = []
for i in range(n):
	w = list(map(int, input().rstrip().split()))
	n = w[0]
	m = w[1]
	k = w[2]
	ans = poker(n, m, k)
	answer.append(ans)
for ans in answer:
	print(int(ans))


from collections import defaultdict
from collections import OrderedDict
from collections import deque
from itertools import combinations
from itertools import permutations
import bisect
import math
import heapq
import sys
import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
for ii in range(int(input())):
	(n, m, k) = map(int, input().split())
	each = n // k
	maxj = min(m, n // k)
	rem = m - maxj
	if rem == 0:
		print(maxj)
	else:
		rest = math.ceil(rem / (k - 1))
		print(maxj - rest)


t = int(input())
for _ in range(t):
	(n, m, k) = map(int, input().split())
	if n // k > m:
		print(m)
		continue
	mx = n // k
	m -= mx
	(p, q) = divmod(m, k - 1)
	if q:
		print(mx - (p + 1))
	else:
		print(mx - p)


import math
t = int(input())
for _ in range(t):
	(n, m, k) = tuple(map(int, input().split()))
	cards_w_each = n / k
	if m == 0:
		print(0)
	elif m / cards_w_each == 0:
		print(0)
	elif cards_w_each > m:
		print(m)
	else:
		jokers_given = [None] * k
		jokers_given[0] = cards_w_each
		m -= cards_w_each
		k -= 1
		for i in range(1, len(jokers_given)):
			jokers_given[i] = math.floor(m / k)
			m -= math.floor(m / k)
			k -= 1
		x = max(jokers_given)
		jokers_given.remove(max(jokers_given))
		y = max(jokers_given)
		print(int(x - y))


import math
for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	cardseach = n // k
	if cardseach >= m:
		print(m)
	elif cardseach == 1:
		print(0)
	else:
		result = cardseach
		f = (m - result) / (k - 1)
		result -= math.ceil(f)
		print(result)


for _ in range(int(input())):
	(n, j, p) = map(int, input().split())
	c = n // p
	if j <= c:
		print(j)
	else:
		q = (j - c) // (p - 1)
		r = (j - c) % (p - 1)
		if r == 0:
			print(c - q)
		else:
			print(c - q - 1)


for _ in range(int(input())):
	(n, m, k) = list(map(int, input().split()))
	if m <= n // k:
		print(m)
	else:
		ans = n // k
		m -= n // k
		while 1:
			if m < k - 1:
				break
			else:
				m -= k - 1
				ans -= 1
		if m != 0:
			ans -= 1
		print(ans)


import math
t = int(input())
while t:
	t -= 1
	(n, m, k) = map(int, input().split())
	maxx = min(m, n // k)
	print(maxx - (m - maxx + k - 2) // (k - 1))


t = int(input())
import math
for _ in range(t):
	(n, m, k) = (int(x) for x in input().split())
	x = n // k
	res = 0
	if n // k >= m:
		res = m
	else:
		arr = [0] * (k - 1)
		winner = n / k
		m = m - winner
		for i in range(int(m)):
			arr[i % (k - 1)] += 1
		res = int(winner - max(arr))
	print(res)


import math
n = int(input())
for i in range(n):
	(a, b, c) = input().split()
	a = int(a)
	b = int(b)
	c = int(c)
	h = a // c
	if h > b:
		print(b)
	elif h == b:
		print(b)
	elif h == 0:
		print(0)
	else:
		t = b - h
		if h > 1:
			l = math.ceil(t / (c - 1))
		else:
			l = t
		if h - l >= 0:
			print(h - l)
		else:
			print(0)


import math
t = int(input())
while t != 0:
	(n, m, k) = map(int, input().split())
	per_p = n // k
	if per_p >= m:
		print(m)
	else:
		maxi_m = per_p
		min_m = math.ceil((m - per_p) / (k - 1))
		print(maxi_m - min_m)
	t -= 1


from math import *
import sys
input = sys.stdin.buffer.readline
a = int(input())
for x in range(a):
	(b, c, d) = map(int, input().split())
	if c == 0:
		print(0)
	elif c == b:
		print(0)
	else:
		k = b // d
		if c > k:
			t = c - k
			n = ceil(t / (d - 1))
			print(k - n)
		else:
			print(c)


import sys
input = lambda : sys.stdin.readline().rstrip()
from math import ceil
for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	joker_max = min(m, n // k)
	m -= joker_max
	guys = k - 1
	if guys:
		joker_max_two = ceil(m / guys)
	else:
		joker_max_two = 0
	print(joker_max - joker_max_two)


t = int(input())
for _ in range(t):
	(n, m, k) = map(int, input().split())
	if n // k >= m:
		print(m)
	else:
		y = m - n // k
		y1 = k - 1
		i = y // y1
		if y % y1 > 0:
			print(n // k - (i + 1))
		else:
			print(n // k - i)


t = int(input())
while t:
	t -= 1
	(n, m, k) = map(int, input().split())
	if m == 0:
		print(0)
	else:
		res = n // k
		if m <= res:
			print(m)
		else:
			m = m - res
			k -= 1
			if m % k == 0:
				temp = m // k
				print(res - temp)
			else:
				temp = m // k
				print(res - temp - 1)


t = int(input())
l = []
for i in range(t):
	(n, m, k) = map(int, input().split())
	if n / k <= m:
		max = n / k
		sl = (m - max + k - 2) // (k - 1)
		l.append(int(max - sl))
	else:
		l.append(int(m))
for i in l:
	print(i)


for tt in range(int(input())):
	(n, joker, k) = map(int, input().split())
	l = [0] * k
	temp = n // k
	while joker:
		if l[0] >= temp:
			break
		l[0] += 1
		joker = joker - 1
	i = 1
	while joker:
		if i >= k:
			i = 1
		l[i] += 1
		joker -= 1
		i += 1
	m = max(l)
	if l.count(m) >= 2:
		print(0)
	else:
		l.sort(reverse=True)
		print(l[0] - l[1])