This problem is an adapted Mooshak version of a UVA Online Judge Problem.


[PC039] Rare Order

A collector of rare books recently discovered a book written in an unfamiliar language that uses the same set of characters as the English language. The book has a small index, but the order of the items in the index is different from what one would expect if the characters were arranged in the same way as in the English alphabet (composed of 26 letters). The collector tried to use the index to determine the order of the characters in the strange alphabet, but eventually gave up as the task proved frustrating and tedious.

The index consists of a set of words that we know are ordered in the "order we want to discover". For example, the index could be:

XWY
ZX
ZXY
ZXW
YWWX

This allows us to discover the relationships between letters. For example, since the word XWY comes before ZX, we know that in the language of the book, the letter 'X' comes before the letter 'Z'. We also know that the letter 'Y' comes after 'Z' because ZXW appears before YWWX. Finally, we know that the letter 'W' comes after 'Y' because the word ZXW comes after ZXY.

With all these considerations, we know that the correct order of letters in the "strange" language can only be XZYW.

The Problem

Your task is to write code to complete the collector's work. In particular, your code should receive a set of ordered words associated with a given "order" of letters and determine what that order is.

Input

The first line contains an integer \(N\) indicating the number of words to read. This is followed by \(N\) lines, each containing a word \(W_i\) consisting only of uppercase letters.

The lines are sorted in the order you want to discover.

Output

You should print a single line containing the capital letters in the order determined by the input. Only characters that appear in the input should appear in the output.

For the given test cases, it is guaranteed that there is one and only one order for which the input makes sense.

Constraints

The following limits are guaranteed in all the test cases that will be given to your program:

\(1 \leq N \leq 100\)       Number of words
\(1 \leq |W_i| \leq 10\)       Length of each word

Example Input Example Output
5
XWY
ZX
ZXY
ZXW
YWWX
XZYW


Competitive Programming (CC3032) 2025/2026
DCC/FCUP - University of Porto