# Aizu Problem ALDS_1_3_B: Queue
#
import sys, math, os

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


N, quantum = [int(_) for _ in input().split()]
queue = []
for _ in range(N):
    name, length = input().split()
    queue.append([name, int(length)])

time = 0
while len(queue) > 0:
    name, length = queue.pop(0)
    if length > quantum:
        time += quantum
        queue.append([name, length - quantum])
    else:
        time += length
        print(name, time) import sys, math, os sys math os PYDEV = os.environ.get('PYDEV') PYDEV os.environ.get('PYDEV') os.environ.get os.environ os environ get 'PYDEV' if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt") PYDEV=="True" PYDEV "True" sys.stdin = open("sample-input.txt", "rt") sys.stdin sys stdin open("sample-input.txt", "rt") open "sample-input.txt" "rt" int(_) for _ in input().split() for _ in input().split() _ input().split() ().split () input split for _ in input().split() int(_) int _ N, quantum = [int(_) for _ in input().split()] N [int(_) for _ in input().split()] quantum queue = [] queue [] for _ in range(N):
    name, length = input().split()
    queue.append([name, int(length)]) _ range(N) range N name, length = input().split() name input().split() ().split () input split length queue.append([name, int(length)]) queue.append queue append [name, int(length)] name int(length) int length time = 0 time 0 while len(queue) > 0:
    name, length = queue.pop(0)
    if length > quantum:
        time += quantum
        queue.append([name, length - quantum])
    else:
        time += length
        print(name, time) len(queue) > 0 len(queue) len queue 0 name, length = queue.pop(0) name queue.pop(0) queue.pop queue pop 0 length if length > quantum:
        time += quantum
        queue.append([name, length - quantum])
    else:
        time += length
        print(name, time) length > quantum length quantum time += quantum time quantum queue.append([name, length - quantum]) queue.append queue append [name, length - quantum] name length - quantum length quantum time += length time length print(name, time) print name time name, length = input().split() input().split() name time = 0 0 time PYDEV = os.environ.get('PYDEV') os.environ.get('PYDEV') PYDEV time += length length time N, quantum = [int(_) for _ in input().split()] [int(_) for _ in input().split()] N queue = [] [] queue length = input().split() input().split() length name, length = queue.pop(0) queue.pop(0) name length = queue.pop(0) queue.pop(0) length time += quantum quantum time quantum = [int(_) for _ in input().split()] [int(_) for _ in input().split()] quantum
# Aizu Problem ALDS_1_3_B: Queue
#
import sys, math, os

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


N, quantum = [int(_) for _ in input().split()]
queue = []
for _ in range(N):
    name, length = input().split()
    queue.append([name, int(length)])

time = 0
while len(queue) > 0:
    name, length = queue.pop(0)
    if length > quantum:
        time += quantum
        queue.append([name, length - quantum])
    else:
        time += length
        print(name, time)