提示: 欢迎访问OurACM平台。
Problem 1912 Divisibility by Thirty-six

Accept: 109    Submit: 574
Time Limit: 1000 mSec    Memory Limit : 32768 KB

Problem Description

There is a string containing only decimal digit characters. The length of the string is between 1 and 1,000. Using characters of the string, you have to construct the maximum number which divides by thirty-six without remainder. Each character of the string may not be used more than once.

Input

The first line of the input contains an integer T (T <= 1000), indicating the number of cases. Each case begins with a line containing a single line representing the source string.

Output

For each test case, print a line containing the test case number (beginning with 1) and the decimal representation of the maximum number (leading zeroes should be omitted). If no number can be constructed, please output “impossible” instead.

Sample Input

2 03061 345

Sample Output

Case 1: 6300 Case 2: impossible

Source

2010年全国大学生程序设计邀请赛(福州)

Submit  Back  Status  Discuss