def min_heapify(x = 1)
  l = 2*x
  r = 2*x+1
  if l <= $n && $heap[l][0] < $heap[x][0]
    minimum = l
  else
    minimum = x
  end
  if r <= $n && $heap[r][0] < $heap[minimum][0]
    minimum = r
  end
  if minimum != x
    $heap[x], $heap[minimum] = $heap[minimum], $heap[x]
    min_heapify(minimum)
  end
end

def extract(x)
  key = $heap[x]
  $heap[x] = $heap[$n]
  $n -= 1
  min_heapify
  key
end

def insert(key)
  $n += 1
  $heap[$n] = key
   i = $n
  while i > 1 && $heap[i/2][0] > $heap[i][0]
    $heap[i], $heap[i/2] = $heap[i/2], $heap[i]
    i /= 2
  end
end

def find(sec)
  (1..$n).each do |x|
    top, size, _ = $heap[x]
    return x if top <= sec && sec - top < size
  end
end

while n = gets.to_i
  break if n == 0
  $n = 0
  $heap = []
  insert([0, 1000000001, -1])
  table = {}
  n.times do
    l = gets.split
    cmd = l.shift
    case cmd
    when "W"
      x, s = l.map(&:to_i)
      pos = 1
      table[x] = []
      while s > 0
        if $heap[pos][2] == -1
          top, size, _ = extract(pos)
          if size > s
            insert([top, s, x])
            insert([top + s, size - s, -1])
          else
            insert([top, size, x])
          end
          table[x] << top
          s -= size
        end
        pos += 1
      end
    when "D"
      x = l[0].to_i
      table[x].each do |top|
        top, size, id = extract(find(top))
        insert([top, size, -1])
      end
      table[x] = []
    when "R"
      sec = l[0].to_i
      p $heap[find(sec)][2]
    end
  end
  puts
end