QOJ.ac

QOJ

時間限制: 1.5 s 記憶體限制: 512 MB 總分: 100

#17604. VESUVIUS

统计

The organizers of a regional ICPC competition failed to provide suitable conditions for the contest, so they decided to rank the teams lexicographically. Thus, the team whose name is lexicographically smallest will be declared the winner.

The heroine of this task, Etna, is the leader of a team whose identity we will hide, but it is enough to say that it is a team whose name starts with the letter 'Z', which puts it in a rather poor position. After long discussions with the committee, Etna managed to fight for a somewhat fairer way of ranking the teams. Unfortunately, the teams will still be ranked lexicographically, but the definition of lexicographical order will change. More precisely, the committee will randomly choose a permutation of the English alphabet, and the lexicographical order will be naturally defined using that permutation. In other words, the order of letters in the permutation will correspond to their lexicographical order.

Etna immediately took out her laptop and wrote a program that finds, for each team, a permutation of letters according to which that specific team will win the competition. Unfortunately, the program has not finished running to this day. Help Etna and write a more efficient program with the same functionality.

Input

The first line contains a natural number $N$, representing the number of teams participating in the competition.

The next $N$ lines contain the names of the teams participating in the competition. Each team's name consists of a single word, which in turn consists of lowercase English letters. Naturally, the team names are distinct.

Output

For each team, in the order they are listed in the input, you need to print in a separate line a permutation of the English alphabet according to which that team will win the competition. If no such permutation exists, you need to print the word "nemoguce", and if there are multiple such permutations, it is sufficient to print any one of them.

Subtasks

Let $L$ be the sum of the lengths of the words of all $N$ teams, and $K$ be the number of distinct letters that appear in the names of all teams.

Subtask Points Constraints
1 13 $1 \le N \le 100, 1 \le L \le 10\,000, 1 \le K \le 6$
2 32 $1 \le N \le 350, 1 \le L \le 10\,000, 1 \le K \le 26$
3 55 $1 \le N \le 25\,000, 1 \le L \le 1\,000\,000, 1 \le K \le 26$

Examples

Input 1

3
war
zag
wro

Output 1

agorwzbcdefhijklmnpqstuvxy
agorzwbcdefhijklmnpqstuvxy
gorawzbcdefhijklmnpqstuvxy

Input 2

3
b
ab
aa

Output 2

bacdefghijklmnopqrstuvwxyz
nemoguce
abcdefghijklmnopqrstuvwxyz

Input 3

7
bcada
dbaab
bbabc
ababb
aacdf
bcdff
baddb

Output 3

cbadfeghijklmnopqrstuvwxyz
cdabfeghijklmnopqrstuvwxyz
bacdfeghijklmnopqrstuvwxyz
nemoguce
abcdfeghijklmnopqrstuvwxyz
cbdafeghijklmnopqrstuvwxyz
nemoguce

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.