#P13437. [GCJ 2009 #1C] All Your Base

[GCJ 2009 #1C] All Your Base

题目描述

In A.D. 2100, aliens came to Earth. They wrote a message in a cryptic language, and next to it they wrote a series of symbols. We've come to the conclusion that the symbols indicate a number: the number of seconds before war begins!

Unfortunately we have no idea what each symbol means. We've decided that each symbol indicates one digit, but we aren't sure what each digit means or what base the aliens are using. For example, if they wrote "ab2ac999", they could have meant "31536000" in base 10 -- exactly one year -- or they could have meant "12314555" in base 6 -- 398951 seconds, or about four and a half days. We are sure of three things: the number is positive; like us, the aliens will never start a number with a zero; and they aren't using unary (base 1).

Your job is to determine the minimum possible number of seconds before war begins.

输入格式

The first line of input contains a single integer, TT. TT test cases follow. Each test case is a string on a line by itself. The line will contain only characters in the 'a' to 'z' and '0' to '9' ranges (with no spaces and no punctuation), representing the message the aliens left us. The test cases are independent, and can be in different bases with the symbols meaning different things.

输出格式

For each test case, output a line in the following format:

Case #XX: VV

Where XX is the case number (starting from 1) and VV is the minimum number of seconds before war begins.

3
11001001
cats
zig
Case #1: 201
Case #2: 75
Case #3: 11

提示

Limits

  • 1T1001 \leq T \leq 100
  • The answer will never exceed 101810^{18}

Small dataset(8 Pts)

  • 1the length of each line<101 \leq \text{the length of each line} < 10

Large dataset(15 Pts)

  • 1the length of each line<611 \leq \text{the length of each line} < 61