#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <ctime>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <deque>
#include <complex>
#include <string>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <valarray>
#include <iterator>
using namespace std;
typedef long long int lli;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<pii, int> ppiii;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RREP(i,x) for(int i=(x);i>=0;i--)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) container.begin(), container.end()
#define SZ(container) ((int)container.size())

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;


int n;

int main(){
	int i,j;
	while(scanf("%d", &n), n){
		vector<ppiii> seg;
		priority_queue<pii, vector<pii>, greater<pii> > del;
		del.push(pii(0, 1000000000));
		int sorted = 1;
		REP(i, n){
			char c;
			int id, len;
			scanf(" %c%d", &c, &id);
//			cerr << c << ", " << id << endl;
			if(c == 'W'){
				scanf("%d", &len);
				while(len && !del.empty()){
					pii s = del.top();
					del.pop();
					int l = min(len, s.second);
					seg.push_back(ppiii(pii(s.first, l), id));
					sorted = 0;
					len -= l;
					s.second -= l;
					s.first  += l;
					if(s.second) del.push(s);
				}
			}else if(c == 'R'){
				if(seg.size() == 0) puts("-1");
				else{
					if(!sorted) sort(seg.begin(), seg.end());
					auto it = lower_bound(seg.begin(), seg.end(), ppiii(pii(id+1, 0), 0));
					if(it == seg.begin()) puts("-1");
					else{
						--it;
						if(it->first.first <= id && id < it->first.first + it->first.second) printf("%d\n", it->second);
						else puts("-1");
					}
				}
			}else if(c == 'D'){
				int t = 0;
				int s = 0;
				for(;s<seg.size();s++){
					if(seg[s].second == id){
						del.push(seg[s].first);
					}else{
						seg[t] = seg[s];
						t ++;
					}
				}
				seg.resize(t);
			}
		}
		puts("");
	}
	return 0;
}