signedmain(){ ios; int n,m,K; cin>>n>>m; K = sqrt(n); deque<int> deq[n/K+(m/K)+10]; for(int i=0;i<n;i++){ int temp;cin>>temp; deq[i/K].push_back(temp); } for(int i=0;i<m;i++){ string a;cin>>a; if(a[0]=='A'){ int x,y;cin>>y>>x;y--; deq[y/K].insert(deq[y/K].begin()+(y%K), x); int len = deq[y/K].size(),cur = y/K; while(len>K){ int temp = deq[cur].back(); deq[cur].pop_back(); cur++; deq[cur].push_front(temp); len = deq[cur].size(); } } elseif(a[0]=='L'){ int x;cin>>x;x--; deq[x/K].erase(deq[x/K].begin()+(x%K)); int len = deq[x/K].size(),cur = x/K; while(len<K && deq[cur+1].size()!=0){ int temp = deq[cur+1].front(); deq[cur+1].pop_front(); deq[cur].push_back(temp); cur++; len = deq[cur].size(); } } elseif(a[0]=='Q'){ int x;cin>>x;x--; int len = x%K; auto it = deq[x/K].begin(); cout<<*(it+len)<<endl; } } }