class IdFish
  def initialize(i,f)
    @id,@fish = i,f
  end
  attr_accessor :id,:fish
end

q = gets.split.last.to_i
a = Array.new
id1 = fish1 = 0

q.times do
  id,fish = gets.chomp.split.map(&:to_i)
  if i = a.index{|x| x.id == id}
    a[i].fish += fish
    if 0 < fish
      id1,fish1 = a[i].id,a[i].fish if fish1 < a[i].fish
      id1 = [id1,a[i].id].min if fish1 == a[i].fish
    else
      fish1 = a.sort_by!{|x| x.fish}.last.fish
      id1 = a[a.sort_by!{|x| x.id}.index{|x| x.fish == fish1}].id
    end
  else
    a << IdFish.new(id,fish)
    id1,fish1 = id,fish if fish1 < fish
    id1 = [id1,id].min if fish1 == fish
  end
  puts "#{id1} #{fish1}"
end 