#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
using namespace std;
#define re(i, n) for (int i=0; i<n; i++)
#define re1(i, n) for (int i=1; i<=n; i++)
#define re2(i, l, r) for (int i=l; i<r; i++)
#define re3(i, l, r) for (int i=l; i<=r; i++)
#define rre(i, n) for (int i=n-1; i>=0; i--)
#define rre1(i, n) for (int i=n; i>0; i--)
#define rre2(i, r, l) for (int i=r-1; i>=l; i--)
#define rre3(i, r, l) for (int i=r; i>=l; i--)
const int M = 101, S = 1024, MAXN = 11, INF = ~0U >> 2;
struct sss {
int v, sum;
bool operator< (sss s0) const {
if (sum < s0.sum) return 1; else if (sum > s0.sum) return 0; else return v < s0.v;
}
} V0[S];
bool F[M][S];
int n, A[MAXN], res;
void prepare()
{
int i0, KK, tmp;
re2(i, 1, M) {
i0 = i; KK = 0; while (i0) {tmp = 1 << (i0 % 10); if (KK & tmp) {KK = -1; break;} else KK |= tmp; i0 /= 10;} if (KK >= 0) F[i][KK] = 1;
for (int j=1; j+j<=i; j++) {
KK = 0; i0 = j; while (i0) {tmp = 1 << (i0 % 10); if (KK & tmp) {KK = -1; break;} else KK |= tmp; i0 /= 10;}
if (KK >= 0) {
i0 = i - j; while (i0) {tmp = 1 << (i0 % 10); if (KK & tmp) {KK = -1; break;} else KK |= tmp; i0 /= 10;}
if (KK >= 0) F[i][KK] = 1;
}
}
re(j, S) if (F[i][j]) {
re(k, 10) F[i][j | (1 << k)] = 1;
}
}
re(i, S) {
KK = 0; re(j, 10) if (i & (1 << j)) KK++;
V0[i].v = i; V0[i].sum = KK;
}
sort(V0, V0 + S);
}
void solve()
{
bool FF; int x;
re(i, S) {
x = V0[i].v; FF = 1; re(j, n) if (!F[A[j]][x]) {FF = 0; break;}
if (FF) {res = x; break;}
}
}
int main()
{
int testno = 0; prepare();
while (1) {
scanf("%d", &n); if (!n) break; else testno++;
re(i, n) scanf("%d", &A[i]);
solve();
printf("Case %d: ", testno); rre(i, 10) if (res & (1 <<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