# -*- coding: utf-8 -*-
"""
Created on Sun Apr 29 14:42:43 2018

@author: maezawa
"""

def print_array(g):
    ans = str(g[0])
    if len(g) > 1:
        for i in range(1,len(g)):
            ans += ' '+str(g[i]) 
    print(ans)

name=[]
time=[]
current_time = 0

n, q = list(map(int, input().split()))
for i in range(n):
    s = input().split()
    name.append(s[0])
    time.append(int(s[1]))
# =============================================================================
# print(n,q)
# print(name)
# print(time)
# =============================================================================
finished = []
fin_time = []
i=0
remain = n
while True:
    if time[i] <= q:
        current_time += time.pop(i)
        finished.append(name.pop(i))
        fin_time.append(current_time)      
        remain -= 1
        if remain == 0:
            break
        i = i%remain
    else:
        time[i] -= q
        current_time += q
        i = (i+1)%remain

for i in range(n):
    print("{} {}".format(finished[i], fin_time[i]))
        
     """
Created on Sun Apr 29 14:42:43 2018

@author: maezawa
""" def print_array(g):
    ans = str(g[0])
    if len(g) > 1:
        for i in range(1,len(g)):
            ans += ' '+str(g[i]) 
    print(ans) print_array ans = str(g[0]) ans str(g[0]) str g[0] g 0 if len(g) > 1:
        for i in range(1,len(g)):
            ans += ' '+str(g[i]) 
     len(g) > 1 len(g) len g 1 for i in range(1,len(g)):
            ans += ' '+str(g[i]) 
     i range(1,len(g)) range 1 len(g) len g ans += ' '+str(g[i]) ans ' '+str(g[i]) ' ' str(g[i]) str g[i] g i print(ans) print ans g g name=[] name [] time=[] time [] current_time = 0 current_time 0 n, q = list(map(int, input().split())) n list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split q for i in range(n):
    s = input().split()
    name.append(s[0])
    time.append(int(s[1]))
# =============================================================================
# print(n,q)
# print(name)
# print(time)
# ============================================================================= i range(n) range n s = input().split() s input().split() ().split () input split name.append(s[0]) name.append name append s[0] s 0 time.append(int(s[1])) time.append time append int(s[1]) int s[1] s 1 finished = [] finished [] fin_time = [] fin_time [] i=0 i 0 remain = n remain n while True:
    if time[i] <= q:
        current_time += time.pop(i)
        finished.append(name.pop(i))
        fin_time.append(current_time)      
        remain -= 1
        if remain == 0:
            break
        i = i%remain
    else:
        time[i] -= q
        current_time += q
        i = (i+1)%remain True if time[i] <= q:
        current_time += time.pop(i)
        finished.append(name.pop(i))
        fin_time.append(current_time)      
        remain -= 1
        if remain == 0:
            break
        i = i%remain
    else:
        time[i] -= q
        current_time += q
        i = (i+1)%remain time[i] <= q time[i] time i q current_time += time.pop(i) current_time time.pop(i) time.pop time pop i finished.append(name.pop(i)) finished.append finished append name.pop(i) name.pop name pop i fin_time.append(current_time) fin_time.append fin_time append current_time remain -= 1 remain 1 if remain == 0:
            break
         remain == 0 remain 0 break i = i%remain i i%remain i remain time[i] -= q time[i] time i q current_time += q current_time q i = (i+1)%remain i (i+1)%remain i+1 i 1 remain for i in range(n):
    print("{} {}".format(finished[i], fin_time[i]))
        
     i range(n) range n print("{} {}".format(finished[i], fin_time[i])) print "{} {}".format(finished[i], fin_time[i]) "{} {}".format "{} {}" format finished[i] finished i fin_time[i] fin_time i fin_time = [] [] fin_time n, q = list(map(int, input().split())) list(map(int, input().split())) n s = input().split() input().split() s finished = [] [] finished current_time += q q current_time remain -= 1 1 remain time=[] [] time current_time = 0 0 current_time i = (i+1)%remain (i+1)%remain i def print_array(g):
    ans = str(g[0])
    if len(g) > 1:
        for i in range(1,len(g)):
            ans += ' '+str(g[i]) 
    print(ans) def print_array(g):
    ans = str(g[0])
    if len(g) > 1:
        for i in range(1,len(g)):
            ans += ' '+str(g[i]) 
    print(ans) print_array q = list(map(int, input().split())) list(map(int, input().split())) q current_time += time.pop(i) time.pop(i) current_time i = i%remain i%remain i name=[] [] name remain = n n remain i=0 0 i
# -*- coding: utf-8 -*-
"""
Created on Sun Apr 29 14:42:43 2018

@author: maezawa
"""

def print_array(g):
    ans = str(g[0])
    if len(g) > 1:
        for i in range(1,len(g)):
            ans += ' '+str(g[i]) 
    print(ans)

name=[]
time=[]
current_time = 0

n, q = list(map(int, input().split()))
for i in range(n):
    s = input().split()
    name.append(s[0])
    time.append(int(s[1]))
# =============================================================================
# print(n,q)
# print(name)
# print(time)
# =============================================================================
finished = []
fin_time = []
i=0
remain = n
while True:
    if time[i] <= q:
        current_time += time.pop(i)
        finished.append(name.pop(i))
        fin_time.append(current_time)      
        remain -= 1
        if remain == 0:
            break
        i = i%remain
    else:
        time[i] -= q
        current_time += q
        i = (i+1)%remain

for i in range(n):
    print("{} {}".format(finished[i], fin_time[i]))
        
    
