#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int INF = 1000000010;
#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define rep(i,n) REP(i, 0, n)
typedef pair<int, int> pint;
ifstream ifs("2152_input.txt");
ofstream ofs("op.txt");
void solve(int N){
    map<pint, int> disk;//disk[[l, r)] = id;
    char q; int t, w; bool accessed = false;
    rep(casenum, N){
        cin >> q >> t;
        if(q == 'W'){
            cin >> w;
            int crr = 0;
            accessed = true;
            for(const auto& k : disk){
                if(k.first.first - crr > 0){
                    int r = min(k.first.first, crr + w);
                    disk[pint(crr, r)] = t;
                    w -= r - crr;
                }
                crr = k.first.second;
                if(w <= 0) break;
            }
            if(w > 0) disk[pint(crr, crr + w)] = t;
        }else if(q == 'D'){
            auto it = disk.begin();
            while(it != disk.end()){
                if(it->second == t) disk.erase(it++);
                else it++;
            }
        }else{
            auto lb = disk.upper_bound(pint(t, INF));
            if(lb != disk.begin()) lb--;
            pint temp = lb->first;
            if(temp.first <= t && t < temp.second && accessed)
              cout << lb->second << endl;
            else
              cout << "-1" << endl;
        }
        
    }
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    while(cin >> n && n){
        solve(n);
        cout << endl;
    }
    return 0;
}