#include <iostream>
#include <string>
#include <vector>
#include <cstring>
using namespace std;

char st[12];
class Node {
	int visited;
	int exits,deaths;
	int children;
	vector<Node *>links;
	string name;
public:
	Node() {children=visited=exits=deaths=0;}
	void Savename() {name=st;}
	void Printname() {cout<<name<<"\n";}
	friend void Makechildren(Node *currentnode);
	friend Node *Identicalcontrol();
	friend void Copysubtree(Node *lhs,Node *rhs);
	friend void Printoutput(Node *root);
	friend void Printexits(Node *currentnode);
	friend void Printdeaths(Node *currentnode);
};

vector<Node *> hist;

char Readname()
{
	char ch;
	int i=0;
	cin.get(ch);
	for(;;)
		switch(ch) 
	{
	case ' ' :
	case '\t':
	case '\n':if(!i)
			  {
				  if(ch=='\n')
				  {
					  st[0]=0;
					  return ch;
				  }
				  else
				  cin.get(ch);
			  }
				  else
				{
					  st[i]=0;
					  return ch;
				}
				  break;
	default:st[i++]=ch;
			cin.get(ch);
			break;
	}
}

Node *Identicalcontrol()
{
	int i;
	for(i=0;i<hist.size();i++)
		if(hist[i]->name==st)
			return hist[i];
		return NULL;
}

void Copysubtree(Node *lhs,Node *rhs)
{
	int i;
	rhs->visited=lhs->visited;
	rhs->exits=lhs->exits;
	rhs->deaths=lhs->deaths;
	rhs->children=lhs->children;
	rhs->name=lhs->name;
	rhs->links.resize(lhs->children);
	for(i=0;i<lhs->children;i++)
	{
		rhs->links[i]=new Node;
		Copysubtree(lhs->links[i],rhs->links[i]);
	}
}

void Makechildren(Node *currentnode)
{
	char ch;
	int sum=0,i;
	Node *temp;
	hist.resize(hist.size()+1);
	hist[hist.size()-1]=currentnode;
	
	currentnode->visited=1;
	if(currentnode->name=="wall")
		return;
	if(currentnode->name=="exit")
	{
		currentnode->exits=1;
		return;
	}
	if(currentnode->name=="death")
	{
		currentnode->deaths=1;
		return;
	}
	
	
	cout<<"into ";
	currentnode->Printname();
	do
	{
		ch=Readname();
		if(strlen(st))
		{
			currentnode->links.resize(++currentnode->children);
			temp=Identicalcontrol();
			if(!temp)
			{
				currentnode->links[currentnode->children-1]=new Node;
				currentnode->links[currentnode->children-1]->name=st;
			}
			else
			{
				currentnode->links[currentnode->children-1]=new Node;
				Copysubtree(temp,currentnode->links[currentnode->children-1]);
			}
		}
	}while(ch!='\n');

	for(i=0;i<currentnode->children;i++)
		if(!currentnode->links[i]->visited)
			Makechildren(currentnode->links[i]);
	
	for(i=0;i<currentnode->children;i++)
		sum+=currentnode->links[i]->exits;
	currentnode->exits=sum;
	sum=0;
	for(i=0;i<currentnode->children;i++)
		sum+=currentnode->links[i]->deaths;
	currentnode->deaths=sum;
}

void Printexits(Node *currentnode)
{
	Node *temp;
	int i,flag=1;
	temp=currentnode;
	while(flag)
	{
		flag=0;
		if(temp->name=="exit")
		cout<<temp->name;
		else
			cout<<temp->name<<" ";
		--temp->exits;
		for(i=0;i<temp->links.size();i++)
			if(temp->links[i]->exits)
			{
				flag=1;
				temp=temp->links[i];
				break;
			}
	}
	cout<<"\n";
}

void Printdeaths(Node *currentnode)
{
	Node * temp;
	int i,flag=1;
	temp=currentnode;
	while(flag)
	{
		flag=0;
		if(temp->name=="death")
		cout<<temp->name;
		else
			cout<<temp->name<<" ";
		--temp->deaths;
		for(i=0;i<temp->links.size();i++)
			if(temp->links[i]->deaths)
			{
				flag=1;
				temp=temp->links[i];
				break;
			}
	}
	cout<<"\n";
}

void Printoutput(Node *root)
{
	cout<<"freedom\n";
	while(root->exits)
	Printexits(root);
	cout<<"death\n";
	while(root->deaths)
	Printdeaths(root);
}

int main()
{
	Node root;
	char ch;
	cout<<"locate\n";
	ch=Readname();
	root.Savename();
	if(ch!='\n')
		Readname();
	Makechildren(&root);
	Printoutput(&root);
	return 0;
}
