#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
#define D10 fixed<<setprecision(10)
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1000000007;
const int INF = MOD + 1;
const ld EPS = 1e-12;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

/*--------------------template--------------------*/

int main()
{
	int n;
	while (cin >> n, n)
	{
		set<pii> empty({ {0,INF} });
		map<int, vector<pii>> mp;
		REP(i, n)
		{
			char c; cin >> c;
			if (c == 'W')
			{
				int a, b; cin >> a >> b;
				vector<pii> v;
				vector<pii> era;
				for (auto it = empty.begin(); b > 0; it++)
				{
					if (it->second - it->first > b)
					{
						v.emplace_back(it->first, it->first + b);
						era.push_back(*it);
						empty.insert(pii(it->first + b, it->second));
						b = 0;
					}
					else
					{
						v.emplace_back(*it);
						b -= it->second - it->first;
						era.push_back(*it);
					}
				}
				REP(i, era.size()) empty.erase(era[i]);
				mp[a] = v;
			}
			else if (c == 'D')
			{
				int a; cin >> a;
				vector<pii> v = mp[a];
				mp.erase(a);
				REP(i, v.size()) empty.insert(v[i]);
			}
			else
			{
				int a; cin >> a;
				int res;
				for (auto j : empty)
				{
					if (a >= j.first&&a < j.second)
					{
						res = -1;
						goto end;
					}
				}
				for (auto j : mp)
				{
					vector<pii> tmp = j.second;
					REP(k, tmp.size())
					{
						if (a >= tmp[k].first&&a < tmp[k].second)
						{
							res = j.first;
							break;
						}
					}
				}

			end:;
				cout << res << endl;
			}
		}
		cout << endl;
	}
	return 0;
}