#include <iostream>

using namespace std;

int main() {
    int t;
    cin >> t;
    while(t--){
    	long x,y,k;
    	cin >> x >> y >> k;
    	long moves_X = (x+k-1)/k;
    	long moves_Y = (y+k-1)/k;
    	if(moves_X <= moves_Y)
    		cout << moves_Y*2;
    	else
    		(moves_X-1)*k >= y ? cout << moves_X*2 - 1 : cout << moves_X*2;
    	cout << endl;
    }
    return 0;
}
