import itertools

def A(a,b):
    return a+b

def S(a,b):
    return a-b

def M(a,b):
    return a*b

def D(a,b):
    if b==0 or a%b:
        raise Exception
    return a/b

ops = ["A", "M", "S", "D"]

brackets = [
"{0}({1}({2}({3},{4}),{5}),{6})",
"{0}({1}({3},{2}({4},{5})),{6})",
"{0}({2}({3},{4}),{1}({5},{6}))",
"{0}({3},{1}({4},{2}({5},{6})))",
"{0}({3},{1}({2}({4},{5}),{6}))",
"{0}({3},{1}({4},{2}({5},{6})))"]

t=1

while(True):
    inp = raw_input().split()
    if ''.join(inp) == "0000":
        break

    ans = set([])

    for op1 in ops:
        for op2 in ops:
            for op3 in ops:
                for nums in itertools.permutations([int(i) for i in inp], 4):
                    for bracket in brackets:
                        expr = bracket.format(op1,op2,op3,nums[0],nums[1],nums[2],nums[3])
                        try:
                            a = eval(expr)
                        except:
                            continue
                        else:
                            ans.add(a)

    ans = sorted(ans)
    i=0
    maxlen = -1
    maxans = 0
    minans = 0
    while i<len(ans):
        j=i
        prev = ans[i]-1
        while j<len(ans) and ans[j] == prev+1:
            prev = ans[j]
            j += 1
        if (j-i) >= maxlen:
            minans = ans[i]
            maxans = ans[j-1]
            maxlen = (j-i)
        i += 1
    print "Case {}: {} to {}".format(t,minans,maxans)


    t+=1