s=input()
d=s.split()
n=int(d[0])
q=int(d[1])
end_t=0
processes=[]
for i in range(n):
    processes.append([])
    s=input()
    d=s.split()
    processes[i].append(d[0])
    processes[i].append(int(d[1]))

cnt=0
i=0
while True:
    if processes[0][1]<=q:
       end_t+=processes[0][1]
       print(processes[0][0],end_t)
       processes.pop(0)
       cnt+=1
       if cnt==n:
           break
   
    else:
       processes[0][1]-=q
       end_t+=q
       processes.append(processes[0])
       processes.pop(0)
       i+=1
 s=input() s input() input d=s.split() d s.split() s.split s split n=int(d[0]) n int(d[0]) int d[0] d 0 q=int(d[1]) q int(d[1]) int d[1] d 1 end_t=0 end_t 0 processes=[] processes [] for i in range(n):
    processes.append([])
    s=input()
    d=s.split()
    processes[i].append(d[0])
    processes[i].append(int(d[1])) i range(n) range n processes.append([]) processes.append processes append [] s=input() s input() input d=s.split() d s.split() s.split s split processes[i].append(d[0]) [i].append [i] processes i append d[0] d 0 processes[i].append(int(d[1])) [i].append [i] processes i append int(d[1]) int d[1] d 1 cnt=0 cnt 0 i=0 i 0 while True:
    if processes[0][1]<=q:
       end_t+=processes[0][1]
       print(processes[0][0],end_t)
       processes.pop(0)
       cnt+=1
       if cnt==n:
           break
   
    else:
       processes[0][1]-=q
       end_t+=q
       processes.append(processes[0])
       processes.pop(0)
       i+=1 True if processes[0][1]<=q:
       end_t+=processes[0][1]
       print(processes[0][0],end_t)
       processes.pop(0)
       cnt+=1
       if cnt==n:
           break
   
    else:
       processes[0][1]-=q
       end_t+=q
       processes.append(processes[0])
       processes.pop(0)
       i+=1 processes[0][1]<=q processes[0][1] [0] processes 0 1 q end_t+=processes[0][1] end_t processes[0][1] [0] processes 0 1 print(processes[0][0],end_t) print processes[0][0] [0] processes 0 0 end_t processes.pop(0) processes.pop processes pop 0 cnt+=1 cnt 1 if cnt==n:
           break
   
     cnt==n cnt n break processes[0][1]-=q processes[0][1] [0] processes 0 1 q end_t+=q end_t q processes.append(processes[0]) processes.append processes append processes[0] processes 0 processes.pop(0) processes.pop processes pop 0 i+=1 i 1 s=input() input() s end_t+=processes[0][1] processes[0][1] end_t end_t+=q q end_t i+=1 1 i q=int(d[1]) int(d[1]) q n=int(d[0]) int(d[0]) n d=s.split() s.split() d d=s.split() s.split() d end_t=0 0 end_t processes=[] [] processes s=input() input() s cnt=0 0 cnt i=0 0 i cnt+=1 1 cnt
s=input()
d=s.split()
n=int(d[0])
q=int(d[1])
end_t=0
processes=[]
for i in range(n):
    processes.append([])
    s=input()
    d=s.split()
    processes[i].append(d[0])
    processes[i].append(int(d[1]))

cnt=0
i=0
while True:
    if processes[0][1]<=q:
       end_t+=processes[0][1]
       print(processes[0][0],end_t)
       processes.pop(0)
       cnt+=1
       if cnt==n:
           break
   
    else:
       processes[0][1]-=q
       end_t+=q
       processes.append(processes[0])
       processes.pop(0)
       i+=1

