class Array
	def bsearch_last_index(l = 0, r = size - 1, &pred)
		return nil if l > r
		c = (l + r) / 2 
		if pred[self[c]]
			bsearch_last_index(c+1, r, &pred) || c
		else
			bsearch_last_index(l, c-1, &pred)
		end
	end

	def bsearch_last_item(l = 0, r = size - 1, &pred)
		i = bsearch_last_index(l, r, &pred)
		i ? self[i] : nil
	end
end

loop do
	n = gets.to_i
	break if n == 0
	
	segments = { -1 => [[0, Float::INFINITY]] }	

	n.times do
		command, i, s = gets.chomp.split
		i = i.to_i

		if command == "W"
			s = s.to_i
			next if s <= 0
			
			seg = []
			loop do
				emp = segments[-1].shift
				start, len = emp
				if s < len
					emp[0] += s
					emp[1] -= s
					seg << [start, s]
					segments[-1].unshift emp
					break
				else 
					s -= len
					seg << emp
				end
			end
			segments[i] = seg

		elsif command == "D"
			merged = []
			e_segs = segments[-1]
			d_segs = segments[i]

			loop do
				if e_segs.empty? || d_segs.empty?
					merged += d_segs + e_segs
					break
				end

				target = nil
				if e_segs[0][0] < d_segs[0][0]
					target = e_segs.shift	
				else
					target = d_segs.shift	
				end

				if !merged.empty? && merged[-1][0] + merged[-1][1] == target[0]
					merged[-1][1] += target[1]
				else
					merged << target
				end
			end
			
			segments[-1] = merged
			segments.delete(i)

		else
			segments.each do |k, arr|
				start, len = arr.bsearch_last_item {|start, len| start <= i}
				if start && i < start + len
					puts k
					break
				end
			end
		end
	end

	puts
end