#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#define assert(cond, message) {\
if (!(cond)) {\
		fprintf(stderr,"(Line %d): Error: %s\n",__LINE__,(message));\
		return -77;\
	}\
}

#define inpfile "windows.in"
#define outfile "windows.out"

#define run_string "Run "
#define alt_string "Alt"
#define tab_string "+Tab"

#define NMAX 1000
#define LENMAX 100

char s[1000];
int n,k;
int pos[NMAX];
char * name[NMAX];

//  check whether pre is str prefix
int isprefix (const char * str, const char * pre) {
	int len = strlen(pre);
	if (strlen(str)<len) return 0;
	int i;
	for (i=0;i<len;i++) {
		if (str[i]!=pre[i]) return 0;
	}
	return 1;
}

void qsort(char ** a, int le, int ri) {
	int i = le, j = ri;
	char *t, *x = a[(i+j)/2];
	do {
		while (strcmp(a[i],x)<0) i++;
		while (strcmp(x,a[j])<0) j--;
		if (i<=j) {
			t = a[i];
            a[i] = a[j];
			a[j] = t;
			i++;j--;		
		}
	} while (i<=j);

	if (i<ri) qsort(a,i,ri);
	if (le<j) qsort(a,le,j);
}

int main() {
	freopen(inpfile,"r",stdin);
	freopen(outfile,"w",stdout);

	int i,j,len,r;
   	assert(fgets(s,1000,stdin),"cannot read first line");
   	assert(strlen(s)<500,"too long line")
	assert(1==sscanf(s,"%d",&n),"cannot read integer N");
	assert(n>0,"N<=0");
	assert(n<=NMAX,"N>NMAX");

	k = 0;
    for (i=0;i<n;i++) {
    	assert(fgets(s,1000,stdin),"cannot read next line with command");
		len = strlen(s);
		assert(len<500,"too long line");
		if ('\n'==s[len-1]) s[--len] = 0;

		if (isprefix(s,run_string)) {
//			assert(len-strlen(run_string)<=LENMAX,"length of command name more than 100 symbols");		    
		    name[k] = (char*)malloc(len+1-strlen(run_string));
		    strcpy(name[k],s+strlen(run_string));
		    for (j = 0; j < strlen(name[k]); j++) {
//		    	assert((name[k][j] >= 'a' && name[k][j] <= 'z') || (name[k][j] >= 'A' && name[k][j] <= 'Z') ||
//		    		(name[k][j] >= '0' && name[k][j] <= '9') || (name[k][j] == ' '), "invalid application name");
		    }
		    pos[k] = k;
		    printf("%s\n",name[k]);
		    k++;
		} else if (isprefix(s,alt_string)) {
			assert(k>0,"alt befor run");
			j = strlen(alt_string);
			while (j<len) {
				assert(isprefix(s+j,tab_string),"unknown key after 'Alt'");
				j+=strlen(tab_string);
				assert(j<=strlen(alt_string)+100*strlen(tab_string),"more than 100 '+Tab'");
			}
			assert(j==len,"excess symbols in 'Alt' line");
			j = (j-strlen(alt_string)) / strlen(tab_string);
			j = j % k;
			for (r=0;r<k;r++) 
				if (pos[r]==k-j-1) {
					pos[r] = k-1;
					printf("%s\n",name[r]);
				}
				else if (pos[r]>k-j-1) pos[r]--;
		} else {			
			assert(0,s);
		}       	 	
    }

	qsort(name,0,k-1);
	for (i=0;i<k-1;i++) 
		assert(strcmp(name[i],name[i+1]),"equal program names");

    for (i=0;i<k;i++) free(name[i]);

	return 0;	
}

