#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define INF 1000000010
#define EPS 1e-10
#define MOD 1000000007
using namespace std;
typedef pair<int,int> P;
typedef pair<P,int> PP;

int n;
vector<PP> v;

void solve(){
	v.clear();
	rep(i,n){
		char x; cin >> x;
		if(x == 'D'){
			int l; cin >> l;
			rep(j,v.size()) if(v[j].second == l){
				v[j].first.first = INF;
			}
			sort(v.begin(),v.end());
			while(true){
				if(v.size() == 0) break;
				if(v[v.size()-1].first.first != INF) break;
				v.pop_back();
			}
		} else if(x == 'R'){
			int p; cin >> p;
			bool ok = false;
			rep(j,v.size()){
				if(v[j].first.first <= p && p <= v[j].first.second){
					cout << v[j].second << endl;
					ok = true;
					break;
				}
			}
			if(!ok) puts("-1");
		} else{
			int l, s; cin >> s >> l;
			int st = 0;
			int V = v.size();
			rep(j,V){
				if(v[j].first.first > st){
					if(l <= v[j].first.first-st){
						v.push_back(PP(P(st,st+l-1),s));
						l = 0;
						break;
					} else{
						v.push_back(PP(P(st,v[j].first.first-1),s));
						l -= v[j].first.first-st;
					}
				}
				st = v[j].first.second+1;
				if(st > INF){
					l = 0;
					break;
				}
			}
			if(l > 0) v.push_back(PP(P(st,st+l-1),s));
			sort(v.begin(),v.end());
		}
	}
	cout << endl;
}

int main(){
	while(true){
		cin >> n;
		if(n == 0) break;
		solve();
	}
}