q = gets.split.map(&:to_i)[1]
h = []
n = []
idx = {}
hsize = 0
q.times{|i|
  a, v = gets.split.map(&:to_i)
  if i = idx[a]
    h[i] += v
    if v > 0
      p = (i+1)/2-1
      while i > 0 &&
          (h[p] < h[i] || h[p] == h[i] && n[p] > n[i])
        idx[n[p]] = i
        idx[n[i]] = p
        h[i], h[p] = h[p], h[i]
        n[i], n[p] = n[p], n[i]
        i = p
        p = (i+1)/2-1
      end
    else
      max = i
      l = 2 * i + 1
      max = l if l < hsize && (h[max] < h[l] || h[max] == h[l] && n[max] > n[l])
      r = 2 * i + 2
      max = r if r < hsize && (h[max] < h[r] || h[max] == h[r] && n[max] > n[r])
      while max != i
        idx[n[max]] = i
        idx[n[i]] = max
        h[i], h[max] = h[max], h[i]
        n[i], n[max] = n[max], n[i]
        i = max
        l = 2 * i + 1
        max = l if l < hsize && h[max] < h[l][1]
        r = 2 * i + 2
        max = r if r < hsize && h[max] < h[r][1]
      end
    end
  else
    h[hsize] = v
    n[hsize] = a
    idx[a] = hsize
    if hsize > 0
      j = hsize
      p = (j+1)/2-1
      while j > 0 && (h[p] < h[j] || h[p] == h[j] && n[p] > n[j])
        idx[n[p]] = j
        idx[n[j]] = p
        h[j], h[p] = h[p], h[j]
        n[j], n[p] = n[p], n[j]
        j = p
        p = (j+1)/2-1
      end
    end
    hsize += 1
  end
  puts "#{n[0]} #{h[0]}"
}