n, q = list(map(int, input().split()))

process = [input().split() for _ in range(n)]

#print(process)

time = 0

while process:

    p = process.pop(0)

    if int(p[1]) <= q:

        time += int(p[1])

        print((p[0], time))

    else:

        time += q

        process.append([p[0], int(p[1])-q])
from collections import deque



n, q = list(map(int, input().split()))

dq = deque()



for _ in range(n):

    name, time = input().split()

    dq.append([name, int(time)])



cnt = 0



while dq:

    qt = dq.popleft()

    if qt[1] <= q:

        cnt += qt[1]

        print((qt[0], cnt))

    else:

        cnt += q

        qt[1] -= q

        dq.append(qt)
n, q = list(map(int, input().split()))
process = [input().split() for _ in range(n)]
# print(process)
time = 0
while process:
    p = process.pop(0)
    if int(p[1]) <= q:
        time += int(p[1])
        print((p[0], time))
    else:
        time += q
        process.append([p[0], int(p[1]) - q])

from collections import deque

n, q = list(map(int, input().split()))
dq = deque()
for _ in range(n):
    name, time = input().split()
    dq.append([name, int(time)])
cnt = 0
while dq:
    qt = dq.popleft()
    if qt[1] <= q:
        cnt += qt[1]
        print((qt[0], cnt))
    else:
        cnt += q
        qt[1] -= q
        dq.append(qt)

+from collections import deque + -process = [input().split() for _ in range(n)] -# print(process) -time = 0 -while process: -    p = process.pop(0) -    if int(p[1]) <= q: -        time += int(p[1]) -        print((p[0], time)) +dq = deque() +for _ in range(n): +    name, time = input().split() +    dq.append([name, int(time)]) +cnt = 0 +while dq: +    qt = dq.popleft() +    if qt[1] <= q: +        cnt += qt[1] +        print((qt[0], cnt)) -        time += q -        process.append([p[0], int(p[1]) - q]) +        cnt += q +        qt[1] -= q +        dq.append(qt)