import std.stdio;
import std.ascii;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.regex;
import std.typecons;
import std.random;

class S {
    int from, to;
    int id;
    int size() { return to - from; }
    this(int from, int to, int id) {
        this.from = from;
        this.to = to;
        this.id = id;
    }
    override string toString() const {
        return format("S(%s,%s,%s)", from, to, id);
    }
}

const M = cast(int)1e9 + 1;

void main() {
    int N;
    while (scanf("%d\n", &N), N > 0) {
        //stderr.writeln(t);
        int id, size;
        auto buf = new char[16];
        auto init = new S(0, M, -1);
        auto D = [init];
        BinaryHeap!(Array!S, "a.from > b.from") PQ;
        PQ.insert(init);
        foreach (i; 0 .. N) {
            scanf("%s %d", buf.ptr, &id);
            switch (buf[0]) {
                case 'W': 
                    scanf("%d", &size);
                    while (size > 0) {
                        auto s = PQ.front; PQ.removeFront;
                        if (s.size > size) {
                            s.from += size;
                            D ~= new S(s.from - size, s.from, id);
                            PQ.insert(s);
                            size = 0;
                        } else {
                            s.id = id;
                            size -= s.size;
                        }
                    }
                    break;
                case 'R':
                    foreach (ref d; D) {
                        if (d.from <= id && id < d.to) {
                            writeln(d.id);
                            break;
                        }
                    }
                    break;
                case 'D':
                    foreach (d; D) {
                        if (d.id == id) {
                            d.id = -1;
                            PQ.insert(d);
                        }
                    }
                    break;
                default: assert(0);
            }
            //writeln(D);
        }
        writeln;
    }
}