logo AlgoBeat OnlineJudge
登录 注册

#216946. [ICPC 2017 Shenyang R] Infinite Fraction Path

内存限制:512 MiB 时间限制:3000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

The ant Welly now dedicates himself to urban infrastructure. He came to the kingdom of numbers and solicited an audience with the king. He recounted how he had built a happy path in the kingdom of happiness. The king affirmed Welly’s talent and hoped that this talent can help him find the best infinite fraction path before the anniversary.

The kingdom has cities numbered from to and you are given an array of decimal digits (, is an integer). The destination of the only one-way road start from the -th city is the city labelled .

A path beginning from the -th city would pass through the cities , and so on consecutively. The path constructs a real number , called the relevant fraction such that the integer part of it is equal to zero and its fractional part is an infinite decimal fraction with digits , and so on.

The best infinite fraction path is the one with the largest relevant fraction.

输入格式

The input contains multiple test cases and the first line provides an integer up to 100 indicating to the total number of test cases.

For each test case, the first line contains the integer (). The second line contains an array of digits , given without spaces.

The summation of is smaller than .

输出格式

For each test case, you should output the label of the case first. Then you are to output exactly characters which are the first digits of the fractional part of the largest relevant fraction.

样例

样例输入 1

4
3
149
5
12345
7
3214567
9
261025520

样例输出 1

Case #1: 999
Case #2: 53123
Case #3: 7166666
Case #4: 615015015