#16D8101014F 久留米 竜之介 Kurume Ryunosuke Python
All = 0
q = []
Queue = []
tmp,time = map(int,input().split())
for i in range(tmp):
    p,zi =input().split()
    q.append([p,int(zi)])
while len(q) > 0:
    if q[0][1]<= time:
        All+=q[0][1]
        v=q.pop(0)
        Queue.append([v[0],All])
    else:
        All+=time
        q[0][1]-=time
        last=q.pop(0)
        q.append(last)
for i in range(len(Queue)):
    print("{0} {1}".format(Queue[i][0],Queue[i][1])) All = 0 All 0 q = [] q [] Queue = [] Queue [] tmp,time = map(int,input().split()) tmp map(int,input().split()) map int input().split() ().split () input split time for i in range(tmp):
    p,zi =input().split()
    q.append([p,int(zi)]) i range(tmp) range tmp p,zi =input().split() p input().split() ().split () input split zi q.append([p,int(zi)]) q.append q append [p,int(zi)] p int(zi) int zi while len(q) > 0:
    if q[0][1]<= time:
        All+=q[0][1]
        v=q.pop(0)
        Queue.append([v[0],All])
    else:
        All+=time
        q[0][1]-=time
        last=q.pop(0)
        q.append(last) len(q) > 0 len(q) len q 0 if q[0][1]<= time:
        All+=q[0][1]
        v=q.pop(0)
        Queue.append([v[0],All])
    else:
        All+=time
        q[0][1]-=time
        last=q.pop(0)
        q.append(last) q[0][1]<= time q[0][1] [0] q 0 1 time All+=q[0][1] All q[0][1] [0] q 0 1 v=q.pop(0) v q.pop(0) q.pop q pop 0 Queue.append([v[0],All]) Queue.append Queue append [v[0],All] v[0] v 0 All All+=time All time q[0][1]-=time q[0][1] [0] q 0 1 time last=q.pop(0) last q.pop(0) q.pop q pop 0 q.append(last) q.append q append last for i in range(len(Queue)):
    print("{0} {1}".format(Queue[i][0],Queue[i][1])) i range(len(Queue)) range len(Queue) len Queue print("{0} {1}".format(Queue[i][0],Queue[i][1])) print "{0} {1}".format(Queue[i][0],Queue[i][1]) "{0} {1}".format "{0} {1}" format Queue[i][0] [i] Queue i 0 Queue[i][1] [i] Queue i 1 All+=q[0][1] q[0][1] All time = map(int,input().split()) map(int,input().split()) time last=q.pop(0) q.pop(0) last p,zi =input().split() input().split() p zi =input().split() input().split() zi Queue = [] [] Queue q = [] [] q v=q.pop(0) q.pop(0) v All = 0 0 All tmp,time = map(int,input().split()) map(int,input().split()) tmp All+=time time All
#16D8101014F 久留米 竜之介 Kurume Ryunosuke Python
All = 0
q = []
Queue = []
tmp,time = map(int,input().split())
for i in range(tmp):
    p,zi =input().split()
    q.append([p,int(zi)])
while len(q) > 0:
    if q[0][1]<= time:
        All+=q[0][1]
        v=q.pop(0)
        Queue.append([v[0],All])
    else:
        All+=time
        q[0][1]-=time
        last=q.pop(0)
        q.append(last)
for i in range(len(Queue)):
    print("{0} {1}".format(Queue[i][0],Queue[i][1]))
