#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
vector<array<int, 4>> v = {
{9, 0, 0, 0},
{7, 1, 0, 0},
{5, 2, 0, 0},
{3, 3, 0, 0},
{1, 4, 0, 0},
{6, 0, 0, 1},
{4, 1, 0, 1},
{2, 2, 0, 1},
{0, 3, 0, 1},
{3, 0, 1, 1},
{1, 2, 1, 1},
{3, 0, 0, 2},
{0, 0, 1, 2},
{1, 1, 0, 2},
{0, 0, 3, 0},
{3, 0, 2, 0},
{1, 1, 2, 0},
{6, 0, 1, 0},
{4, 1, 1, 0},
{2, 2, 1, 0},
{0, 3, 1, 0},
{1, 1, 1, 1}
};
int dp[50][50][50][50];
int DP(int a, int b, int c, int d) {
if(a < 0 or b < 0 or c < 0 or d < 0)return -1;
if(a == 0 and b == 0 and c == 0 and d == 0) return 0;
int res = 0;
for(auto &[i, j, k, l] : v) {
if(i <= a and j <= b and k <= c and l <= d) {
res = max(res, DP(a - i, b - j, c - k, d - l) + 1);
}
}
return dp[a][b][c][d] = res;
}
void run(){
int a, b, c, d;
cin >> a >> b >> c >> d;
cout << DP(a, b, c, d) << 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;
}