import java.util.*;
class SNode {
public String data;
int next;
SNode(int i,String u){next=i;data=u;}
};
class StaticList {
SNode List[];
int length,maxlen;
StaticList(int n,String u)
{
length=0;
maxlen=n;
List=new SNode[n];
for(int i=0;i<n;i++)
{
List[i]=new SNode(i+1,u);
}
List[0].next=2;
List[1].next=0;
List[n-1].next=0;
}
void DestroyList()
{
length = 0;
}
void ClearList()
{
length=0;
for(int i=0;i<maxlen;i++)
{
List[i].next=i+1;
}
List[0].next=2;
List[1].next=0;
List[maxlen-1].next=0;
}
boolean ListEmpty()
{
return (length == 0);
}
int ListLength()
{
return length;
}
String GetElem(int p)
{
int i=List[1].next,po;
if(p<1||i==0||p>length+1)
return null;
else
{
po=1;
while(p>1)
{
po=List[po].next;
p--;
}
p=List[po].next;
return List[p].data;
}
}
int LocateElem(String e)
{
int i=List[1].next,po;
if(i==0)
return 0;
else
{
po=1;
while(po!=0)
{
po=List[po].next;
if(e.compareTo(List[po].data)==0)
return po;
}
}
return 0;
}
boolean Insert(int p,String e)
{
int i=List[0].next,po;
if(i==0||p>length+1)
return false;
else
{
po=1;
while(p>1)
{
po=List[po].next;
p--;
}
List[i].data=e;
List[0].next=List[i].next;
List[i].next=List[po].next;
List[po].next=i;
length++;
return true;
}
}
String Delete(int p)
{
int i=List[1].next,po;
if(p<1||i==0||p>length+1)
return null;
else
{
po=1;
while(p>1)
{
po=List[po].next;
p--;
}
p=List[po].next;
List[po].next=List[p].next;
List[p].next=List[0].next;
List[0].next=p;
length--;
return List[po].data;
}
}
void ShowFrom()
{
for(int i=0;i<maxlen;i++)
{
System.out.printf("%-8S%2d\n",List[i].data,List[i].next);
}
}
};
public class Main
{
public static void main(String[] args)
{
Scanner cin = new Scanner(System.in);
String t;
int n;
StaticList L=new StaticList(11,"");
while(cin.hasNext())
{
t=cin.next();
if(t.charAt(2)=='s')
{
n=cin.nextInt();
t=cin.next();
L.Insert(n, t);
}
else if(t.charAt(2)=='l')
{
n=cin.nextInt();
L.Delete(n);
}
else if(t.charAt(2)=='a')
{
t=cin.next();
System.out.printf("%2d\n",L.LocateElem(t));
System.out.println("********************");
}
else
{
L.ShowFrom();
System.out.println("********************");
}
}
cin.close();
}
}
/**************************************************************
Problem: 2139
User: admin
Language: Java
Result: Accepted
Time:1079 ms
Memory:40620 kb
****************************************************************/