[Solution] Manipulating History Codeforces Solution | Codeforces Problem Solution 2022
Keine has the ability to manipulate history.
The history of Gensokyo is a string of length initially. To fix the chaos caused by Yukari, she needs to do the following operations times, for the -th time:
- She chooses a non-empty substring of .
- She replaces with a non-empty string, . Note that the lengths of strings and can be different.
Note that if occurs more than once in , exactly one of them will be replaced.
For example, let "marisa", "a", and "z". After the operation, becomes "mzrisa" or "marisz".
After operations, Keine got the final string and an operation sequence of length . Just as Keine thinks she has finished, Yukari appears again and shuffles the order of . Worse still, Keine forgets the initial history.
Help Keine find the initial history of Gensokyo!
Recall that a substring is a sequence of consecutive characters of the string. For example, for string "abc" its substrings are: "ab", "c", "bc" and some others. But the following strings are not its substring: "ac", "cba", "acb".
Hacks
You cannot make hacks in this problem.
Each test contains multiple test cases. The first line contains a single integer () — the number of test cases. The description of the test cases follows.
The first line of each test case contains a single integer () — the number of operations.
The next lines contains one non-empty string — the -th string of the shuffled sequence .
The next line contains one non-empty string — the final string.
It is guaranteed that the total length of given strings (including and ) over all test cases does not exceed . All given strings consist of lowercase English letters only.
It is guaranteed that the initial string exists. It can be shown that the initial string is unique.
For each test case, print the initial string in one line.
No comments:
Post a Comment