#include <iostream>
#include <cstdio>
#include <string>
#include <cassert>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;

#define rep(i, n)     reps(i, 0, n)
#define reps(i, f, n) for (int i = (f); i < (int)(n); ++i)

struct Data {
    int id;
    int len;
    Data(int id, int len) : id(id), len(len) {}
    Data(){}
};

vector<Data> hdd;
vector<int> deleted;

void W(int id, int s)
{
    rep(i, hdd.size()){
        if(deleted[hdd[i].id]){
            if(hdd[i].len <= s){
                s -= hdd[i].len;
                hdd[i].id = id;
            }
            else{
                int remain = hdd[i].len - s;
                hdd[i].id = id;
                hdd[i].len = s;
                hdd.insert(hdd.begin()+i+1, Data(0, remain));
                s = 0;
            }
        }
        if(s == 0)
            return;
    }
    //assert(1==0);
}

void D(int id)
{
    deleted[id] = 1;
}

int R(int p)
{
    int pos = 0;
    rep(i, hdd.size()){
        if(pos<=p && p<pos+hdd[i].len){
            return hdd[i].id;
        }
        pos += hdd[i].len;
    }
    //assert(0);
}

void dump()
{
    puts("===");
    rep(i, hdd.size()){
        printf("%d, len=%d\n", hdd[i].id, hdd[i].len);
    }
    puts("");
}

int main()
{
    int n;
    while(scanf("%d", &n), n){
        // initialize
        hdd.assign(1, Data(0, 1000000010));
        deleted.assign(n+1, 0);
        deleted[0] = 1;
        map<int, int> dict;
        vector<int> inv(n+1, -1);
        
        rep(i, n){
            char cmd[10];
            scanf("%s", cmd);
            if(cmd[0] == 'W'){
                int id, s;
                scanf("%d%d", &id, &s);
                
                int tmp = dict.size() + 1;
                dict[id] = tmp;
                inv[tmp] = id;
                W(tmp, s);
            }
            else{
                int id;
                scanf("%d", &id);
                if(cmd[0] == 'D')
                    D(dict[id]);
                else{
                    int ret = R(id);
                    if(deleted[ret])
                        puts("-1");
                    else
                        printf("%d\n", inv[ret]);
                }
            }
        }
        puts("");
    }
    return 0;
}