def parse():
	x = int(input())
	return x

def solve(x):
	if not x: return "INSOMNIA"
	k = 0
	l = [False]*10
	while not all(l):
		k += x
		for c in str(k): l[int(c)] = True
	return k

def main():
	for i in range(int(input())):
		x = parse()
		y = solve(x)
		print("Case #{}: {}".format(i+1, y))

if __name__ == "__main__": main()
d8146da3aabc2b17f03d81666cfd57dffe131755
def parse():
    x = int(input())
    return x


<mask token>

def parse():
    x = int(input())
    return x


def solve(x):
    if not x:
        return 'INSOMNIA'
    k = 0
    l = [False] * 10
    while not all(l):
        k += x
        for c in str(k):
            l[int(c)] = True
    return k


<mask token>

def parse():
    x = int(input())
    return x


def solve(x):
    if not x:
        return 'INSOMNIA'
    k = 0
    l = [False] * 10
    while not all(l):
        k += x
        for c in str(k):
            l[int(c)] = True
    return k


def main():
    for i in range(int(input())):
        x = parse()
        y = solve(x)
        print('Case #{}: {}'.format(i + 1, y))


<mask token>

def parse():
    x = int(input())
    return x


def solve(x):
    if not x:
        return 'INSOMNIA'
    k = 0
    l = [False] * 10
    while not all(l):
        k += x
        for c in str(k):
            l[int(c)] = True
    return k


def main():
    for i in range(int(input())):
        x = parse()
        y = solve(x)
        print('Case #{}: {}'.format(i + 1, y))


if __name__ == '__main__':
    main()

def parse():
	x = int(input())
	return x

def solve(x):
	if not x: return "INSOMNIA"
	k = 0
	l = [False]*10
	while not all(l):
		k += x
		for c in str(k): l[int(c)] = True
	return k

def main():
	for i in range(int(input())):
		x = parse()
		y = solve(x)
		print("Case #{}: {}".format(i+1, y))

if __name__ == "__main__": main()