Under construction

Still being built. Things may change

Beautiful Numbers (Small)

Time limit5sMemory limit512 MB

Summary
For each N, find a base B > 1 where N is written with only the digit 1, preferring the base with the most 1 digits.
Level

Easy3 of 10

Topics
Math, Brute force, Number theory, Implementation
Solved
No attempts yet

Problem

Call a number beautiful if it is written with the digit 1 repeated one or more times. Not every number is beautiful in base 10, but any positive integer can be made beautiful by writing it in another base.

You are given an integer NN. Find a base BB (with B>1B > 1) such that every digit of NN written in base BB is 1. If several bases work, choose the one that gives the most 1 digits.

Input

The first line contains the number of test cases TT. Each of the following TT lines contains one integer NN.

Limits

  • 1≤T≤1001 \le T \le 100
  • 3≤N≤10003 \le N \le 1000

Output

For each test case, print one line of the form Case #x: y, where xx is the test case number starting from 1 and yy is the base described above.

Hint

For N=3N = 3 the best answer is 11 in base 2, so BB is 2.

For N=13N = 13 the best answer is 111 in base 3, so BB is 3. The number 13 is also 11 in base 12, but that form has fewer 1 digits.

Examples1

  1. Example 1

    Input
    2
    3
    13
    
    
    Expected output
    Case #1: 2
    Case #2: 3