#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#ifdef LOCAL
#include "debug.h"
#else
#define print(...)
#define printt(...)
#endif
#define int long long
void run(){
int a[4];
for( int i=0 ; i<4 ; i++ )
cin >> a[i];
int ans = 0;
ans += a[2] / 3;
a[2] %= 3;
int x = a[3] / 2 + (a[2] == 2);
a[3] %= 2;
if(a[2] == 2)a[2] = 0;
while(x > 1) {
if(a[1] > 0 and a[0] > 0) {
ans++;
a[1]--;
a[0]--;
x -= 2;
}else if(a[0] > 2) {
a[0] -= 3;
x -= 2;
}else
break;
}
int y = (a[2] + a[3]) * 3 + a[1] * 2 + a[0];
ans += y / 9;
cout << ans << endl;
}
int32_t main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int t = 1, cs = 1;
cin >> t;
while( t --> 0 ) {
cout << "Case " << cs++ << ": ";
run();
}
return 0;
}