# -*- 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])))

        

    

# -*- 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])))

        





# -*- 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])))

# -*- 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 14:42:43 2018 +Created on Sun Apr 29 18:04:22 2018 +ALDS1_3b_r リングバッファによる実装 -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 fifo_enque(data): +    global tail +    global fifo +    fifo[tail] = data +    tail = (tail + 1) % fifo_size -name = [] -time = [] -current_time = 0 +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 -    name.append(s[0]) -    time.append(int(s[1])) -# ============================================================================= -# print(n,q) -# print(name) -# print(time) -# ============================================================================= +    data = [s[0], int(s[1])] +    fifo_enque(data) +current_time = 0 -i = 0 -remain = n -    if time[i] <= q: -        current_time += time.pop(i) -        finished.append(name.pop(i)) +    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]) -        remain -= 1 -        if remain == 0: -            break -        i = i % remain -    else: -        time[i] -= q -        current_time += q -        i = (i + 1) % remain +    if head == tail: +        break