QOJ.ac

QOJ

Time Limit: 60 s Memory Limit: 1024 MB Total points: 26

#24790. Silly Substitutions

Statistics

You are given a string $S$ of length $N$ which consists of digits 0-9. You do the following operations on the string in the order given.

1. Find all the substrings 01 and replace each of them with 2. 2. Find all the substrings 12 and replace each of them with 3. 3. Find all the substrings 23 and replace each of them with 4. 4. Find all the substrings 34 and replace each of them with 5. .

.

.

9. Find all the substrings 89 and replace each of them with 0. 10. Find all the substrings 90 and replace each of them with 1.

You repeat this process in the same given order until none of the above operations change the string. For example, if $S$ is 12 then we do not stop at operation $1$ since it does not affect the string but perform operation $2$ and change the string to 3. We can see that the string does not change further no matter how many times we repeat the above process.

Your task is to find how the final string will look like for the given $S$.

Input

The first line of the input gives the number of test cases, $T$. $T$ test cases follow. Each test case consists of two lines.

The first line of each test case contains an integer $N$, denoting the length of the string $S$.

The second line of each test case contains a string $S$ of length $N$.

Output

For each test case, output one line containing Case #$x$: $y$, where $x$ is the test case number (starting from 1) and $y$ is the final string obtained.

Constraints

$1 \le T \le 100$.

The input string only consists of digits 0-9.

Test Set 1

$1 \le N \le 100$.

Test Set 2

For at most 10 cases:

$1 \le N \le 5 \times 10^5$.

For the remaining cases:

$1 \le N \le 100$.

Examples

Input 1

4
3
012
4
0145
5
00000
11
98765432101

Output 1

Case #1: 22
Case #2: 26
Case #3: 00000
Case #4: 1

Note

In Sample Case #1, substring 01 is replaced with 2 and the resulting string is 22 which is not affected further by any of the operations. Therefore final string is 22.

In Sample Case #2, substring 01 is replaced with 2 and the resulting string is 245. The substring 45 is replaced with 6 and the resulting string is 26 which is not further affected by any of the operations. Therefore final string is 26.

In Sample Case #3, since the operations cannot be performed on the given string, the string does not change.

In Sample Case #4, all the operations can be performed sequentially on the string and the final string is 1.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.