#include <iostream>
using namespace std;

struct segment{
    segment *next, *file;
    int id, head, length;
};

segment S[20000];
segment *head, *blank;

void W(int I, int S){
    segment *p=head, *last=NULL;
    while(S){
        while(p->id!=-1) p=p->next;
        if(p->length>S){
            p->id=I;
            segment *b=blank++;
            b->next=p->next;
            p->next=b;
            b->head=p->head+S;
            b->length=p->length-S;
            p->length=S;
            S=0;
            if(last!=NULL)last->file=p;
        }else{
            p->id=I;
            S-=p->length;
            if(last!=NULL)last->file=p;
            last=p;
            p=p->next;
        }
    }
    return;
}

void D(int I){
    segment *p=head,*next;
    while(p->id!=I) p=p->next;
    while(p!=NULL){
        p->id=-1;
        next=p->file;
        p->file=NULL;
        p=next;
    }
    return;
}

void R(int P){
    segment *p=head;
    while(p!=NULL){
        if(p->head<=P && P<p->head+p->length){
            cout<<p->id<<endl;
            return;
        }else{
            p=p->next;
        }
    }
}

int main(){
    int N;
    while(cin>>N,N){
        for(int i=0;i<20000;i++){
            S[i].next=S[i].file=NULL;
            S[i].id=S[i].head=S[i].length=-1;
        }
        blank=&S[1];
        head=&S[0];
        head->id=-1;
        head->head=0;
        head->length=1000000001;
        for(int i=0;i<N;i++){
            char c;
            cin>>c;
            int I,S,P;
            switch(c){
                case 'W':
                    cin>>I>>S;
                    // cout<<'W'<<' '<<I<<' '<<S<<endl;
                    W(I,S);
                    break;
                case 'D':
                    cin>>I;
                    // cout<<'D'<<' '<<I<<endl;
                    D(I);
                    break;
                case 'R':
                    cin>>P;
                    // cout<<'R'<<' '<<P<<endl;
                    R(P);
                    break;
                default:
                    break;
            }
        }
        cout<<endl;
    }
    return 0;
}