CF BUDDY
← Problems·

1688C · Manipulating History

1700 · constructive algorithms, greedy, strings

Problem: Keine has the ability to manipulate history.

The history of Gensokyo is a string ss of length 11 initially. To fix the chaos caused by Yukari, she needs to do the following operations nn times, for the ii-th time:

  • She chooses a non-empty substring t2i1t_{2i-1} of ss.
  • She replaces t2i1t_{2i-1} with a non-empty string, t2it_{2i}. Note that the lengths of strings t2i1t_{2i-1} and t2it_{2i} can be different.

Note that if t2i1t_{2i-1} occurs more than once in ss, exactly one of them will be replaced.

For example, let s=s="marisa", t2i1=t_{2i-1}="a", and t2i=t_{2i}="z". After the operation, ss becomes "mzrisa" or "marisz".

After nn operations, Keine got the final string and an operation sequence tt of length 2n2n. Just as Keine thinks she has finished, Yukari appears again and shuffles the order of tt. 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 Format: Each test contains multiple test cases. The first line contains a single integer TT (1T1031 \leq T \leq 10^3) — the number of test cases. The description of the test cases follows.

The first line of each test case contains a single integer nn (1n<1051 \le n < 10 ^ 5) — the number of operations.

The next 2n2n lines contains one non-empty string tit_{i} — the ii-th string of the shuffled sequence tt.

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

It is guaranteed that the total length of given strings (including tit_i and ss) over all test cases does not exceed 21052 \cdot 10 ^ 5. 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 Format: For each test case, print the initial string in one line.

Note: Test case 1:

Initially ss is "a".

  • In the first operation, Keine chooses "a", and replaces it with "ab". ss becomes "ab".
  • In the second operation, Keine chooses "b", and replaces it with "cd". ss becomes "acd".

So the final string is "acd", and t=[t=["a", "ab", "b", "cd"]] before being shuffled.

Test case 2:

Initially ss is "z".

  • In the first operation, Keine chooses "z", and replaces it with "aa". ss becomes "aa".
  • In the second operation, Keine chooses "a", and replaces it with "ran". ss becomes "aran".
  • In the third operation, Keine chooses "a", and replaces it with "yakumo". ss becomes "yakumoran".

So the final string is "yakumoran", and t=[t=["z", "aa", "a", "ran", "a", "yakumo"]] before being shuffled.

Sample Cases

Case 1

Input

2
2
a
ab
b
cd
acd
3
z
a
a
aa
yakumo
ran
yakumoran

Output

a
z

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback