Fill
#include<bits/stdc++.h>
using namespace std;
const int maxn = 200 + 5;
int T, a, b, c, d;
struct node{
int v[3], dist;
bool operator < (const node& rhs) const{
return dist > rhs.dist;
}
};
int cap[3], vis[maxn][maxn], ans[maxn];
void update_ans(const node& u){
for(int i = 0; i < 3; i++){
int d = u.v[i];
if(ans[d] < 0 || ans[d] > u.dist) ans[d] = u.dist;
}
}
void solve(){
memset(vis, 0, sizeof(vis));
memset(ans, -1, sizeof(ans));
node start;
start.v[0] = 0, start.v[1] = 0, start.v[2] = c, start.dist = 0;
cap[0] = a, cap[1] = b, cap[2] = c;
priority_queue<node> q;
q.push(start);
vis[0][0] = 1;
while(!q.empty()){
node u = q.top(); q.pop();
update_ans(u);
if(ans[d] >= 0) break;
for(int i = 0; i < 3; i++){
for(int j = 0; j < 3; j++) if(i != j){
if(u.v[i] == 0 || u.v[j] == cap[j]) continue;
int amount = min(cap[j], u.v[i] + u.v[j]) - u.v[j];
node u2;
memcpy(&u2, &u, sizeof(u));
u2.v[i] -= amount;
u2.v[j] += amount;
u2.dist += amount;
if(!vis[u2.v[0]][u2.v[1]]){
vis[u2.v[0]][u2.v[1]] = 1;
q.push(u2);
}
}
}
}
while(d >= 0){
if(ans[d] >= 0){
printf("%d %d\n", ans[d], d);
return;
}
d--;
}
}
int main()
{
scanf("%d", &T);
while(T--){
scanf("%d%d%d%d", &a, &b, &c, &d);
solve();
}
return 0;
}