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.

Difficulty: interview

Starter code:

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


for _ in range(int(input())):
    n, m, k = map(int, input().split())
    # n = int(input())
    # arr = list(map(int, input().split()))
    x = min(m, n // k)
    m -= x
    y = (m + (k - 1) - 1) // (k - 1)
    print(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 = list(map(int, input().split()))
    print(solve(n, m, k))


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

t = int(input())

for _ in range(t):
    n, m, k = [int(x) for x in input().split()]
    np1 = min(m, n//k)
    m -= np1
    # the remainder divided over k - 1 players (rounded up)
    np2 = (m + k - 2)//(k-1)
    print(np1 - np2)


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


def read_ints():
    return list(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)


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)

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)

import sys

input = sys.stdin.readline
flush = sys.stdout.flush

for _ in range(int(input())):
    n, m, k = list(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 _ 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 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))
        


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 = list(map(int, input().split()))
    taken = min(m, n//k)
    remaining = m - taken
    print(taken - ceil(remaining, k-1))


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


# solve()

T = ni()
for _ in range(T):
    solve()


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


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)
    


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


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

from math import ceil

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

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

def main():
    inf = 10 ** 20

    t = int(input())
#    t, a, b = map(int, input().split())
#    t = 1
    
    for _ in range(1, t+1):
    #    print("Case #{}: ".format(_), end = '')
        
        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()

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)