#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, a, b) for (int i = (a); i < ((int)(b)); ++i)
#define rrep(i, a, b) for (int i = (int)(b) - 1; i >= ((int)(a)); --i)
#define all(c) c.begin(), c.end()
#define sz(c) ((int)c.size())
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;

void dump_impl(string s) {}
template <class H, class... T>
void dump_impl(string s, H head, T... tail) {
    int p = 0;
    rep(i, 0, sz(s)) {
        char x = s[i];
        if (x == ',' && p == 0) {
            cerr << " = " << head << ", ";
            dump_impl(s.substr(i + 1), tail...);
            return;
        } else {
            cerr << x;
            if (x == '(') p++;
            if (x == ')') p--;
        }
    }
}
// #define dump(...) do { cerr << "\x1b[33;1m"; dump_impl(#__VA_ARGS__ ",", __VA_ARGS__); cerr << "\x1b[0m" << endl; } while (0)
#define dump(...)

const int INF = 1001001001001001001LL;

void solve(int N) {
    set<tuple<int, int, int>> range_u, range_a;
    range_a.insert(make_tuple(0, INF, -1));

    rep(i, 0, N) {
        char com;
        cin >> com;
        if (com == 'W') {
            int qf, size;
            cin >> qf >> size;

            set<tuple<int, int, int>> memo;
            for (auto &ra : range_a) {
                int l, r, f;
                tie(l, r, f) = ra;

                int len = r - l;
                if (f == -1) {
                    if (len <= size) {
                        size -= len;
                        range_u.insert(make_tuple(l, r, qf));
                        memo.insert(ra);
                    } else {
                        range_u.insert(make_tuple(l, l + size, qf));
                        range_a.insert(make_tuple(l + size, r, -1));
                        range_a.erase(ra);
                        size = 0;
                    }
                    if (size == 0) {
                        break;
                    }
                }
            }
            for (auto tpl : memo) {
                range_a.erase(tpl);
            }
        } else if (com == 'D') {
            int qf;
            cin >> qf;
            set<tuple<int, int, int>> memo;
            for (auto &ra : range_u) {
                int l, r, f;
                tie(l, r, f) = ra;
                if (f == qf) {
                    range_a.insert(make_tuple(l, r, -1));
                    memo.insert(ra);
                }
            }
            for (auto tpl : memo) {
                range_u.erase(tpl);
            }
        } else {
            int sec;
            cin >> sec;
            for (auto ra : range_a) {
                int l, r, f;
                tie(l, r, f) = ra;
                if (l <= sec && sec < r) {
                    dump(l, r, f);
                    cout << f << endl;
                    break;
                }
            }
            for (auto ra : range_u) {
                int l, r, f;
                tie(l, r, f) = ra;
                if (l <= sec && sec < r) {
                    dump(l, r, f);
                    cout << f << endl;
                    break;
                }
            }
            // cerr << "----" << endl;
        }

        // cerr << "range_a" << endl;
        // for (auto ra : range_a) {
        //     int l, r, f;
        //     tie(l, r, f) = ra;
        //     dump(l, r, f);
        // }
        // cerr << "range_u" << endl;
        // for (auto ra : range_u) {
        //     int l, r, f;
        //     tie(l, r, f) = ra;
        //     dump(l, r, f);
        // }
        // cerr << "==========" << endl;
    }
    cout << endl;
}

signed main() {
    int N;
    while (cin >> N, N) {
        solve(N);
    }
}


Measured memory_bytes: 3752