n,q=map(int,input().split())
#print(n,p)
round_robin=[]
for i in range(n):
    x=input().split()
    name=x[0]
    t=int(x[1])
    round_robin.append([name,t])
#print(round_robin)
finished=[]
counter=0
while round_robin:
    left_time=round_robin[0][1]
    if left_time<=q:
        counter+=left_time
        finished.append([round_robin[0][0],counter])
        del round_robin[0]
    else:
        counter+=q
        left_time-=q
        round_robin[0]=[round_robin[0][0],left_time]
        round_robin.append(round_robin.pop(0))

for i in finished:
    print(*i) n,q=map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split q round_robin=[] round_robin [] for i in range(n):
    x=input().split()
    name=x[0]
    t=int(x[1])
    round_robin.append([name,t])
#print(round_robin) i range(n) range n x=input().split() x input().split() ().split () input split name=x[0] name x[0] x 0 t=int(x[1]) t int(x[1]) int x[1] x 1 round_robin.append([name,t]) round_robin.append round_robin append [name,t] name t finished=[] finished [] counter=0 counter 0 while round_robin:
    left_time=round_robin[0][1]
    if left_time<=q:
        counter+=left_time
        finished.append([round_robin[0][0],counter])
        del round_robin[0]
    else:
        counter+=q
        left_time-=q
        round_robin[0]=[round_robin[0][0],left_time]
        round_robin.append(round_robin.pop(0)) round_robin left_time=round_robin[0][1] left_time round_robin[0][1] [0] round_robin 0 1 if left_time<=q:
        counter+=left_time
        finished.append([round_robin[0][0],counter])
        del round_robin[0]
    else:
        counter+=q
        left_time-=q
        round_robin[0]=[round_robin[0][0],left_time]
        round_robin.append(round_robin.pop(0)) left_time<=q left_time q counter+=left_time counter left_time finished.append([round_robin[0][0],counter]) finished.append finished append [round_robin[0][0],counter] round_robin[0][0] [0] round_robin 0 0 counter del round_robin[0] round_robin[0] round_robin 0 counter+=q counter q left_time-=q left_time q round_robin[0]=[round_robin[0][0],left_time] round_robin[0] round_robin 0 [round_robin[0][0],left_time] round_robin[0][0] [0] round_robin 0 0 left_time round_robin.append(round_robin.pop(0)) round_robin.append round_robin append round_robin.pop(0) round_robin.pop round_robin pop 0 for i in finished:
    print(*i) i finished print(*i) print *i i round_robin=[] [] round_robin q=map(int,input().split()) map(int,input().split()) q left_time-=q q left_time counter+=left_time left_time counter counter=0 0 counter counter+=q q counter finished=[] [] finished x=input().split() input().split() x name=x[0] x[0] name n,q=map(int,input().split()) map(int,input().split()) n t=int(x[1]) int(x[1]) t left_time=round_robin[0][1] round_robin[0][1] left_time
n,q=map(int,input().split())
#print(n,p)
round_robin=[]
for i in range(n):
    x=input().split()
    name=x[0]
    t=int(x[1])
    round_robin.append([name,t])
#print(round_robin)
finished=[]
counter=0
while round_robin:
    left_time=round_robin[0][1]
    if left_time<=q:
        counter+=left_time
        finished.append([round_robin[0][0],counter])
        del round_robin[0]
    else:
        counter+=q
        left_time-=q
        round_robin[0]=[round_robin[0][0],left_time]
        round_robin.append(round_robin.pop(0))

for i in finished:
    print(*i)