#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)
#define SQ(x) ((x)*(x))
#define Mod(x, mod) (((x)+(mod)%(mod))
#define MP make_pair
#define PB push_back
#define Fi first
#define Se second
#define INF (1<<29)
#define EPS 1e-10
#define MOD 1000000007

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;


// [a,b)の区間ごとにデータを保持する -1:=そこにデータはない
struct FileSystem{
  list<pair<pair<int, int>, int> >se;
  list<pair<pair<int, int>, int> >::iterator it, insertit;
  FileSystem(){
    se.push_back(make_pair(make_pair(0, 1000000005), -1));
  }
  void write(int id, int size){
    it = se.begin();
    while(it != se.end() && size > 0){
      if(it->second == -1){
	int sectorSize = it->first.second-it->first.first;
	if(sectorSize < size){
	  it->second = id;
	  size -= sectorSize;
	}else{
	  insertit = it; insertit++;
	  if(sectorSize > size) se.insert(insertit,make_pair(make_pair(it->first.first+size, it->first.second), -1));
	  it->second = id;
	  it->first.second = it->first.first + size;
	  size = 0;
	}
      }
      it++;
    }
  }
  void erase(int id){
    it = se.begin();
    while(it != se.end()){
      if(it->second == id) it->second = -1;
      it++;
    }
  }
  int ref(int adress){
    it = se.begin();
    while(it != se.end()){
      if(it->first.first <= adress && adress < it->first.second) return it->second;
      it++;
    }
    return -1;
  }
};

int main(){
  int N;
  while(scanf("%d",&N) && N){
    FileSystem fs;
    rep(i,N){
      char cmd[2];
      scanf("%s", cmd);
      if(cmd[0]=='W'){
	int l,s; scanf("%d%d",&l,&s);
	fs.write(l,s);
      }else if(cmd[0]=='D'){
	int l; scanf("%d",&l);
	fs.erase(l);
      }else if(cmd[0]=='R'){
	int p; scanf("%d", &p);
	printf("%d\n", fs.ref(p));
      }
    }
    puts("");
  }
  return 0;
}