/***************
Problem from :ds
Problem describe :
链表实现
data:
****************/
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<map>
#include<stack>
#include<queue>
#include<ctime>
#include<cstring>
#include<vector>
#include<string>
#define ll __int64
#define inf 0x3f3f3f3f3f
using namespace std;
struct node{
int val;
node *next;
};
/*void print(node *head)
{
while(head)
{
cout << head->val <<endl;
head = head->next;
}
return ;
} */
int main()
{
node *head, *end, *p;
int len=0, n, m, i, j, k;
char cmd[8];
scanf("%d %d", &n, &m);
head=NULL;
end =NULL;
for(i=0; i<n; i++)
{
node *temp = new node;
scanf("%d", &temp->val) ;
if(!i)
{
head = temp;
if(i==n-1)
{
end = temp;
temp->next=NULL;
}
}
else if(i==n-1)
{
end = temp;
temp->next = NULL;
p->next = temp;
}
else p->next = temp;
p = temp;
}
//print(head);
int a, b;
len = n;
while(m--)
{
scanf("%s", cmd);
cin >> a;
if(cmd[0]=='a')
{
len++;
node *temp = new node;
temp->val = a;
if(head==NULL) //原队列为空
{
head = temp;
end = temp;
temp->next = NULL;
}
else
{
end->next = temp;
temp->next = NULL;
end = temp;
}
}
else if(cmd[0]=='d')
{
len--;
if(head==NULL) continue;
int k=0;
node *p=head;
while(p)
{
if(a==0) break;
if(k==a-1) break;
p = p->next;
k++;
}
if(p==head&&a==0)
{
head = p->next;
}
else if(p->next==end)
{
p->next=NULL;
end=p;
}
else
{
p->next = p->next->next;
}
}
else if(cmd[0]=='c')
{
scanf("%d", &b);
node *q=head;
k=0;
while(q)
{
if(k==a) break;
q=q->next;
k++;
}
q->val=b;
}
else if(cmd[0]=='q')
{
node *q=head;
k=0;
while(q)
{
if(k==a) break;
q=q->next;
k++;
}
printf("%d\n", q->val);
}
//print(head);
}
return 0;
}