s = raw_input().split()
n = int(s[0])
q = int(s[1])

process_name = []
process_time = []
for x in xrange(n):
  ps = raw_input().split()
  process_name.append(ps[0])
  process_time.append(int(ps[1]))

total_time = 0
while process_name != []:
  pn = process_name.pop(0)
  pt = process_time.pop(0)
  if pt <= q:
    total_time += pt
    print pn, total_time
  else: 
    total_time += q
    process_name.append(pn)
    process_time.append(pt-q) s = raw_input().split() s raw_input().split() ().split () raw_input split n = int(s[0]) n int(s[0]) int s[0] s 0 q = int(s[1]) q int(s[1]) int s[1] s 1 process_name = [] process_name [] process_time = [] process_time [] for x in xrange(n):
  ps = raw_input().split()
  process_name.append(ps[0])
  process_time.append(int(ps[1])) x xrange(n) xrange n ps = raw_input().split() ps raw_input().split() ().split () raw_input split process_name.append(ps[0]) process_name.append process_name append ps[0] ps 0 process_time.append(int(ps[1])) process_time.append process_time append int(ps[1]) int ps[1] ps 1 total_time = 0 total_time 0 while process_name != []:
  pn = process_name.pop(0)
  pt = process_time.pop(0)
  if pt <= q:
    total_time += pt
    print pn, total_time
  else: 
    total_time += q
    process_name.append(pn)
    process_time.append(pt-q) process_name != [] process_name [] pn = process_name.pop(0) pn process_name.pop(0) process_name.pop process_name pop 0 pt = process_time.pop(0) pt process_time.pop(0) process_time.pop process_time pop 0 if pt <= q:
    total_time += pt
    print pn, total_time
  else: 
    total_time += q
    process_name.append(pn)
    process_time.append(pt-q) pt <= q pt q total_time += pt total_time pt print pn total_time total_time += q total_time q process_name.append(pn) process_name.append process_name append pn process_time.append(pt-q) process_time.append process_time append pt-q pt q q = int(s[1]) int(s[1]) q process_name = [] [] process_name s = raw_input().split() raw_input().split() s total_time += pt pt total_time total_time = 0 0 total_time pt = process_time.pop(0) process_time.pop(0) pt pn = process_name.pop(0) process_name.pop(0) pn n = int(s[0]) int(s[0]) n ps = raw_input().split() raw_input().split() ps process_time = [] [] process_time total_time += q q total_time
s = raw_input().split()
n = int(s[0])
q = int(s[1])

process_name = []
process_time = []
for x in xrange(n):
  ps = raw_input().split()
  process_name.append(ps[0])
  process_time.append(int(ps[1]))

total_time = 0
while process_name != []:
  pn = process_name.pop(0)
  pt = process_time.pop(0)
  if pt <= q:
    total_time += pt
    print pn, total_time
  else: 
    total_time += q
    process_name.append(pn)
    process_time.append(pt-q)