1.

/**
* ACM Training 2009
* ACM Problem #200 - Rare Order
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=4&page=show_problem&problem=136
*
* @author Dennis Wilfert
* @version 1.0, 11/03/2009
*
* Methode: Topologische Sortierung
* Status : Accepted
* Runtime: 0.124
*/

import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.LinkedList;

class Main {

public static void main(String[] args) throws IOException {

BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
PrintWriter writer = new PrintWriter(new BufferedOutputStream(System.out));

LinkedList<Character> l = new LinkedList<Character>();

boolean[] exists = new boolean[26];

char[][] chr = new char[10000][];
int line = 0;
int length = 1;
int maxlength = 0;
int index, j, i;
while (true) {

chr[line] = reader.readLine().toCharArray();
if (maxlength < chr[line].length) {
maxlength = chr[line].length;
}

if (chr[line][0] == '#') {
break;
}

line++;

}
for (i = 0; i < line; i++) {

if (!exists[chr[i][0] - 65]) {
l.addLast(chr[i][0]);
exists[chr[i][0] - 65] = true;
}
}

while (length < maxlength) {
for (i = 0; i < line - 1; i++) {
if (length == chr[i].length - 1 && length == chr[i + 1].length - 1) {
j = 0;
while (chr[i][j] == chr[i + 1][j])
j++;

if (j == length) {
if (exists[chr[i][j] - 65] && !exists[chr[i + 1][j] - 65]) {
index = l.indexOf(chr[i][j]);
l.add(index + 1, chr[i + 1][j]);
exists[chr[i + 1][j] - 65] = true;
}
if (!exists[chr[i][j] - 65] && exists[chr[i + 1][j] - 65]) {
index = l.indexOf(chr[i + 1][j]);
l.add(index, chr[i][j]);
exists[chr[i][j] - 65] = true;
}
}

}
}
length++;
}

for (char c : l) {
writer.print(c);
}
writer.println();
writer.flush();

}
}