logo AlgoBeat OnlineJudge
登录 注册

#216962. [ICPC 2017 Qingdao R] Suffix

内存限制:512 MiB 时间限制:1000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

Consider given non-empty strings denoted by . Now for each of them, you need to select a corresponding suffix, denoted by . For each string , the suffix is a non-empty substring whose right endpoint is the endpoint of the entire string. For instance, all suffixes of the string “jiangsu” are “u”, “su”, “gsu”, “ngsu”, “angsu”, “iangsu” and itself.

All selected suffixes could assemble into a long string . Here plus signs indicate additions of strings placing the latter at the tail of the former. Your selections of suffixes would determine the lexicographical order of . Now, your mission is to find the one with minimum lexicographical order.

Here is a hint about lexicographical order. To compare strings of different lengths, the shorter string is usually padded at the end with enough “blanks” which is a special symbol that is treated as smaller than every letters.

输入格式

The first line of input contains an integer which is the total number of test cases. For each case, the first line contains an positive integer . Each of the following lines contains a string entirely in lowercase, corresponding to . The summation of lengths of all strings in input is smaller or equal to 500000.

输出格式

For each test case, output the string with minimum lexicographical order.

样例

样例输入 1

3
3
bbb
aaa
ccc
3
aba
aab
bab
2
abababbaabbababba
abbabbabbbababbab

样例输出 1

baaac
aaabab
aab