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

queue = []

for i in range(n):

	name,time = input().split()

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



t = 0

i = 0

while queue:

	i %= len(queue)

	p = queue[i]

	t += min(q, p[1])

	if p[1] > q:

		p[1] -= q

		i += 1

	else:

		print((p[0], t))

		queue.pop(i)

from collections import deque



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

queue = deque()

for i in range(n):

	name,time = input().split()

	queue.append((name, int(time)))



t = 0

while queue:

	name,time = queue.popleft()

	t += min(q, time)

	if time > q:

		queue.append((name, time-q))

	else:

		print((name,t))

n, q = list(map(int, input().split()))
queue = []
for i in range(n):
    name, time = input().split()
    queue.append([name, int(time)])
t = 0
i = 0
while queue:
    i %= len(queue)
    p = queue[i]
    t += min(q, p[1])
    if p[1] > q:
        p[1] -= q
        i += 1
    else:
        print((p[0], t))
        queue.pop(i)

from collections import deque

n, q = list(map(int, input().split()))
queue = deque()
for i in range(n):
    name, time = input().split()
    queue.append((name, int(time)))
t = 0
while queue:
    name, time = queue.popleft()
    t += min(q, time)
    if time > q:
        queue.append((name, time - q))
    else:
        print((name, t))

+from collections import deque + -queue = [] +queue = deque() -    queue.append([name, int(time)]) +    queue.append((name, int(time))) -i = 0 -    i %= len(queue) -    p = queue[i] -    t += min(q, p[1]) -    if p[1] > q: -        p[1] -= q -        i += 1 +    name, time = queue.popleft() +    t += min(q, time) +    if time > q: +        queue.append((name, time - q)) -        print((p[0], t)) -        queue.pop(i) +        print((name, t))