#P13435. [GCJ 2009 #1B] The Next Number

[GCJ 2009 #1B] The Next Number

题目描述

You are writing out a list of numbers. Your list contains all numbers with exactly DiD_i digits in its decimal representation which are equal to ii, for each ii between 1 and 9, inclusive. You are writing them out in ascending order.

For example, you might be writing every number with two '1's and one '5'. Your list would begin 115, 151, 511, 1015, 1051.

Given NN, the last number you wrote, compute what the next number in the list will be.

输入格式

The first line of input contains an integer TT, the number of test cases in the input. TT lines follow, one for each test case, each containing a single integer NN.

输出格式

For each test case, output

Case #XX: KK

where XX is the test case number, starting from 1, and KK is the next integer in the list.

3
115
1051
6233
Case #1: 151
Case #2: 1105
Case #3: 6323

提示

Limits

Small dataset(9 Pts)

  • Time limit: 20 2 seconds.
  • 1T501 \leq T \leq 50
  • 1N1061 \leq N \leq 10^6

Large dataset(26 Pts)

  • Time limit: 30 3 seconds.
  • 1T5001 \leq T \leq 500
  • 1N10201 \leq N \leq 10^{20}