Score : $300$ points
Takahashi, who governs the Kingdom of AtCoder, has decided to change the alphabetical order of English lowercase letters.
The new alphabetical order is represented by a string $X$, which is a permutation of a
, b
, $\ldots$, z
. The $i$-th character of $X$ $(1 \leq i \leq 26)$ would be the $i$-th smallest English lowercase letter in the new order.
The kingdom has $N$ citizens, whose names are $S_1, S_2, \dots, S_N$, where each $S_i$ $(1 \leq i \leq N)$ consists of lowercase English letters.
Sort these names lexicographically according to the alphabetical order decided by Takahashi.
Simply speaking, the lexicographical order is the order in which words are listed in a dictionary. As a more formal definition, here is the algorithm to determine the lexicographical order between different strings $S$ and $T$.
Below, let $S_i$ denote the $i$-th character of $S$. Also, if $S$ is lexicographically smaller than $T$, we will denote that fact as $S \lt T$; if $S$ is lexicographically larger than $T$, we will denote that fact as $S \gt T$.
a
, b
, $\ldots$, z
.Input is given from Standard Input in the following format:
$X$ $N$ $S_1$ $S_2$ $\vdots$ $S_N$
Print $N$ lines. The $i$-th line $(1 \leq i \leq N)$ should contain the $i$-th smallest name when the citizens' names are sorted according to the alphabetical order decided by Takahashi.
bacdefghijklmnopqrstuvwxzy 4 abx bzz bzy caa
bzz bzy abx caa
In the new alphabetical order set by Takahashi, b
is smaller than a
and z
is smaller than y
. Thus, sorting the citizens' names lexicographically would result in bzz
, bzy
, abx
, caa
in ascending order.
zyxwvutsrqponmlkjihgfedcba 5 a ab abc ac b
b a ac ab abc