from collections import deque
n, q = map(int, input().split())
deq = deque()
for i in range(n):
    name, time = input().split(); time = int(time)
    deq.append((time, name))
ans = []
cur = 0
while deq:
    time, name = deq.popleft()
    if time <= q:
        cur += time
        ans.append("%s %d" % (name, cur))
    else:
        cur += q
        deq.append((time-q, name))
print(*ans, sep="\n") from collections import deque n, q = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split q deq = deque() deq deque() deque for i in range(n):
    name, time = input().split(); time = int(time)
    deq.append((time, name)) i range(n) range n name, time = input().split() name input().split() ().split () input split time time = int(time) time int(time) int time deq.append((time, name)) deq.append deq append (time, name) time name ans = [] ans [] cur = 0 cur 0 while deq:
    time, name = deq.popleft()
    if time <= q:
        cur += time
        ans.append("%s %d" % (name, cur))
    else:
        cur += q
        deq.append((time-q, name)) deq time, name = deq.popleft() time deq.popleft() deq.popleft deq popleft name if time <= q:
        cur += time
        ans.append("%s %d" % (name, cur))
    else:
        cur += q
        deq.append((time-q, name)) time <= q time q cur += time cur time ans.append("%s %d" % (name, cur)) ans.append ans append "%s %d" % (name, cur) "%s %d" (name, cur) name cur cur += q cur q deq.append((time-q, name)) deq.append deq append (time-q, name) time-q time q name print(*ans, sep="\n") print *ans ans sep="\n" sep "\n" ans = [] [] ans time = input().split() input().split() time time = int(time) int(time) time cur = 0 0 cur name = deq.popleft() deq.popleft() name q = map(int, input().split()) map(int, input().split()) q n, q = map(int, input().split()) map(int, input().split()) n deq = deque() deque() deq name, time = input().split() input().split() name cur += q q cur time, name = deq.popleft() deq.popleft() time cur += time time cur
from collections import deque
n, q = map(int, input().split())
deq = deque()
for i in range(n):
    name, time = input().split(); time = int(time)
    deq.append((time, name))
ans = []
cur = 0
while deq:
    time, name = deq.popleft()
    if time <= q:
        cur += time
        ans.append("%s %d" % (name, cur))
    else:
        cur += q
        deq.append((time-q, name))
print(*ans, sep="\n")