# coding=utf-8
import sys

n, q = map(int, sys.stdin.readline().split())
queue = []
total_time = 0
finished_loop = 0

for i in range(n):
    name, time = input().split()
    queue.append([name, int(time)])

while queue:
    n -= finished_loop
    finished_loop = 0
    for i in range(n):
        poped = queue.pop(0)
        name = poped[0]
        time = poped[1]
        if time > q:
            queue.append([name, time - q])
            total_time += q
        else:
            total_time += time
            print(name, total_time)
            finished_loop += 1 import sys sys n, q = map(int, sys.stdin.readline().split()) n map(int, sys.stdin.readline().split()) map int sys.stdin.readline().split() sys.stdin.readline().split sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline split q queue = [] queue [] total_time = 0 total_time 0 finished_loop = 0 finished_loop 0 for i in range(n):
    name, time = input().split()
    queue.append([name, int(time)]) i range(n) range n name, time = input().split() name input().split() ().split () input split time queue.append([name, int(time)]) queue.append queue append [name, int(time)] name int(time) int time while queue:
    n -= finished_loop
    finished_loop = 0
    for i in range(n):
        poped = queue.pop(0)
        name = poped[0]
        time = poped[1]
        if time > q:
            queue.append([name, time - q])
            total_time += q
        else:
            total_time += time
            print(name, total_time)
            finished_loop += 1 queue n -= finished_loop n finished_loop finished_loop = 0 finished_loop 0 for i in range(n):
        poped = queue.pop(0)
        name = poped[0]
        time = poped[1]
        if time > q:
            queue.append([name, time - q])
            total_time += q
        else:
            total_time += time
            print(name, total_time)
            finished_loop += 1 i range(n) range n poped = queue.pop(0) poped queue.pop(0) queue.pop queue pop 0 name = poped[0] name poped[0] poped 0 time = poped[1] time poped[1] poped 1 if time > q:
            queue.append([name, time - q])
            total_time += q
        else:
            total_time += time
            print(name, total_time)
            finished_loop += 1 time > q time q queue.append([name, time - q]) queue.append queue append [name, time - q] name time - q time q total_time += q total_time q total_time += time total_time time print(name, total_time) print name total_time finished_loop += 1 finished_loop 1 time = poped[1] poped[1] time finished_loop = 0 0 finished_loop queue = [] [] queue time = input().split() input().split() time name = poped[0] poped[0] name finished_loop += 1 1 finished_loop finished_loop = 0 0 finished_loop total_time = 0 0 total_time poped = queue.pop(0) queue.pop(0) poped name, time = input().split() input().split() name n -= finished_loop finished_loop n n, q = map(int, sys.stdin.readline().split()) map(int, sys.stdin.readline().split()) n total_time += time time total_time total_time += q q total_time q = map(int, sys.stdin.readline().split()) map(int, sys.stdin.readline().split()) q
# coding=utf-8
import sys

n, q = map(int, sys.stdin.readline().split())
queue = []
total_time = 0
finished_loop = 0

for i in range(n):
    name, time = input().split()
    queue.append([name, int(time)])

while queue:
    n -= finished_loop
    finished_loop = 0
    for i in range(n):
        poped = queue.pop(0)
        name = poped[0]
        time = poped[1]
        if time > q:
            queue.append([name, time - q])
            total_time += q
        else:
            total_time += time
            print(name, total_time)
            finished_loop += 1