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

queue = []

for i in range(n):

	name,time = input().split()

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



t = 0

while queue:

	name,time = queue.pop(0)

	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)

n, q = list(map(int, input().split()))
queue = []
for i in range(n):
    name, time = input().split()
    queue.append((name, int(time)))
t = 0
while queue:
    name, time = queue.pop(0)
    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)

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