#include <bits/stdc++.h>
typedef long long LL;
#define SORT(c) sort((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

using namespace std;
int main(void)
{
  for(;;){
    int n;
    cin >> n;
    if(!n) return 0;
    set<tuple<int,int,int> >f;
    //r,l,id
    map<int,vector<tuple<int,int,int> > > pos;
    REP(i,n){
      string c;
      cin >> c;
      if(c=="W"){
	int id,se;
	cin >> id >> se;
	int tmp=0;
	for(;;){
	  auto ite=(f.lower_bound(make_tuple(tmp+1,0,0)));
	  if(ite==f.end()){
	    auto ma=make_tuple(tmp+se,tmp,id);
	    f.insert(ma);
	    pos[id].push_back(ma);
	    break;
	  }
	  int sup,suc;
	  tie(suc,sup,ignore)=*ite;
	  if(tmp<sup){
	    if(tmp+se<=sup){
	      auto ma=make_tuple(tmp+se,tmp,id);
	      f.insert(ma);
	      pos[id].push_back(ma);
	      break;
	    }else{
	      auto ma=make_tuple(sup,tmp,id);
	      f.insert(ma);
	      pos[id].push_back(ma);
	      se-=sup-tmp;
	    }
	  }
	  tmp=suc;
	}
      }else if(c=="D"){
	int id;
	cin >> id;
	for(auto x:pos[id]) f.erase(x);
	pos[id].clear();
      }else if(c=="R"){
	int p;
	cin >> p;
	auto x=f.lower_bound(make_tuple(p+1,0,0));
	if(x==f.end()){
	  cout << -1 << endl;
	}else{
	  int l,id;
	  tie(ignore,l,id)=*x;
	  if(l<=p) cout << id << endl;
	  else cout << -1 << endl;
	}
      }
    }
    cout << endl;
  }
}