import sys
#import numpy as np
import copy

fline = input().rstrip().split(' ')
N, Q = int(fline[0]), int(fline[1])

list = []
for i in range(N):
    tlist = []
    line = input().split(' ')
    tlist = [line[0], line[1]]
    #print(tlist)
    list.append(tlist)

#print(list)
current = 0
while len(list) != 0:
    if int(list[0][1]) <= Q:
        current += int(list[0][1])
        print(list[0][0] + " " + str(current))
        del list[0]
    else:
        list[0][1] = str((int)(list[0][1])-Q)
        list.append(list[0])
        del list[0]
        current += Q
    #print(list)
 import sys sys import copy copy fline = input().rstrip().split(' ') fline input().rstrip().split(' ') ().rstrip().split ().rstrip() ().rstrip () input rstrip split ' ' N, Q = int(fline[0]), int(fline[1]) N int(fline[0]) int fline[0] fline 0 Q int(fline[1]) int fline[1] fline 1 list = [] list [] for i in range(N):
    tlist = []
    line = input().split(' ')
    tlist = [line[0], line[1]]
    #print(tlist)
    list.append(tlist)

#print(list) i range(N) range N tlist = [] tlist [] line = input().split(' ') line input().split(' ') ().split () input split ' ' tlist = [line[0], line[1]] tlist [line[0], line[1]] line[0] line 0 line[1] line 1 list.append(tlist) list.append list append tlist current = 0 current 0 while len(list) != 0:
    if int(list[0][1]) <= Q:
        current += int(list[0][1])
        print(list[0][0] + " " + str(current))
        del list[0]
    else:
        list[0][1] = str((int)(list[0][1])-Q)
        list.append(list[0])
        del list[0]
        current += Q
    #print(list) len(list) != 0 len(list) len list 0 if int(list[0][1]) <= Q:
        current += int(list[0][1])
        print(list[0][0] + " " + str(current))
        del list[0]
    else:
        list[0][1] = str((int)(list[0][1])-Q)
        list.append(list[0])
        del list[0]
        current += Q
    #print(list) int(list[0][1]) <= Q int(list[0][1]) int list[0][1] [0] list 0 1 Q current += int(list[0][1]) current int(list[0][1]) int list[0][1] [0] list 0 1 print(list[0][0] + " " + str(current)) print list[0][0] + " " + str(current) list[0][0] + " " list[0][0] [0] list 0 0 " " str(current) str current del list[0] list[0] list 0 list[0][1] = str((int)(list[0][1])-Q) list[0][1] [0] list 0 1 str((int)(list[0][1])-Q) str (int)(list[0][1])-Q (int)(list[0][1]) int list[0][1] [0] list 0 1 Q list.append(list[0]) list.append list append list[0] list 0 del list[0] list[0] list 0 current += Q current Q fline = input().rstrip().split(' ') input().rstrip().split(' ') fline Q = int(fline[0]), int(fline[1]) int(fline[1]) Q current += int(list[0][1]) int(list[0][1]) current line = input().split(' ') input().split(' ') line list = [] [] list current = 0 0 current N, Q = int(fline[0]), int(fline[1]) int(fline[0]) N tlist = [] [] tlist tlist = [line[0], line[1]] [line[0], line[1]] tlist current += Q Q current
import sys
#import numpy as np
import copy

fline = input().rstrip().split(' ')
N, Q = int(fline[0]), int(fline[1])

list = []
for i in range(N):
    tlist = []
    line = input().split(' ')
    tlist = [line[0], line[1]]
    #print(tlist)
    list.append(tlist)

#print(list)
current = 0
while len(list) != 0:
    if int(list[0][1]) <= Q:
        current += int(list[0][1])
        print(list[0][0] + " " + str(current))
        del list[0]
    else:
        list[0][1] = str((int)(list[0][1])-Q)
        list.append(list[0])
        del list[0]
        current += Q
    #print(list)

