#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <sstream>
#include <list>

using namespace std;

typedef pair<long long int, long long int> P;
typedef pair<P, long long int> elem;

int main(){
	
	long long int N;
	
	while(true){
		
		cin >> N;
		if(N == 0){
			break;
		}
		
		list<elem> lst;
		elem e;
		e.first.first = 1500000000;
		e.first.second = 1;
		e.second = 1500000000;
		
		lst.push_back(e);
		
		for(int loop = 0; loop < N; loop++){
			
			char c;
			cin >> c;
			list<elem>::iterator itr = lst.begin();
			
			if(c == 'W'){
				long long int num, count;
				cin >> num >> count;
				long long int pos = 0;
				while(true){
					elem e_cur = *itr;
					if(e_cur.first.first > pos){
						elem e1;
						e1.first.first = pos;
						e1.first.second = min(count, e_cur.first.first- pos);
						e1.second = num;
						lst.insert(itr, e1);
						count -= e_cur.first.first - pos;
						if(count <= 0){
							break;
						}
					}
					pos = e_cur.first.first + e_cur.first.second;
					++itr;
				}
			}else if(c == 'D'){
				long long int num;
				cin >> num;
				while(itr != lst.end()){
					if(((elem)*itr).second == num){
						itr = lst.erase(itr);
					}else{
						++itr;
					}
				}
			}else{
				long long int pos;
				cin >> pos;
				long long int ans = -1;
				while(itr != lst.end()){
					elem e_cur = *itr;
					if(e_cur.first.first + e_cur.first.second > pos){
						if(e_cur.first.first <= pos){
							ans = e_cur.second;
						}
						break;
					}
					itr++;
				}
				cout << ans << endl;
			}
		}
		/*
		for(list<elem>::iterator itr = lst.begin(); itr != lst.end(); itr++){
			elem e = *itr;
			cout << e.first.first << " " << e.first.second << " " << e.second << endl;
		}
		*/
		cout << endl;
	}
	return 0;
}