#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<functional>
using namespace std;
#define REP(i, a, n) for(int i=a; i<n; i++)

vector<pair<int, int>> vp; // identifier, size

int main()
{
	int N;
	while (cin >> N, N) {
		vp.clear();
		vp.push_back(make_pair(-1, 1000000001));

		char com;
		REP(i, 0, N) {
			cin >> com;

			if (com == 'W') {
				int l, s;
				cin >> l >> s;

				for (auto itr = vp.begin(); itr != vp.end(); itr++){
					if (itr->first == -1) {
						if (itr->second >= s) {
							itr->second -= s;
							vp.insert(itr, make_pair(l, s));
							break;
						}
						else {
							itr->first = l;
							s -= itr->second;
						}
					}
				}
			}

			else if (com == 'D') {
				int l;
				cin >> l;

				for (auto itr = vp.begin(); itr != vp.end(); itr++){
					if (itr->first == l) itr->first = -1;
				}
			}

			else {
				int p;
				cin >> p;

				for (auto itr = vp.begin(); itr != vp.end(); itr++) {
					if (itr->second > p) {
						cout << itr->first << endl;
						break;
					}
					p -= itr->second;
				}
			}
		}

		cout << endl;
	}
	return 0;
}