#define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
#include <bits/stdc++.h>
using namespace std;
#define CRP(t, x) const t &x
#define OPL(t, x) bool operator<(CRP(t, x)) const
#define FIL(x, v) memset(x, v, sizeof(x))
#define CLR(x) FIL(x, 0)
#define NE1(x) FIL(x, -1)
#define INF(x) FIL(x, 0x3f)
typedef long long ll, i64;
char s[129];
int a[8];
int main()
{
    set<string> S;
    int T;
    scanf("%d", &T);
    for (int t = 1; t <= T; t++)
    {
        CLR(a), scanf("%s", s);
        printf("Case #%d: ", t);
        for (int i = 0; i < 8; i++)
            for (int j = 0; j < 16; j++)
                a[i] = a[i] << 1 | (s[i << 4 | j] - '0');
        //for (int i = 0; i < 8; i++) printf("%x%c", a[i], ":\n"[i == 7]);
        //for (int i = 0; i < 8; i++) scanf("%x", a + i);
        S.clear();
        string str;
        for (int len = 8; len >= 2; len--)
        {
            int pos = -1;
            for (int st = 7; st - len + 1 >= 0; st--)
                if (all_of(a + st - len + 1, a + st + 1, [](int x) { return x == 0; }))
                {
                    pos = st - len + 1;
                    str.clear();
                    for (int i = 0; i < pos; i++)
                    {
                        sprintf(s, "%x", a[i]), str += s;
                        if (i < 7) str += ':';
                    }
                    if (pos == 0) str += ':';
                    for (int i = pos + len; i < 8; i++)
                    {
                        if (i) str += ':';
                        sprintf(s, "%x", a[i]), str += s;
                    }
                    if (pos + len == 8) str += ':';
                    S.insert(str);
                }
            if (!S.empty()) break;
        }
        if (!S.empty())
        {
            //cout << *S.begin() << endl;
            int ml = 0x3f3f3f3f;
            for (auto &s : S) ml = min(ml, (int)s.size());
            for (auto &s : S)
                if (s.size() == ml)
                {
                    cout << s << endl;
                    break;
                }
        }
        else
            for (int i = 0; i < 8; i++)
                printf("%x%c", a[i], ":\n"[i == 7]);
    }
    return 0;
}
//ljtql