#include <bits/stdc++.h>
using namespace std;

#define for_(i,a,b) for(int i=a;i<b;++i)
#define size_of(a) (int)a.size()

typedef pair< int, int > Seg;

int N, n;
map< int, int > ftoi, itof;
vector< Seg > segs, fseg[10010];

void _write_() {
	int l, S; cin >> l >> S;
	ftoi[l] = n;
	itof[n] = l;
	
	vector< Seg > new_segs;	
	
	for_(i,0,size_of(segs)) {
		if (S) {
			int w = segs[i].second - segs[i].first;
		
			if (w <= S) {
				S -= w;
				fseg[n].push_back(segs[i]);
			} else {
				fseg[n].push_back(Seg(segs[i].first, segs[i].first + S));
				new_segs.push_back(Seg(segs[i].first + S, segs[i].second));
				S = 0;
			}
		} else {
			new_segs.push_back(segs[i]);
		}
	}
	
	segs = new_segs;
	
	++n;
}

void _delete_() {
	int l; cin >> l;
	int f = ftoi[l];
	
	for_(i,0,size_of(fseg[f])) segs.push_back(fseg[f][i]);
	
	fseg[f].clear();
	
	sort(segs.begin(), segs.end());
	
	int s = segs[0].first, t = segs[0].second;
	vector< Seg > new_segs;
	
	for_(i,1,size_of(segs)) {
		if (segs[i].first == t) {
			t = segs[i].second;
		} else {
			new_segs.push_back(Seg(s, t));
			s = segs[i].first;
			t = segs[i].second;
		}
	}
	new_segs.push_back(Seg(s, t));
	
	segs = new_segs;
}

void _read_() {
	int p; cin >> p;
	
	for_(i,0,n) {
		for_(j,0,size_of(fseg[i])) {
			if (fseg[i][j].first <= p && p < fseg[i][j].second) {
				cout << itof[i] << endl;
				return;
			}
		}
	}
	
	cout << -1 << endl;
}

int main() {	
	while (cin >> N, N) {
		n = 0;
		ftoi.clear();
		itof.clear();
		
		segs.clear();
		segs.push_back(Seg(0, (int)1e9 + 1));
		
		for_(i,0,N) fseg[i].clear();
		
		for_(i,0,N) {
			char c; cin >> c;
			switch (c) {
			case 'W':
				_write_();
				break;
			case 'D':
				_delete_();
				break;
			case 'R':
				_read_();
				break;
			}
		}
		
		cout << endl;
	}
	
	return 0;
}