GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

Friday, 3 June 2022

[Solution] Manipulating History Codeforces Solution | Codeforces Problem Solution 2022

C. Manipulating History
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Keine has the ability to manipulate history.

The history of Gensokyo is a string s of length 1 initially. To fix the chaos caused by Yukari, she needs to do the following operations n times, for the i-th time:

  • She chooses a non-empty substring t2i1 of s.
  • She replaces t2i1 with a non-empty string, t2i. Note that the lengths of strings t2i1 and t2i can be different.

Note that if t2i1 occurs more than once in sexactly one of them will be replaced.

Solution Click Below:-  CLICK HERE

For example, let s="marisa", t2i1="a", and t2i="z". After the operation, s becomes "mzrisa" or "marisz".

After n operations, Keine got the final string and an operation sequence t of length 2n. Just as Keine thinks she has finished, Yukari appears again and shuffles the order of t. 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.


Input

Each test contains multiple test cases. The first line contains a single integer T (1T103) — the number of test cases. The description of the test cases follows.

The first line of each test case contains a single integer n (1n<105) — the number of operations.

The next 2n lines contains one non-empty string ti — the i-th string of the shuffled sequence t.

The next line contains one non-empty string s — the final string.

It is guaranteed that the total length of given strings (including ti and s) over all test cases does not exceed 2105. 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.

Output

For each test case, print the initial string in one line.

No comments:

Post a Comment