#include <iostream>
#include <string>
#include <vector>
#include <time.h>

using namespace std;

main()
{
	int m, next, first, last;
	int f[26] = {0}, l[26] = {0};
	string s;
	vector<string> list[26], history;

	while( cin >> s ) {
		first = s[0] - 'a';
		last = s[s.length() - 1] - 'a';
		f[first]++;
		l[last]++;
		list[first].push_back(s);
	}

	srand(time(0));

	while ( true ) {
		next = rand() % 26;
		if ( f[next] != 0 && l[next] != 0 ) {
			break;
		}
	}

	while( true ) {
		m = list[next].size();
		s = list[next][rand() % m];
		last = s[s.length() - 1] - 'a';

		if( f[last] == 0 ) {
			continue;
		}

		history.push_back(s);
		cout << s << endl;
		next = last;

		if( next == history[0][0] - 'a' ) {
			break;
		}
	}
}

