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

que = [list(map(str, input().split())) for i in range(n)]

mxt = sum([int(y) for x,y in que])

t = 0

i = 0

while t < mxt:

	i %= n

	if int(que[i][1]) <= q:

		t += int(que[i][1])

		print(que[i][0],t)

		que.pop(i)

		n -= 1

	else:

		t += q

		que[i][1] = int(que[i][1]) - q

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

que = [list(map(str, input().split())) for i in range(n)]

for i in range(n):que[i][1] = int(que[i][1])

mxt = sum([y for x,y in que])

t = 0

i = 0

while t < mxt:

    if i >= n: i %= n

    if que[i][1] <= q:

        t += que[i][1]

        print(que[i][0],t)

        que.pop(i)

        n -= 1

    else:

        t += q

        que[i][1] -= q

        i += 1
n, q = list(map(int, input().split()))
que = [list(map(str, input().split())) for i in range(n)]
mxt = sum([int(y) for x, y in que])
t = 0
i = 0
while t < mxt:
    i %= n
    if int(que[i][1]) <= q:
        t += int(que[i][1])
        print(que[i][0], t)
        que.pop(i)
        n -= 1
    else:
        t += q
        que[i][1] = int(que[i][1]) - q
        i += 1

n, q = list(map(int, input().split()))
que = [list(map(str, input().split())) for i in range(n)]
for i in range(n):
    que[i][1] = int(que[i][1])
mxt = sum([y for x, y in que])
t = 0
i = 0
while t < mxt:
    if i >= n:
        i %= n
    if que[i][1] <= q:
        t += que[i][1]
        print(que[i][0], t)
        que.pop(i)
        n -= 1
    else:
        t += q
        que[i][1] -= q
        i += 1

-mxt = sum([int(y) for x, y in que]) +for i in range(n): +    que[i][1] = int(que[i][1]) +mxt = sum([y for x, y in que]) -    i %= n -    if int(que[i][1]) <= q: -        t += int(que[i][1]) +    if i >= n: +        i %= n +    if que[i][1] <= q: +        t += que[i][1] -        que[i][1] = int(que[i][1]) - q +        que[i][1] -= q