# -*- coding: utf-8 -*-
"""
Created on Sun Apr 29 18:04:22 2018
ALDS1_3b_r リングバッファによる実装
@author: maezawa
"""

def fifo_enque(data):
    global tail
    global fifo
    fifo[tail] = data
    tail = (tail+1)%fifo_size
    
def fifo_deque():
    global head
    global fifo
    data = fifo[head]
    head = (head+1)%fifo_size
    return data

fifo_size = 100000
fifo = [0 for _ in range(fifo_size)]
head = 0
tail = 0

n, q = list(map(int, input().split()))
for i in range(n):
    s = input().split()
    data = [s[0], int(s[1])]
    fifo_enque(data)
    
current_time = 0
finished = []
fin_time = []

while True:
    data = fifo_deque()
    if data[1] > q:
        current_time += q
        data[1] -= q
        fifo_enque(data)
    else:
        current_time += data[1]
        finished.append(data[0])
        fin_time.append(current_time)
    if head == tail:
        break

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

 """
Created on Sun Apr 29 18:04:22 2018
ALDS1_3b_r リングバッファによる実装
@author: maezawa
""" def fifo_enque(data):
    global tail
    global fifo
    fifo[tail] = data
    tail = (tail+1)%fifo_size
     fifo_enque global tail global fifo fifo[tail] = data fifo[tail] fifo tail data tail = (tail+1)%fifo_size tail (tail+1)%fifo_size tail+1 tail 1 fifo_size data data def fifo_deque():
    global head
    global fifo
    data = fifo[head]
    head = (head+1)%fifo_size
    return data fifo_deque global head global fifo data = fifo[head] data fifo[head] fifo head head = (head+1)%fifo_size head (head+1)%fifo_size head+1 head 1 fifo_size return data data fifo_size = 100000 fifo_size 100000 0 for _ in range(fifo_size) for _ in range(fifo_size) _ range(fifo_size) range fifo_size for _ in range(fifo_size) 0 fifo = [0 for _ in range(fifo_size)] fifo [0 for _ in range(fifo_size)] head = 0 head 0 tail = 0 tail 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()
    data = [s[0], int(s[1])]
    fifo_enque(data)
     i range(n) range n s = input().split() s input().split() ().split () input split data = [s[0], int(s[1])] data [s[0], int(s[1])] s[0] s 0 int(s[1]) int s[1] s 1 fifo_enque(data) fifo_enque data current_time = 0 current_time 0 finished = [] finished [] fin_time = [] fin_time [] while True:
    data = fifo_deque()
    if data[1] > q:
        current_time += q
        data[1] -= q
        fifo_enque(data)
    else:
        current_time += data[1]
        finished.append(data[0])
        fin_time.append(current_time)
    if head == tail:
        break True data = fifo_deque() data fifo_deque() fifo_deque if data[1] > q:
        current_time += q
        data[1] -= q
        fifo_enque(data)
    else:
        current_time += data[1]
        finished.append(data[0])
        fin_time.append(current_time)
     data[1] > q data[1] data 1 q current_time += q current_time q data[1] -= q data[1] data 1 q fifo_enque(data) fifo_enque data current_time += data[1] current_time data[1] data 1 finished.append(data[0]) finished.append finished append data[0] data 0 fin_time.append(current_time) fin_time.append fin_time append current_time if head == tail:
        break head == tail head tail break 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 finished = [] [] finished fifo = [0 for _ in range(fifo_size)] [0 for _ in range(fifo_size)] fifo head = 0 0 head q = list(map(int, input().split())) list(map(int, input().split())) q data = [s[0], int(s[1])] [s[0], int(s[1])] data current_time = 0 0 current_time def fifo_deque():
    global head
    global fifo
    data = fifo[head]
    head = (head+1)%fifo_size
    return data def fifo_deque():
    global head
    global fifo
    data = fifo[head]
    head = (head+1)%fifo_size
    return data fifo_deque fifo_size = 100000 100000 fifo_size tail = 0 0 tail def fifo_enque(data):
    global tail
    global fifo
    fifo[tail] = data
    tail = (tail+1)%fifo_size
     def fifo_enque(data):
    global tail
    global fifo
    fifo[tail] = data
    tail = (tail+1)%fifo_size
     fifo_enque current_time += q q current_time fin_time = [] [] fin_time data = fifo_deque() fifo_deque() data current_time += data[1] data[1] current_time s = input().split() input().split() s n, q = list(map(int, input().split())) list(map(int, input().split())) n
# -*- coding: utf-8 -*-
"""
Created on Sun Apr 29 18:04:22 2018
ALDS1_3b_r リングバッファによる実装
@author: maezawa
"""

def fifo_enque(data):
    global tail
    global fifo
    fifo[tail] = data
    tail = (tail+1)%fifo_size
    
def fifo_deque():
    global head
    global fifo
    data = fifo[head]
    head = (head+1)%fifo_size
    return data

fifo_size = 100000
fifo = [0 for _ in range(fifo_size)]
head = 0
tail = 0

n, q = list(map(int, input().split()))
for i in range(n):
    s = input().split()
    data = [s[0], int(s[1])]
    fifo_enque(data)
    
current_time = 0
finished = []
fin_time = []

while True:
    data = fifo_deque()
    if data[1] > q:
        current_time += q
        data[1] -= q
        fifo_enque(data)
    else:
        current_time += data[1]
        finished.append(data[0])
        fin_time.append(current_time)
    if head == tail:
        break

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


