from collections import deque
n, q = map(int,raw_input().split())
queue = deque([])
for i in range(n):
    queue.append(map(str,raw_input().split()))

queue = deque(map(lambda x : [x[0],int(x[1])], queue)) 
end  = deque([])
time = 0

while len(queue) > 0:
    xqt = queue.popleft()
    res_time = xqt[1] - q
    if res_time <= 0:
        time = time + xqt[1]
        end.append([xqt[0],time])
    else:
        time = time + q
        xqt[1] = res_time
        queue.append(xqt)

while len(end) > 0:
    out = end.popleft()
    print out[0], out[1] from collections import deque n, q = map(int,raw_input().split()) n map(int,raw_input().split()) map int raw_input().split() ().split () raw_input split q queue = deque([]) queue deque([]) deque [] for i in range(n):
    queue.append(map(str,raw_input().split())) i range(n) range n queue.append(map(str,raw_input().split())) queue.append queue append map(str,raw_input().split()) map str raw_input().split() ().split () raw_input split queue = deque(map(lambda x : [x[0],int(x[1])], queue)) queue deque(map(lambda x : [x[0],int(x[1])], queue)) deque map(lambda x : [x[0],int(x[1])], queue) map lambda x : [x[0],int(x[1])] [x[0],int(x[1])] x[0] x 0 int(x[1]) int x[1] x 1 x queue end  = deque([]) end deque([]) deque [] time = 0 time 0 while len(queue) > 0:
    xqt = queue.popleft()
    res_time = xqt[1] - q
    if res_time <= 0:
        time = time + xqt[1]
        end.append([xqt[0],time])
    else:
        time = time + q
        xqt[1] = res_time
        queue.append(xqt) len(queue) > 0 len(queue) len queue 0 xqt = queue.popleft() xqt queue.popleft() queue.popleft queue popleft res_time = xqt[1] - q res_time xqt[1] - q xqt[1] xqt 1 q if res_time <= 0:
        time = time + xqt[1]
        end.append([xqt[0],time])
    else:
        time = time + q
        xqt[1] = res_time
        queue.append(xqt) res_time <= 0 res_time 0 time = time + xqt[1] time time + xqt[1] time xqt[1] xqt 1 end.append([xqt[0],time]) end.append end append [xqt[0],time] xqt[0] xqt 0 time time = time + q time time + q time q xqt[1] = res_time xqt[1] xqt 1 res_time queue.append(xqt) queue.append queue append xqt while len(end) > 0:
    out = end.popleft()
    print out[0], out[1] len(end) > 0 len(end) len end 0 out = end.popleft() out end.popleft() end.popleft end popleft print out[0] out 0 out[1] out 1 time = 0 0 time queue = deque(map(lambda x : [x[0],int(x[1])], queue)) deque(map(lambda x : [x[0],int(x[1])], queue)) queue n, q = map(int,raw_input().split()) map(int,raw_input().split()) n queue = deque([]) deque([]) queue time = time + q time + q time end  = deque([]) deque([]) end xqt = queue.popleft() queue.popleft() xqt res_time = xqt[1] - q xqt[1] - q res_time q = map(int,raw_input().split()) map(int,raw_input().split()) q out = end.popleft() end.popleft() out time = time + xqt[1] time + xqt[1] time
from collections import deque
n, q = map(int,raw_input().split())
queue = deque([])
for i in range(n):
    queue.append(map(str,raw_input().split()))

queue = deque(map(lambda x : [x[0],int(x[1])], queue)) 
end  = deque([])
time = 0

while len(queue) > 0:
    xqt = queue.popleft()
    res_time = xqt[1] - q
    if res_time <= 0:
        time = time + xqt[1]
        end.append([xqt[0],time])
    else:
        time = time + q
        xqt[1] = res_time
        queue.append(xqt)

while len(end) > 0:
    out = end.popleft()
    print out[0], out[1]