# include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N= 10000015 , mod= 1e9 + 7 ;
template < typename T >
void Debug ( T x, string s) {
cout<< s<< ": " << x<< endl;
}
struct node
{
int val, p_cnt;
int next, last;
} a[ N] ;
# define PII pair< int , int >
# define PB push_back
int vis[ N] , vis_p[ N] ;
struct linklist
{
int head= 1 , tail= 1 , sz= 0 , mid= tail;
void insertl ( int tot) { sz++ ;
if ( sz== 1 ) {
head= tail= tot; vis_p[ tot] = 0 ;
a[ tot] . last= - 1 ; a[ tot] . next= - 1 ;
mid= tail;
}
else {
a[ tot] . next= head;
a[ tot] . last= - 1 ;
a[ head] . last= tot;
vis_p[ tot] = vis_p[ head] - 1 ;
head= tot;
if ( sz% 2 == 1 ) {
movel ( ) ;
}
else {
mid= mid;
}
}
}
void insertr ( int tot) {
sz++ ;
if ( sz== 1 ) {
head= tail= tot; vis_p[ tot] = 0 ;
a[ tot] . last= - 1 ; a[ tot] . next= - 1 ;
mid= tot;
}
else {
a[ tot] . last= tail;
a[ tot] . next= - 1 ;
a[ tail] . next= tot;
vis_p[ tot] = vis_p[ tail] + 1 ;
tail= tot;
if ( sz% 2 == 0 ) {
mover ( ) ;
}
else mid= mid;
}
}
void del ( int tot) {
int tl= a[ tot] . last, tr= a[ tot] . next;
if ( tr!= - 1 )
a[ tl] . next= tr;
if ( tl!= - 1 )
a[ tr] . last= tl;
if ( tot== head) {
head= a[ head] . next;
}
if ( tot== tail) {
tail= a[ tail] . last;
}
if ( vis_p[ mid] > vis_p[ tot] ) {
if ( sz% 2 == 1 ) mover ( ) ;
else mid= mid;
}
else if ( vis_p[ mid] < vis_p[ tot] ) {
if ( sz% 2 == 0 ) movel ( ) ;
else mid= mid;
}
else if ( mid== tot) {
if ( sz% 2 == 0 ) movel ( ) ;
else mover ( ) ;
}
sz-- ;
a[ tot] . last= a[ tot] . next= - 1 ;
}
void movel ( ) {
mid= a[ mid] . last;
}
void mover ( ) {
mid= a[ mid] . next;
}
} List;
int tot= 0 ;
void solve ( )
{
int posl= 0 , posr= 0 ; a[ 0 ] . last= a[ 0 ] . next= - 1 ;
int q; scanf ( "%d " , & q) ; char c;
for ( int i= 1 ; i<= q; i++ ) {
scanf ( "%c " , & c) ;
if ( c== 'L' ) { ++ tot;
List. insertl ( tot) ;
}
else if ( c== 'R' ) { ++ tot;
List. insertr ( tot) ;
}
else if ( c== 'G' ) {
int x; scanf ( "%d " , & x) ;
List. del ( x) ;
}
else {
printf ( "%d\n" , List. mid) ;
}
}
}
int main ( )
{
# ifndef ONLINE_JUDGE
freopen ( "b.txt" , "r" , stdin ) ;
freopen ( "bout.txt" , "w" , stdout ) ;
# endif
int t;
t= 1 ;
while ( t-- )
solve ( ) ;
}