#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll MOD = 1000000007;

const int INF = 1000000010;

struct Segment{
    int pos, size, id;
    Segment(int pos, int size, int id): pos(pos), size(size), id(id) {}
    bool operator<(const Segment& right ) const {
        return pos == right.pos ? size < right.size : pos < right.pos;
    }
};

int main(){
    while(true){
        int N;
        cin >> N;
        if(N == 0) break;

        set<Segment> empty;
        empty.emplace(0, INF, -1);
        set<Segment> occupied;
        
        for(int i=0;i<N;i++){
            char cmd;
            cin >> cmd;
            if(cmd == 'W'){
                int id, size;
                cin >> id >> size;
                while(true){
                    Segment u = *empty.begin();
                    empty.erase(empty.begin());
                    if(u.size < size){
                        size -= u.size;
                        u.id = id;
                        occupied.insert(u);
                    }else{
                        empty.emplace(u.pos + size, u.size - size, -1);                    
                        occupied.emplace(u.pos, size, id);
                        break;
                    }
                }
            }else if(cmd == 'D'){
                int id;
                cin >> id;
                for(auto it=occupied.begin();it!=occupied.end();){
                    if(it->id == id){
                        empty.insert(*it);
                        occupied.erase(it++);
                    }else{
                        it++;
                    }
                }
            }else{
                int pos;
                cin >> pos;
                auto it = occupied.lower_bound(Segment(pos, INF, INF));
                bool found = false;
                if(it != occupied.begin()){
                    auto prev = next(it, -1);
                    if(prev->pos <= pos && pos < prev->pos + prev->size){
                        cout << prev->id << endl;
                        found = true;
                    }
                }
                if(!found){
                    cout << -1 << endl;
                }
            }
        }
        cout << endl;
    }
    return 0;
}