/*One touch and i IGNITE*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define F first
#define S second
#define endl "\n"
#define Endl "\n"
const int N = 2e5 + 5;
int tc, n, casee = 1, a, b, c, d;
int dp[50][50][50][50];
struct R {
int a, b, c, d;
};
vector<R> v;
void buildBaseCase() {
/// this is --a, b, c, d
v.push_back({0, 0, 1, 2});
v.push_back({0, 0, 3, 0});
// v.push_back({0, 3, 0, 1});
v.push_back({0, 3, 1, 0});
v.push_back({1, 1, 0, 2});
v.push_back({1, 1, 1, 1});
v.push_back({1, 1, 2, 0});
v.push_back({1, 4, 0, 0});
v.push_back({2, 2, 0, 1});
v.push_back({2, 2, 1, 0});
v.push_back({3, 0, 0, 2});
v.push_back({3, 0, 1, 1});
v.push_back({3, 0, 2, 0});
v.push_back({3, 3, 0, 0});
v.push_back({4, 1, 0, 1});
v.push_back({4, 1, 1, 0});
v.push_back({5, 2, 0, 0});
v.push_back({6, 0, 0, 1});
v.push_back({6, 0, 1, 0});
v.push_back({7, 1, 0, 0});
v.push_back({9, 0, 0, 0});
}
int rec(int a, int b, int c, int d) {
bool notPossible = true;
for (auto i : v) {
if (i.a <= a && i.b <= b && i.c <= c && i.d <= d) {
notPossible = false;
break;
}
}
if (notPossible)
return 0;
int &ret = dp[a][b][c][d];
if (~ret)
return ret;
ret = 0;
for (auto i : v) {
if (i.a <= a && i.b <= b && i.c <= c && i.d <= d) {
ret = max(ret, 1 + rec(a - i.a, b - i.b, c - i.c, d - i.d));
}
}
return ret;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0); // cout.tie(0);
// freopen("Input/input37.txt", "r", stdin);
// freopen("Output/output37.txt", "w", stdout);
buildBaseCase();
cin >> tc;
while (tc--) {
cin >> a >> b >> c >> d;
memset(dp, -1, sizeof dp);
int Ans = rec(a, b, c, d);
cout << "Case " << casee++ << ": " << Ans << endl;
}
return 0;
}