#include <bits/stdc++.h>
using namespace std;

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define abs(a) max((a),-(a))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repe(i,n) rep(i,(n)+1)
#define per(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define pere(i,n) rep(i,(n)+1)
#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define RET return 0
#define MOD 1000000007
#define INF 1000000000000000000

typedef long long LL;
typedef long double LD;

int main(){
  while(1){
    int n;
    cin >> n;
    if(n==0) return 0;
    char c;
    int x,s;
    map<int,pair<int,int>> mp;
    map<int,bool> us;
    int now;
    for(int t=0;t<n;t++){
      cin >> c;
      if(c=='W'){
        cin >> x >> s;
        us[x]=true;
        now=0;
        while(1){
          auto itr=mp.lower_bound(now);
          if(itr==mp.end()){
            mp[now]={now+s,x};
            break;
          }else{
            if(now+s<=itr->first){
              mp[now]={now+s,x};
              break;
            }else{
              if(now<itr->first){
                mp[now]={itr->first,x};
                s-=itr->first-now;
              }
              if(!us[itr->second.second]){
                now=itr->first;
                if(now+s<=itr->second.first){
                  mp[now]={now+s,x};
                  break;
                }else{
                  mp[now]={itr->second.first,x};
                  s-=itr->second.first-now;
                }
              }
              now=itr->second.first;
            }
          }
          if(s==0) break;
        }
      }else if(c=='D'){
        cin >> x;
        us[x]=false;
      }else{
        cin >> x;
        auto itr=mp.upper_bound(x);
        if(itr==mp.begin()){
          cout << -1 << endl;
        }else{
          itr--;
          if(itr->second.first<=x){
            cout << -1 << endl;
          }else{
            if(us[itr->second.second]) cout << itr->second.second << endl;
            else cout << -1 << endl;
          }
        }
      }
    }
    cout << endl;
  }
  return 0;
}

