# -*- coding:utf-8 -*-

queue = list()
time = 0

n, q = [int(x) for i, x in enumerate(input().split()) if i < 2]
for i in range(n):
    temp = input().split()
    temp[1] = int(temp[1])
    queue.append(temp)
while(len(queue)):
    process = queue.pop(0)
    if process[1] <= q:
        time += process[1]
        print("{0} {1}".format(process[0], time))
    else:
        time += q
        process[1] -= q
        queue.append(process) queue = list() queue list() list time = 0 time 0 int(x) for i, x in enumerate(input().split()) if i < 2 for i, x in enumerate(input().split()) if i < 2 i x enumerate(input().split()) enumerate input().split() ().split () input split i < 2 i 2 if i < 2 int(x) int x n, q = [int(x) for i, x in enumerate(input().split()) if i < 2] n [int(x) for i, x in enumerate(input().split()) if i < 2] q for i in range(n):
    temp = input().split()
    temp[1] = int(temp[1])
    queue.append(temp) i range(n) range n temp = input().split() temp input().split() ().split () input split temp[1] = int(temp[1]) temp[1] temp 1 int(temp[1]) int temp[1] temp 1 queue.append(temp) queue.append queue append temp while(len(queue)):
    process = queue.pop(0)
    if process[1] <= q:
        time += process[1]
        print("{0} {1}".format(process[0], time))
    else:
        time += q
        process[1] -= q
        queue.append(process) len(queue) len queue process = queue.pop(0) process queue.pop(0) queue.pop queue pop 0 if process[1] <= q:
        time += process[1]
        print("{0} {1}".format(process[0], time))
    else:
        time += q
        process[1] -= q
        queue.append(process) process[1] <= q process[1] process 1 q time += process[1] time process[1] process 1 print("{0} {1}".format(process[0], time)) print "{0} {1}".format(process[0], time) "{0} {1}".format "{0} {1}" format process[0] process 0 time time += q time q process[1] -= q process[1] process 1 q queue.append(process) queue.append queue append process n, q = [int(x) for i, x in enumerate(input().split()) if i < 2] [int(x) for i, x in enumerate(input().split()) if i < 2] n time += process[1] process[1] time temp = input().split() input().split() temp time += q q time queue = list() list() queue q = [int(x) for i, x in enumerate(input().split()) if i < 2] [int(x) for i, x in enumerate(input().split()) if i < 2] q time = 0 0 time process = queue.pop(0) queue.pop(0) process
# -*- coding:utf-8 -*-

queue = list()
time = 0

n, q = [int(x) for i, x in enumerate(input().split()) if i < 2]
for i in range(n):
    temp = input().split()
    temp[1] = int(temp[1])
    queue.append(temp)
while(len(queue)):
    process = queue.pop(0)
    if process[1] <= q:
        time += process[1]
        print("{0} {1}".format(process[0], time))
    else:
        time += q
        process[1] -= q
        queue.append(process)