#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
#define f first
#define s second
using namespace std;
typedef pair<int,int>P;
int main(){
  string st;
  vector<P>v;
  int n,x,y;
  while(cin>>n,n){
    v.clear();
    while(n--){
      cin>>st;
      if(st=="W"){
        cin>>x>>y;
        r(i,v.size()+1){
          if(i==v.size()){
            v.push_back(P(x,y));
            break;
          }
          else if(v[i].f==-1){
            if(v[i].s-y<0)v[i].f=x,y-=v[i].s;
            else{
              v[i].s-=y;
              v.insert(v.begin()+i,P(x,y));
              goto L;
            }
          }
        }
      }
      else if(st=="D"){
        cin>>x;
        r(i,v.size())if(v[i].f==x)v[i].f=-1;
      }
      else{
        int p=0,fl=0;
        cin>>x;x++;
        r(i,v.size()){
          if(p<=x&&x<=p+v[i].s){
            cout<<v[i].f<<endl;
            fl++;
            break;
          }
          p+=v[i].s;
        }
        if(!fl)cout<<-1<<endl;
      }L:;
    }
    cout<<endl;
  }
}