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
mid = mfish = 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
      mid,mfish = a[i].id,a[i].fish if mfish < a[i].fish
      mid = [mid,a[i].id].min if mfish == a[i].fish
    else
      mfish = a.sort_by{|x| x.fish}.last.fish
      mid = a.select{|x| x.fish==mfish}.sort_by!{|x| x.id}.first.id
    end
  else
    a << IdFish.new(id,fish)
    mid,mfish = id,fish if mfish < fish
    mid = [mid,id].min if mfish == fish
  end
  puts "#{mid} #{mfish}"
end 