#include <cstdlib>
#include <iostream>
#include <vector>

class Tab {
	private:
		int *tab;
	public:
		bool fin;
		Tab(void) { 
			tab= new int[2];
		};
		Tab(const Tab& t) {
			tab= new int[2];
			tab[0]= t[0];
			tab[1]= t[1];
			fin= t.fin;
		}
		~Tab(void) { 
			delete [] tab;
		};
		int operator [](int k) const {
			return tab[k];
		};
		int& operator [](int k) {
			return tab[k];
		};
};

bool equiv(int n, int p, int q, std::vector<Tab>& f)
{
	if ( n==0 )
		return f[p].fin==f[q].fin;
	else
		return f[p].fin==f[q].fin
				&& equiv(n-1, f[p][0], f[q][0], f) 
				&& equiv(n-1, f[p][1], f[q][1], f);
}

int main(int argc, char *argv[])
{
	std::vector<Tab> f;
	while ( std::cin.peek()!='\n' ) {
		Tab t;
		std::cin >> t[0] >> t[1];
		t.fin= false;
		while (std::cin.peek()!='\n') {
			int c= std::cin.get();
			if (c!=' ' )
				t.fin= true;
		}
		std::cin.get();
		f.push_back(t);	
	}

	for (auto& t : f)
		std::cout<< t[0]<< '\t'<< t[1]<< (t.fin? "*" : "") << std::endl;

	std::vector<int> E;
	for (int p=0; p<f.size(); ++p)
		E.push_back(p);

	for (int p=0; p<f.size(); ++p) {
		if (E[p]==p)
			for (int q=p+1; q<f.size(); ++q)
				if (equiv(f.size(), p, q, f))
					E[q]= E[p];
	}
	
	std::cout << "-------\n";
	for (int p=0; p<f.size(); ++p)
		if (E[p]==p)
		std::cout<< E[p] << ":\t" <<E[f[p][0]]<< '\t'<< E[f[p][1]]
					<< (f[p].fin? "*" : "") << std::endl;

	return EXIT_SUCCESS;
}

