import std.stdio;
import std.ascii;
import std.c.stdio;
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;

struct S {
    int from, to;
    int id;
    int size() { return to - from; }
}

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

void main() {
    int N;
    while (scanf("%d\n", &N), N > 0) {
        int id, size;
        auto buf = new char[16];
        S[] D = [ S(0, M, -1) ];
        foreach (i; 0 .. N) {
            scanf("%s %d", buf.ptr, &id);
            switch (buf[0]) {
                case 'W': 
                    scanf("%d", &size);
                    while (size > 0) {
                        auto index = countUntil!"a.id == -1"(D);
                        S* p = &D[index];
                        if (p.size > size) {
                            p.from += size;
                            D.insertInPlace(index, S(p.from - size, p.from, id));
                            size = 0;
                        } else {
                            p.id = id;
                            size -= p.size;
                        }
                    }
                    break;
                case 'R':
                    foreach (ref d; D) {
                        if (d.from <= id && id < d.to) {
                            writeln(d.id);
                            break;
                        }
                    }
                    break;
                case 'D':
                    foreach (ref d; D) {
                        if (d.id == id) d.id = -1;
                    }
                    break;
                default: assert(0);
            }
            //writeln(D);
        }
        writeln;
    }
}