#include <bits/stdc++.h>
using namespace std;
int INF = 1000000001;
int main(){
  while (1){
    int N;
    cin >> N;
    if (N == 0){
      break;
    }
    vector<pair<int, int>> L;
    L.push_back(make_pair(-1, INF));
    for (int i = 0; i < N; i++){
      char c;
      cin >> c;
      if (c == 'W'){
        int l, S;
        cin >> l >> S;
        vector<pair<int, int>> L2;
        for (auto R : L){
          if (R.first == -1){
            if (S >= R.second){
              L2.push_back(make_pair(l, R.second));
              S -= R.second;
            } else if (S > 0){
              L2.push_back(make_pair(l, S));
              L2.push_back(make_pair(-1, R.second - S));
              S = 0;
            } else {
              L2.push_back(R);
            }
          } else {
            L2.push_back(R);
          }
        }
        swap(L, L2);
      }
      if (c == 'D'){
        int l;
        cin >> l;
        vector<pair<int, int>> L2;
        for (auto R : L){
          if (R.first == l){
            L2.push_back(make_pair(-1, R.second));
          } else {
            L2.push_back(R);
          }
        }
        swap(L, L2);
      }
      if (c == 'R'){
        int P;
        cin >> P;
        for (auto R : L){
          if (P >= R.second){
            P -= R.second;
          } else {
            cout << R.first << endl;
            break;
          }
        }
      }
    }
    cout << endl;
  }
}
