#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

bool less_than(string x, string y) {
	sort(x.begin(), x.end());
	sort(y.begin(), y.end());
	return x < y;
}

bool is_anagram(string x, string y) {
	if (x != y) {
		sort(x.begin(), x.end());
		sort(y.begin(), y.end());
		return x == y;
	}
	return false;
}

int main() {
	vector<string> voc;	// словарь (можно использовать массив с запасом)
	string word; 		// очередное слово
	while (cin >> word) voc.push_back(word); // читаем и запоминаем слово
	sort(voc.begin(), voc.end(), less_than); // по использованию букв
	bool found = false;
	cout << "Anagrams list:";
	for (auto i = voc.begin(); i != voc.end() - 1; i++) {
		if (is_anagram(*i, *(i + 1))) {
			if (!found) cout << endl << *i << " ";
			cout << *(i + 1) << " ";
			found = true;
		} else found = false;
	}
}