#define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
#include <bits/stdc++.h>
using namespace std;
unsigned long long a[6666];
unsigned long long b[] = {1ull, 10ull, 100ull, 1000ull, 10000ull, 100000ull, 1000000ull, 10000000ull, 100000000ull, 1000000000ull, 10000000000ull};
int main()
{
    //freopen(R"(C:\Users\Administrator\Desktop\coj8\p122.in)", "r", stdin);
    int T, n;
    scanf("%d", &T);
    for (int t = 1; t <= T; t++)
    {
        scanf("%d", &n);
        for (int i = 0; i < n; i++)
            scanf("%llu", a + i);
        unsigned long long refans = 0;
        for (int i = 0; i < n; i++)
            for (int j = 0; j < i; j++)
                refans = max(a[j] * *upper_bound(b, b + 11, a[i]) + a[i], refans);
        printf("Case #%d: %llu\n", t, refans);
        continue;
		char ans[100];
        unsigned long long *x1 = max_element(a, a + n);
        unsigned long long v1 = *x1;
        *x1 = -1;
        unsigned long long *x2 = max_element(a, x1);
        unsigned long long v2 = *x2;
        *x2 = -1;
        unsigned long long *x3 = max_element(x1 + 1, a + n);
        unsigned long long v3 = *x3;
        *x3 = -1;
        unsigned long long ans1 = 0, ans2 = 0;
        if (a < x1)
        {
            sprintf(ans, "%llu%llu", v2, v1);
            sscanf(ans, "%llu", &ans1);
        }
        if (x1 + 1 < a + n)
        {
            sprintf(ans, "%llu%llu", v1, v3);
            sscanf(ans, "%llu", &ans2);
        }
        printf("Case #%d: %llu %llu\n", t, max(ans1, ans2), max(ans1, ans2) - refans);
    }
    return 0;
}
