from collections import deque

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

f = lambda a, b: (a, int(b))

dq = deque(f(*input().split()) for _ in range(n))

cnt = 0

ans = []

while dq:

    s, t = dq.popleft()

    if t <= q:

        cnt += t

        ans.append(f"{s} {cnt}")

    else:

        cnt += q

        dq.append((s, t - q))

print(*ans, sep="\n")



import sys

from collections import deque

readline = sys.stdin.readline

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

f = lambda a, b: (a, int(b))

dq = deque(f(*readline().split()) for _ in range(n))

cnt = 0

ans = []

while dq:

    s, t = dq.popleft()

    if t <= q:

        cnt += t

        ans.append(f"{s} {cnt}")

    else:

        cnt += q

        dq.append((s, t - q))

print(*ans, sep="\n")



from collections import deque

n, q = map(int, input().split())
f = lambda a, b: (a, int(b))
dq = deque(f(*input().split()) for _ in range(n))
cnt = 0
ans = []
while dq:
    s, t = dq.popleft()
    if t <= q:
        cnt += t
        ans.append(f"{s} {cnt}")
    else:
        cnt += q
        dq.append((s, t - q))
print(*ans, sep="\n")

import sys
from collections import deque

readline = sys.stdin.readline
n, q = map(int, input().split())
f = lambda a, b: (a, int(b))
dq = deque(f(*readline().split()) for _ in range(n))
cnt = 0
ans = []
while dq:
    s, t = dq.popleft()
    if t <= q:
        cnt += t
        ans.append(f"{s} {cnt}")
    else:
        cnt += q
        dq.append((s, t - q))
print(*ans, sep="\n")

+import sys +readline = sys.stdin.readline -dq = deque(f(*input().split()) for _ in range(n)) +dq = deque(f(*readline().split()) for _ in range(n))