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 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 ≤ t ≤ 500) — the number of test cases.

Then the test cases follow. Each test case contains three integers n, m and k (2 ≤ n ≤ 50, 0 ≤ m ≤ n, 2 ≤ k ≤ 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.
'''
n=int(input())
x=n-1
s=n*2*x+2
j=0
for i in range(2*n+1):
   if(i%x!=0):
       print("*  "*j+" "*s+"  *"*j)
       
       
       
   else:
       print("*  "*j+"*"*s+"  *"*j)
       j=j+1
       s=abs(s-2*x)
'''
'''
def fib(n):
   a=0
   b=1
   c=0
   for x in range(n-1):
      c=a+b
      a=b
      b=c
   print(c)

fib(71)   #only valid upto 71st fiboncci
n=71
a=((((1+5**0.5)/2)**n)-(((1-5**0.5)/2)**n))/(5**0.5)            
print(int(a))   
'''
'''
t=int(input())
for _ in range(t):
   n=int(input())
   li=list(map(int, input().split()))
   li.sort
   if(1 in li):
      

   else:
      print((2**n)%998,244,353)
   
'''
'''
t=int(input())
for _ in range(t):
    n,s=map(int,input().split())
    li=list(map(int,input().split()))
    i=0
    li1=[]
    for x in range(n):
        li1.append(li[x])
    li1.sort(reverse=True)


    while(s>0 and li1!=li):
        if(li[i]<li[i+1]):
            li[i],li[i+1]=li[i+1],li[i]
            s=s-1
        if(i+1==n-1):
            i=0
        i=i+1
    st=''
    for j in li:
        st=st+str(j)
    print(st)
'''
'''
t=int(input())
for _ in range(t):
    n=int(input())
    li=list(map(int, input().split()))
    p=max(li)
    li1=[0 for i in range(p+1)]
    take=1
    last=-1
    for x in li:
        if(last==x):
            take=not take
        else:
            take=1
        if(take):
            li1[x]+=1
            last=x
    print(li1)
    print(li1.index(max(li1)))
        
   '''         
'''
t=int(input())
for _ in range(t):
    n,k=map(int,input().split())
    if(n==0):
        print((k*(k+1))%1000000007)
    elif(k%2==0):
        k=k/2
        k=k-1
        q=n+k
        a=q*(q+1)
        a=a+n
    else:
        k=k//2
        q=n+k
        a=q*(q+1)
        a=a-n
    a=int(a)
    print(a%1000000007)
'''
'''
t=int(input())
for _ in range(t):
    n1=int(input())
    l1=list(map(int,input().split()))
    n2=int(input())
    l2=list(map(int,input().split()))
    c=0
    a=[]
    b=[]
    for x in range(n1):
        if(l1[x] in l2):
            a.append(l1[x])
            l2[l2.index(l1[x])]=0
        else:
            if(len(a)!=0):
                b.append(a)
                a=[]
    print(len(b))
'''
'''
t=int(input())
while(t>0):
    li=[]
    n=int(input())
    i=0
    while(i<n):
        a=[]
        a=list(map(int,input().split()))
        li.append(a)
        i+=1
    f=0
    x=0
    y=0
    while(x<n):
        while(y<n):
            if(li[x][y]==1):
                if(x==0):
                    if(li[x+1][y]==1 or li[x+1][y]==1 ):
                    f=1
                    x=101
                    y=101
            y+=1
        x+=1
    if(f==0):
        print("SAFE")
    t-=1
    '''
'''
n=int(input())
li=list(map(int,input().split()))
a=[]
for x in range(n):
    if(li[x] in a):
        continue
    print(li.count(li[x])+li[x],end=' ')
    a.append(li[x])
'''
'''
def tree(n,ind,h,tr):
    if(h==0):
        return
    b=n-1
    a=n-2**h
    tr[2*ind]=a
    tr[2*ind+1]=b
    tree(a,2*ind,h-1,tr)
    tree(b,2*ind+1,h-1,tr)
    
def solution(h,q):
    tr=[0 for i in range(2**h)]
    tr[1]=2**h-1
    tree(2**h-1,1,h-1,tr)
    p=[]
    for x in q:
        c=tr.index(x)//2
        if(c==0):
            p.append(-1)
        else:
            p.append(tr[c])
    return p
print(solution(5, [19, 14, 28]))

def n2b(n, b):        
    if n == 0:
        return 0
    st=''
    while n:
        st=st+str(n%b)
        n //= b
    return st
'''
'''
def printMin(num,b): 
    count = [0 for x in range(b)] 
    string = str(num) 
    for i in range(len(string)): 
        count[int(string[i])] = count[int(string[i])] +  1
        
    result =''
  
    for i in range(b): 
        while count[i] > 0: 
            result = result + str(i)
            count[i] = count[i] - 1
  
    return result 


def sub(x,y,b):
    st=''
    l=len(y)
    a=b-1
    a=str(a)
    n=int(a*l)
    x=int(x)
    y=int(y)
    y=n-y
    c=1
    ans=0
    while(x and y):
       p=x%10
       q=y%10
       r=p+q+c
       st=st+str(r%b)
       c=r//b
       x//=10
       y//=10
    return st[::-1]

    
def solution(n, b):
    p=[]
    while(int(n)):
        l=len(n)
        x=str(printMin(n,b))
        y=x[::-1]
        n=sub(y,x,b)
        if(l!=len(n)):
            n='0'*(l-len(n))+n
        if(n in p):
            q=p.index(n)
            return len(p)-q
        p.append(n)
    return 1


def issorted(li,n):
    for x in range(n):
        if(x+1==li[x]):
            continue
        else:
            return False
    return True
'''
'''

for _ in range(int(input())):
    n,k=map(int,input().split())
    li=list(map(int,input().split()))
    a=[]
    ind=[]
    for x in range(n):
        if(li[x]!=x+1):
            a.append(li[x])
            ind.append(x)
    f=0
    ans=[]
    while(k):
        ti=[]
        i=[]
        for x in range(len(a)):
            if(a[x]!=ind[x]+1):
                ti.append(ind[x])
                i.append(x)
                if(len(i)==3):
                    ans.append(ti)
                    break
        if(len(i)< 3 and len(i) >0):
            print(-1)
            break
        if(len(i)==0):
            f=1
            break
        a[i[0]],a[i[1]],a[i[2]]=a[i[2]],a[i[0]],a[i[1]]
        k-=1
        print(ti)
    if(f==1):
        print(len(ans))
        for x in range(len(ans)):
            print(ans[x][0]+1,ans[x][1]+1,ans[x][2]+1)
    else:
        print(-1)
        
'''
'''
for _ in range(int(input())):
    x,y,l,r=map(int,input().split())
    if(x==0 or y==0):
        print(l)
    else:
        if(l==r):
            print(r)
        else:
            a=x|y
            a_bin=bin(a)
            r_bin=bin(r)
            a_bin=a_bin[2:]
            r_bin=r_bin[2:]
            ans=a_bin
            while(int(ans)>int(r_bin)):
                ans=ans[1:]
            print(int(ans,2))
       '''
'''

def is_safe(m,i,j,a,v):
    if(v[i][j]==False ):
        if(m[i][j]==0):
            return True
        
        elif(m[i][j]==1 and a[0]==0):
            a[0]+=1
            return True
        elif(m[i][j]==1 and a[0]==1):
            a[0]+=1
            return False
        else:
            return False
    else:
        return False
    
    
def solution(m):
    h=len(m)
    w=len(m[0])
    v=[]
    for x in range(h):
        a=[]
        for y in range(w):
            a.append(False)
        v.append(a)
    li=[]
    c=0
    p=1
    i=0
    j=0
    path_finder(m,i,j,h,w,li,p,c,v)
    return li[0]

def path_finder(m,i,j,h,w,li,p,c,v):
    if(len(li)==1 and p>=li[0]):
        return
    if(c==2):
       return
    if(i==h-1 and j==w-1):
        li.append(p)
        return
    a1=[c]
    a2=[c]
    a3=[c]
    a4=[c]
    
    v[i][j]=True
    if(i+1<h and is_safe(m,i+1,j,a1,v)):
        path_finder(m,i+1,j,h,w,li,p+1,a1[0],v)
        
    if(i-1>=0 and is_safe(m,i-1,j,a2,v)):
        path_finder(m,i-1,j,h,w,li,p+1,a2[0],v)

    if(j+1<w and is_safe(m,i,j+1,a3,v)):
        path_finder(m,i,j+1,h,w,li,p+1,a3[0],v)

    if(j-1>=0 and is_safe(m,i,j-1,a4,v)):
        path_finder(m,i,j-1,h,w,li,p+1,a4[0],v)
        
    v[i][j]=False

print(solution([[0, 1, 0, 1, 0, 0, 0], [0, 0, 0, 1, 0, 1, 0]]))




print(solution([[0,1,0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0],
                [0,0,0,1,0,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0],
                [1,1,1,1,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0],
                [1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,0,0,0,0],
                [1,1,1,1,1,1,1,0,0,1,1,1,1,1,1,1,0,0,0,0],
                [1,1,1,1,1,1,1,0,1,0,1,0,1,0,1,0,0,0,0,0],
                [0,0,0,1,0,0,0,0,1,0,0,1,0,0,0,0,0,0,0,0],
                [1,0,0,0,0,1,0,1,1,0,1,1,1,1,1,1,0,0,0,0],
                [0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,1,0,0,0,0],
                [1,0,0,0,0,0,1,1,1,0,1,0,1,0,1,1,0,0,0,0],
                [1,1,1,1,1,0,1,0,1,0,0,0,1,0,1,1,0,0,0,0],
                [1,1,1,1,1,0,1,1,1,0,0,0,1,0,1,0,0,0,0,0],
                [1,1,0,1,0,0,1,1,1,1,1,0,1,0,1,0,0,0,0,0],
                [0,1,0,1,1,1,0,0,0,0,1,0,0,1,1,1,0,0,0,0],
                [0,1,0,0,0,1,0,0,0,0,1,1,0,1,1,1,0,0,0,0],
                [1,1,1,1,0,1,1,1,1,1,1,0,0,1,1,1,0,0,0,0],
                [1,1,1,1,0,1,0,1,0,1,0,0,1,1,1,1,0,0,0,0],
                [0,0,0,1,0,1,0,1,0,1,1,0,0,1,1,1,0,0,0,0],
                [1,1,1,1,0,1,0,1,0,0,0,0,0,1,1,1,0,0,0,0],
                [1,1,1,1,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0]]))


print(solution([[0,1,1,1,0],
                [0,0,0,0,1],
                [1,1,1,0,0],
                [1,1,0,0,1],
                [1,1,0,1,1],
                [1,1,1,0,0],
                [1,1,1,0,0],
                [1,1,1,0,0]]))  
    
       '''
'''

def is_safe(i,j,h,w,m):
    if(i>=h or i<0 or j<0 or j>=w or m[i][j]):
        return False
    return True

def solution(m):
    h,w=len(m),len(m[0])
    q=[]
    q[0]=(0,0)
    val=[0]
    bfs=[]
    while(q):
        a=q.pop(0)
        bfs.append(a)
        i=a[0]
        j=a[1]
        if(is_safe(i+1,j,h,w,m)):
            if((i+1,j) not in q and (i+1,j) not in bfs):
                q[(i+1,j)]=q[(i,j)]+1

        if(is_safe(i-1,j,h,w,m)):
            if((i-1,j) not in q):
                q[(i-1,j)]=q[(i,j)]+1

        if(is_safe(i,j+1,h,w,m)):
            if((i,j+1) not in q):
                q[(i,j+1)]=q[(i,j)]+1

        if(is_safe(i,j-1,h,w,m)):
            if((i,j-1) not in q):
                q[(i,j-1)]=q[(i,j)]+1

    return q[(h-1,w-1)]

print(solution([[0,1,1,1,0],
                [0,0,0,0,1],
                [1,1,1,0,0],
                [1,1,0,0,1],
                [1,1,0,0,1],
                [1,1,1,0,0],
                [1,1,1,0,0],
                [1,1,1,0,0]])) 

'''
'''
def sht_pth(sx, sy, maze):
    w = len(maze[0])
    h = len(maze)
    board = [[None for i in range(w)] for i in range(h)]
    board[sx][sy] = 1

    arr = [(sx, sy)]
    while arr:
        x, y = arr.pop(0)
        for i in [[1,0],[-1,0],[0,-1],[0,1]]:
          nx, ny = x + i[0], y + i[1]
          if 0 <= nx < h and 0 <= ny < w:
            if board[nx][ny] is None:
                board[nx][ny] = board[x][y] + 1
                if maze[nx][ny] == 1 :
                  continue
                arr.append((nx, ny)) 
                  
    return board

def solution(m):
  w = len(m[0])
  h = len(m)
  tb = sht_pth(0, 0, m)
  bt = sht_pth(h-1, w-1, m)
  board = []

  ans = 2 ** 32-1
  for i in range(h):
      for j in range(w):
          if tb[i][j] and bt[i][j]:
              ans = min(tb[i][j] + bt[i][j] - 1, ans)
  return ans





print(solution([[0,1,0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0],
                [0,0,0,1,0,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0],
                [1,1,1,1,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0],
                [1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,0,0,0,0],
                [1,1,1,1,1,1,1,0,0,1,1,1,1,1,1,1,0,0,0,0],
                [1,1,1,1,1,1,1,0,1,0,1,0,1,0,1,0,0,0,0,0],
                [0,0,0,1,0,0,0,0,1,0,0,1,0,0,0,0,0,0,0,0],
                [1,0,0,0,0,1,0,1,1,0,1,1,1,1,1,1,0,0,0,0],
                [0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,1,0,0,0,0],
                [1,0,0,0,0,0,1,1,1,0,1,0,1,0,1,1,0,0,0,0],
                [1,1,1,1,1,0,1,0,1,0,0,0,1,0,1,1,0,0,0,0],
                [1,1,1,1,1,0,1,1,1,0,0,0,1,0,1,0,0,0,0,0],
                [1,1,0,1,0,0,1,1,1,1,1,0,1,0,1,0,0,0,0,0],
                [0,1,0,1,1,1,0,0,0,0,1,0,0,1,1,1,0,0,0,0],
                [0,1,0,0,0,1,0,0,0,0,1,1,0,1,1,1,0,0,0,0],
                [1,1,1,1,0,1,1,1,1,1,1,0,0,1,1,1,0,0,0,0],
                [1,1,1,1,0,1,0,1,0,1,0,0,1,1,1,1,0,0,0,0],
                [0,0,0,1,0,1,0,1,0,1,1,0,0,1,1,1,0,0,0,0],
                [1,1,1,1,0,1,0,1,0,0,0,0,0,1,1,1,0,0,0,0],
                [1,1,1,1,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0]]))



for _ in range(int(input())):
    n=int(input())
    li=list(map(int,input().split()))
    c=0
    for x in range(n):
        s=0
        for y in range(x,n):
            s=s+li[y]
            sq=s**.5
            if(sq==int(sq)):
                c+=1
    
    print("Case #"+str(_+1)+":",c)            
            
    
'''
'''
def find_max(li):
    m=-1
    ind=-1
    for x in range(len(li)):
        if(li[x]>m):
            m=li[x]
            ind=x
    return m,ind
        
def solve(arr):
    m,ind=find_max(arr)
    a=sorted(arr[:ind])
    b=sorted(arr[ind+1:])
    
    

arr=[2,3,1,7,5,4,5]
solve(arr)


'''
'''

for _ in range(int(input())):
    n=int(input())
    li=list(map(int, input().split()))
    li.sort()
    f=0
    o=0
    e=0
    for x in range(n):
        if(li[x]%2==0):
            e+=1
        else:
            o+=1
    if(e%2==0 and o%2==0):
        f=1
        print("YES")
    else:
        for x in range(n-1):
            if(li[x+1]-li[x]==1):
                f=1
                print("YES")
    if(f==0):
        print("NO")



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


















    






            
        
        
        
    
    
