//=================================
// Created on: 2018/07/04 12:38:03
//=================================
#include <bits/stdc++.h>
using namespace std;
int main()
{
    for (int N;;) {
        cin >> N;
        if (N == 0) { break; }
        using P = pair<int, int>;
        map<int, vector<P>> reg;
        set<P> empty;
        constexpr int INF = 1000000000;
        empty.insert({0, INF});
        auto sz = [](const P& p) { return p.second - p.first+1; };
        for (int i = 0; i < N; i++) {
            char c;
            cin >> c;
            if (c == 'W') {
                int l, s;
                cin >> l >> s;
                vector<P> rem;
                for (const auto& p : empty) {
                    if (sz(p) <= s) {
                        s -= sz(p), rem.push_back(p), reg[l].push_back(p);
                    } else {
                        rem.push_back(p), empty.insert({p.first + s, p.second}), reg[l].push_back({p.first, p.first + s - 1}), s = 0;
                    }
                    if (s == 0) { break; }
                }
                for (const auto& r : rem) { empty.erase(r); }
            } else if (c == 'D') {
                int l;
                cin >> l;
                for (const auto& r : reg[l]) { empty.insert(r); }
                reg.erase(l);
            } else {
                int P;
                cin >> P;
                bool found = false;
                for (const auto& vs : reg) {
                    if (found) { break; }
                    const int r = vs.first;
                    const auto& v = vs.second;
                    for (const auto& p : v) {
                        if (p.first <= P and P <= p.second) {
                            found = true, cout << r << endl;
                            break;
                        }
                    }
                }
                if (not found) { cout << -1 << endl; }
            }
        }
        cout << endl;
    }
    return 0;
}

