#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define L 1000000001

static int d[ L ];

int
main (
  int   argc,
  char *argv[ ]
  )
{
  int i;

  for ( ; ; )
  {
    int n;

    scanf ( " %d", &n );
    if ( n == 0 ) break ;
    memset ( d, -1, sizeof ( d ) );

    while ( n-- )
    {
      char cmd;

      scanf ( " %c", &cmd );
      switch ( cmd )
      {
        case 'W':
        {
          int l, s;

          scanf ( " %d %d", &l, &s );
          for ( i = 0; s > 0; ++i )
          {
            if ( d[ i ] != -1 ) continue ;
            d[ i ] = l; --s;
          }
        } break ;
        case 'D':
        {
          int l;

          scanf ( " %d", &l );
          for ( i = 0; i < L; ++i )
          if ( d[ i ] == l )
            d[ i ] = -1;
        } break ;
        case 'R':
        {
          int p;

          scanf ( " %d", &p );
          printf ( "%d\n", d[ p ] );
        } break ;
      }
    }
    puts ( "" );
  }

  return ( EXIT_SUCCESS );
}