#include <iostream>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;

struct Section {
    int contents;
    ll start,end;
    Section(int s,int e,int c) : start(s), end(e), contents(c) {;}

    ll size() { return end - start + 1; }
};

class Disk {
private:
    int _size;
    vector<Section> sv;

public:
    Disk () {
        sv.clear();
        sv.push_back(Section(0,1000000000ll,-1));
    }

    typedef vector<Section>::iterator itr;

    int getSize() { return _size; }

    void write(ll file_id,ll size) {
        for(itr it = sv.begin(); it != sv.end(); ++it) {
            if(it->contents == -1) {
                it->contents = file_id;
                if(it->size() > size) {
                    ll e = it->end;
                    it->end = it->start + size -1;
                    ll nexts = (it->end)+1;
                    it++;
                    sv.insert(it, 1, Section( nexts, e, -1));
                    break;
                }else{
                    size -= it->size();
                }
            }
        }
    }

    void dump() {
        for(itr it = sv.begin(); it != sv.end(); ++it) {
            cout<<"from "<<it->start<<" to "<<it->end<<" : file_id "<<it->contents<<endl;
        }
    }

    void delete_file(ll file_id) {
        for(itr it = sv.begin(); it != sv.end(); ++it) {
            if(it->contents == file_id) {
                it->contents = -1;
            }
        }
        return;
    }

    int reference(ll ptr) {
        for(itr it = sv.begin(); it != sv.end(); ++it) {
            if(it->start <= ptr && it->end >= ptr) return it->contents;
        }
        return -1;
    }
};

int main() {
    int N;
    ll rs,rt;
    string op;
    while(cin>>N, N) {
        Disk disk;
        for(int i=0; i<N; ++i) {
            cin>>op;
            if(op == "W") {
                cin>>rs>>rt;
                disk.write(rs,rt);
            }else if(op == "D") {
                cin>>rs;
                disk.delete_file(rs);
            }else{
                cin>>rs;
                cout<<disk.reference(rs)<<endl;
            }
        }
        cout<<endl;
    }
}