#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
#define FIL(x, v) memset(x, v, sizeof(x))
#define CLR(x) FIL(x, 0)
char s[200];
int bula[10][10]; //8*4
bool is0[10];
struct sq
{
    int l, r;
    int leng;
} q[10];
int cnt = 0;
bool cmp(const sq &a, const sq &b)
{
    if (a.leng == b.leng)
        return a.l > b.l;
    else
        return a.leng > b.leng;
}
int main()
{
    int T;
    scanf("%d", &T);
    for (int cas = 1; cas <= T; cas++)
    {
        CLR(s), CLR(bula), CLR(is0), CLR(q), cnt = 0;
        scanf("%s", s + 1);
        printf("Case #%d: ", cas);
        cnt = 0;
        memset(is0, 0, sizeof(is0));
        int cur = 1;
        for (int i = 1; i <= 8; i++)
        {
            bool zero = 1;
            for (int pos = 1; pos <= 4; pos++)
            {
                int chua = 0;
                for (int ka = 3; ka >= 0; ka--)
                {
                    int thisbit = s[cur++] - '0';
                    if (thisbit) chua ^= (thisbit << ka);
                }
                bula[i][pos] = chua;
                if (chua) zero = 0;
            }
            if (zero) is0[i] = 1;
        }
        /*	for(int i=1;i<=8;i++,cout<<":"){
			for(int j=1;j<=4;j++)cout<<bula[i][j];
		}
		puts("");*/
        bool con = 0;
        for (int i = 1; i <= 8; i++)
        {
            if (is0[i] && (!con))
            {
                cnt++;
                q[cnt].l = i;
                con = 1;
            }
            else if (is0[i] && con)
            {
                q[cnt].r = i;
            }
            else
            {
                con = 0;
            }
        }
        for (int i = 1; i <= cnt; i++) q[i].leng = q[i].r - q[i].l + 1;
        sort(q + 1, q + 1 + cnt, cmp);
        bool cg = 1;
        if (cnt < 1 || q[1].leng == 1) cg = 0;
        //if(cg&&q[1].l==1&&q[1].r==8){printf("::\n");continue;}
        for (int i = 1; i <= 8; i++)
        {
            if (cg)
            {
                if (q[1].l <= i && i <= q[1].r)
                {
                    if (i == 1 || i == q[1].r) printf(":");
                    continue;
                }
            }
            bool isfirst = 1;
            for (int j = 1; j <= 4; j++)
            {
                if (is0[i])
                {
                    printf("0");
                    break;
                }
                else if (bula[i][j] <= 9)
                {
                    if (bula[i][j] == 0 && isfirst)
                        continue;
                    else
                    {
                        printf("%d", bula[i][j]);
                        isfirst = 0;
                    }
                }
                else
                {
                    putchar('a' + bula[i][j] - 10);
                    isfirst = 0;
                }
            }
            if (i != 8) printf(":");
        }
        puts("");
    }
}
