#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <cmath>
#include <algorithm>
#include <functional>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep1(i,n) for(int i=1;i<=(n);++i)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl;
typedef pair<int,int> P;
int n;
vector<P> vc;
int main(){
	while(true){
		cin>>n;
		if(n==0) break;
		vc.clear();
		rep(i,n){
			char t;
			cin>>t;
			if(t=='W'){
				int id,x;
				cin>>id>>x;
				rep(k,vc.size()){
					if(vc[k].fs==-1){
						if(x<vc[k].sc){
							vc[k].sc-=x;
							vc.insert(vc.begin()+k,P(id,x));
							x=0;
						}else{
							vc[k].fs=id;
							x-=vc[k].sc;
						}
					}
					if(x==0) break;
				}
				if(x>0){
					vc.pb(P(id,x));
				}
			}else if(t=='D'){
				int id;
				cin>>id;
				rep(k,vc.size()){
					if(vc[k].fs==id) vc[k].fs=-1;
				}
			}else{
				int x;
				cin>>x;
				int now=0;
				bool done=false;
				rep(k,vc.size()){
					now+=vc[k].sc;
					if(x<now){
						cout<<vc[k].fs<<endl;
						done=true;
						break;
					}
				}
				if(!done){
					puts("-1");
				}
			}
		}
		cout<<endl;
	}
}