n, q = map(int, input().split())
l = []
for i in range(n):
  t = []
  for j in input().split():
    t += [j]
  t[1] = int(t[1])
  l += [t]

c = 0
while len(l) > 0:
  if l[0][1] > q:
    l[0][1] -= q
    l += [l[0]]
    l.pop(0)
    c += q
  else:
    c += l[0][1]
    print(l[0][0], c)
    l.pop(0) n, q = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split q l = [] l [] for i in range(n):
  t = []
  for j in input().split():
    t += [j]
  t[1] = int(t[1])
  l += [t] i range(n) range n t = [] t [] for j in input().split():
    t += [j]
   j input().split() ().split () input split t += [j] t [j] j t[1] = int(t[1]) t[1] t 1 int(t[1]) int t[1] t 1 l += [t] l [t] t c = 0 c 0 while len(l) > 0:
  if l[0][1] > q:
    l[0][1] -= q
    l += [l[0]]
    l.pop(0)
    c += q
  else:
    c += l[0][1]
    print(l[0][0], c)
    l.pop(0) len(l) > 0 len(l) len l 0 if l[0][1] > q:
    l[0][1] -= q
    l += [l[0]]
    l.pop(0)
    c += q
  else:
    c += l[0][1]
    print(l[0][0], c)
    l.pop(0) l[0][1] > q l[0][1] [0] l 0 1 q l[0][1] -= q l[0][1] [0] l 0 1 q l += [l[0]] l [l[0]] l[0] l 0 l.pop(0) l.pop l pop 0 c += q c q c += l[0][1] c l[0][1] [0] l 0 1 print(l[0][0], c) print l[0][0] [0] l 0 0 c l.pop(0) l.pop l pop 0 l += [l[0]] [l[0]] l q = map(int, input().split()) map(int, input().split()) q l = [] [] l t = [] [] t l += [t] [t] l c = 0 0 c n, q = map(int, input().split()) map(int, input().split()) n c += l[0][1] l[0][1] c c += q q c t += [j] [j] t
n, q = map(int, input().split())
l = []
for i in range(n):
  t = []
  for j in input().split():
    t += [j]
  t[1] = int(t[1])
  l += [t]

c = 0
while len(l) > 0:
  if l[0][1] > q:
    l[0][1] -= q
    l += [l[0]]
    l.pop(0)
    c += q
  else:
    c += l[0][1]
    print(l[0][0], c)
    l.pop(0)
