Under construction

Still being built. Things may change

Counting Sheep (Small)

Interview

Time limit5sMemory limit512 MB

Summary
Track which digits 0 to 9 appear as Bleatrix counts multiples of N, and report the last multiple or INSOMNIA if digit 9 never completes.
Level

Easy3 of 10

Topics
Simulation, Implementation, Math
Solved
No attempts yet

Problem

A sheep named Bleatrix has come up with a strategy to fall asleep faster.

First, she picks a number NN. Then she thinks of NN, 2×N2 \times N, 3×N3 \times N, and so on. Each time she thinks of a number, she writes down every digit that appears in it, but she does not write down a digit she has already written. Once all ten digits from 0 to 9 have been written down, she falls asleep.

Bleatrix starts from NN, and after i×Ni \times N she always thinks of (i+1)×N(i + 1) \times N. For example, if N=1692N = 1692, the process goes like this:

  • N=1692N = 1692. She has written 1, 2, 6, 9.
  • 2N=33842N = 3384. She has written 1, 2, 3, 4, 6, 8, 9.
  • 3N=50763N = 5076. She has written every digit, and she falls asleep.

What is the last number Bleatrix thinks of before she falls asleep? If she will never fall asleep, print INSOMNIA.

Input

The first line contains the number of test cases TT. Each of the next TT lines contains one test case: the number NN that Bleatrix picked.

  • 1≤T≤1001 \le T \le 100
  • 0≤N≤2000 \le N \le 200

Output

For each test case, print one line Case #x: y, where xx is the test case number starting from 1 and yy is the last number Bleatrix thinks of before she falls asleep. If she will never fall asleep, print INSOMNIA in place of yy.

Hint

In the first case of the sample, 2×0=02 \times 0 = 0, 3×0=03 \times 0 = 0, and so on, so Bleatrix never writes down any digit other than 0. She will never fall asleep.

In the second case, she thinks of 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 in that order, and 0 is the last digit she writes down. The answer is 10.

In the third case, she thinks of 2, 4, 6, and so on. She cannot write down the digit 9 before she reaches 90. By the time she thinks of 90, she has already written every digit from 0 to 8, so the answer is 90.

In the fourth case, she thinks of 11, 22, 33, 44, 55, 66, 77, 88, 99, 110, so the answer is 110.

Examples1

  1. Example 1

    Input
    4
    0
    1
    2
    11
    
    Expected output
    Case #1: INSOMNIA
    Case #2: 10
    Case #3: 90
    Case #4: 110