#include <bits/stdc++.h>
using namespace std;

int main() {
	int n;
	queue <string> alumnos, trabajadores;
	string accion, nombre, tipo;
	
	cin >> n;
	for(int i=1;i<n;i++){
		cin >> accion >> tipo;
		if(accion=="LLEGA" && tipo=="ALUMNO"){
			cin >> nombre;
			alumnos.push(nombre);
		}
		else if(accion=="LLEGA" && tipo=="TRABAJADOR"){
			cin >> nombre;
			trabajadores.push(nombre);
		}
		else if(accion=="ATIENDE"){
			while(!trabajadores.empty()){
				cout << trabajadores.front();
				trabajadores.pop();
			}
			cout << alumnos.front();
			alumnos.pop();
		}
	}
return 0;
}
