from collections import deque

n, q = map(int, input().split())
a = deque([])
for i in range(n):
    a.append(list(input().split()))

end_time = 0
while len(a):
    e = a.popleft()
    if int(e[1]) - q > 0:
        e[1] = int(e[1]) - q
        a.append(e)
        end_time += q
    else:
        end_time += int(e[1])
        print(e[0], end_time)
 from collections import deque n, q = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split q a = deque([]) a deque([]) deque [] for i in range(n):
    a.append(list(input().split())) i range(n) range n a.append(list(input().split())) a.append a append list(input().split()) list input().split() ().split () input split end_time = 0 end_time 0 while len(a):
    e = a.popleft()
    if int(e[1]) - q > 0:
        e[1] = int(e[1]) - q
        a.append(e)
        end_time += q
    else:
        end_time += int(e[1])
        print(e[0], end_time) len(a) len a e = a.popleft() e a.popleft() a.popleft a popleft if int(e[1]) - q > 0:
        e[1] = int(e[1]) - q
        a.append(e)
        end_time += q
    else:
        end_time += int(e[1])
        print(e[0], end_time) int(e[1]) - q > 0 int(e[1]) - q int(e[1]) int e[1] e 1 q 0 e[1] = int(e[1]) - q e[1] e 1 int(e[1]) - q int(e[1]) int e[1] e 1 q a.append(e) a.append a append e end_time += q end_time q end_time += int(e[1]) end_time int(e[1]) int e[1] e 1 print(e[0], end_time) print e[0] e 0 end_time n, q = map(int, input().split()) map(int, input().split()) n e = a.popleft() a.popleft() e end_time += int(e[1]) int(e[1]) end_time q = map(int, input().split()) map(int, input().split()) q end_time += q q end_time a = deque([]) deque([]) a end_time = 0 0 end_time
from collections import deque

n, q = map(int, input().split())
a = deque([])
for i in range(n):
    a.append(list(input().split()))

end_time = 0
while len(a):
    e = a.popleft()
    if int(e[1]) - q > 0:
        e[1] = int(e[1]) - q
        a.append(e)
        end_time += q
    else:
        end_time += int(e[1])
        print(e[0], end_time)

