#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;


int main() {
	while (1) {
		vector<pair<int, int>>ps;
		ps.emplace_back(-1, 1000000007);
		int N; cin >> N;
		if (!N)break;
		for (int i = 0; i < N; ++i) {
			char c; cin >> c;
			if (c == 'W') {
				int a, b; cin >> a >> b;
				int rest = b;
				for (auto pt = ps.begin(); pt != ps.end(); ++pt) {
					if (pt->first == -1) {
						if (pt->second> rest) {
							pt->second -= rest;
							ps.insert(pt, make_pair(a, rest));
							break;
						}
						else if (pt->second == rest) {
							pt->first = a;
							break;
						}
						else {
							pt->first = a;
							rest -= pt->second;
						}
					}
					else {
						continue;
					}
				}
			}
			else if (c == 'D') {
				int b; cin >> b;
				for (auto pt = ps.begin(); pt != ps.end(); ++pt) {
					if (pt->first == b) {
						pt->first = -1;
					}
				}
			}
			else if(c=='R') {
				int b; cin >> b;
				int rest = b;
				for (auto&& pt = ps.cbegin(); pt != ps.cend(); ++pt) {
					if (pt->second > rest) {
						cout << pt->first << endl;
						break;
					}
					else {
						rest -= pt->second;
					}
				}

			}
		}
		
		cout << endl;
	}

	return 0;
}