#include <iostream>
using namespace std;
int main()
{
int m , k , l , h;
cin >> m;
while( m-- )
{
cin >> k >> l >> h;
int i = ( k + l ) / h;
k = ( k + l ) % h + ( k + l ) / h;
while( k >= h )
{
i += k / h;
k = k / h + k % h;
}
cout << i << endl;
}
return 0;
}