logo AlgoBeat OnlineJudge
登录 注册

#216838. [GKS 2021 #E] Shuffled Anagrams

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

题目描述

Let be a string containing only letters of the English alphabet. An anagram of is any string that contains exactly the same letters as (with the same number of occurrences for each letter), but in a different order. For example, the word kick has anagrams such as kcik and ckki.

Now, let be the -th letter in . We say that an anagram of , , is shuffled if and only if for all , . So, for instance, kcik is not a shuffled anagram of kick as the first and fourth letters of both of them are the same. However, ckki would be considered a shuffled anagram of kick, as would ikkc.

Given an arbitrary string , your task is to output any one shuffled anagram of , or else print IMPOSSIBLE if this cannot be done.

输入格式

The first line of the input gives the number of test cases, . test cases follow. Each test case consists of one line, a string of English letters.

输出格式

For each test case, output one line containing Case #: , where is the test case number (starting from ) and is a shuffled anagram of the string for that test case, or IMPOSSIBLE if no shuffled anagram exists for that string.

样例

样例输入 1

2
start
jjj

样例输出 1

Case #1: tarts
Case #2: IMPOSSIBLE

数据范围与提示

In test case #, tarts is a shuffled anagram of start as none of the letters in each position of both strings match the other. Another possible solution is trsta (though you only need to provide one solution). However, in test case #, there is no way of anagramming jjj to form a shuffled anagram, so IMPOSSIBLE is printed instead.

Limits

.

All input letters are lowercase English letters.

Test Set 1

.

Test Set 2

.