#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
char s[1050];
int pre[256];
int main()
{
    int T;
    scanf("%d", &T);
    for (int t = 1; t <= T; t++)
    {
        scanf("%s", s);
        memset(pre, -1, sizeof(pre));
        unsigned ans = -1;
        int n = strlen(s);
        for (int i = 0; i < n; i++)
        {
            if (pre[s[i]] != -1)
                ans = min<unsigned>(ans, i - pre[s[i]]);
            pre[s[i]] = i;
        }

        printf("Case #%d: %d\n", t, ans);
    }
    return 0;
}