#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<29;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};


int main(){
	while(1){
		int n;
		map<ll,ll> mp;
		scanf("%d",&n);
		if(n==0) break;
		list<pll> lt;
		for(int i=0;i<n;i++){
			char c;
			cin>>c;
			if(c=='W'){
				int x,y;
				scanf("%d%d",&x,&y);
				auto it=lt.begin();
				mp[x]=y;
				while(it!=lt.end()){
					if(it->first==-1){
						int t=it->second;
						if(y>=t){
							it->first=x;
							y-=t;
						}
						else{
							it=lt.insert(it,make_pair(x,y));
							it++;
							it->second=t-y;
							y=0;
						}
					}
					if(y==0) break;
					it++;
				}
				if(y) lt.push_back(make_pair(x,y));
			}
			if(c=='D'){
				auto it=lt.begin();
				int x;
				scanf("%d",&x);
				int t=mp[x];
				while(it!=lt.end()){
					if(it->first==x){
						it->first=-1;
						t-=it->second;
						if(t==0) break;
					}
					it++;
				}
			}
			if(c=='R'){
				int x;
				scanf("%d",&x);
				auto it=lt.begin();
				bool B=0;
				while(it!=lt.end()){
					int t=it->second,y=it->first;
					if(t<=x) x-=t;
					else{
						printf("%d\n",y);
						B=1;
						break;
					}
					it++;
				}
				if(!B) printf("-1\n");
			}
		}
		printf("\n");
	}
}
