n = int(input())for i in range(n): a, b, c = map(int,input().split()) count = 0 cola = a + b while(cola//c): count += cola//c cola = cola//c + cola%c print(int(count))