#ifdef Asaad
#include "cp.h"
#define debug(...) _dbg_many(#__VA_ARGS__, __VA_ARGS__)
#define here cerr << "LINE " << __LINE__ << "\n"
#else
#include <bits/stdc++.h>
using namespace std;
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
*/
#define debug(...)
#define here
#endif
#define ll long long
#define int long long
#define all(x) x.begin(), x.end()
#define siz(x) ((int)x.size())
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define f first
#define s second
#define eb emplace_back
#define pb push_back
const int mod = 1e9+7;
const int N = 200009;
const long long inf = 1e18+12309138;
double eps = 1e-9;
void tc () {
//nb=
int w;
int x, y;
int ans[2] = {0};
cin >> x >> y >> w;
if ( w == 1 ) {
cout << x << " " << y << "\n";
return;
}
bool p = 0;
bool big = ( x < y );
int dif = abs(x-y);
ans[big] += (dif+w-1)/w;
int tot = min(x, y)*2;
int rem = (w-(dif%w))%w;
if ( rem > 0 ) {
if ( big && (tot>0) ) ans[0]++;
else if ( rem > 1 && (tot>1) ) ans[1]++;
p^=rem%2;
if ( tot <= rem ) {
cout << ans[0] << " " << ans[1] << "\n";
return;
}
tot-= rem;
}
ans[0] += tot/w;
ans[1] += tot/w;
p^=((tot/w)*w)%2;
tot-= (tot/w)*w;
if ( tot > 0 ) ans[p]++;
if ( tot > 1 ) ans[p^1]++;
cout << ans[0] << " " << ans[1] << "\n";
}
signed main () {
ios::sync_with_stdio(false);
cin.tie(0);
//freopen( "input.txt", "r", stdin );
//freopen( "output.txt", "w", stdout );
//cout << fixed << setprecision(9);
//pre();
int t=1;
cin >> t;
for (int i=1; i<=t; i++) {
#ifdef Asaad
auto start = chrono::high_resolution_clock::now();
//cout << "---Case " << i << " Start---\n\n";
#endif
tc();
#ifdef Asaad
auto end = chrono::high_resolution_clock::now();
//cout << "---Case " << i << " End---\n";
cerr << "Time #" << i << ": " << chrono::duration_cast<chrono::milliseconds>(end - start).count() << "ms" << endl;
//cout << "--------------\n";
#endif
}
}