
from collections import deque

n, q = map(int, input().split())
procs = deque([])

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

total = 0

while procs:
    procs[0][1] -= q

    if procs[0][1] > 0:
        total += q
        procs.append(procs.popleft())
    else:
        total += q + procs[0][1]
        print(procs[0][0], total)
        procs.popleft() from collections import deque n, q = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split q procs = deque([]) procs deque([]) deque [] for i in range(n):
    name, time = input().split()
    time = int(time)
    procs.append([name, time]) i range(n) range n name, time = input().split() name input().split() ().split () input split time time = int(time) time int(time) int time procs.append([name, time]) procs.append procs append [name, time] name time total = 0 total 0 while procs:
    procs[0][1] -= q

    if procs[0][1] > 0:
        total += q
        procs.append(procs.popleft())
    else:
        total += q + procs[0][1]
        print(procs[0][0], total)
        procs.popleft() procs procs[0][1] -= q procs[0][1] [0] procs 0 1 q if procs[0][1] > 0:
        total += q
        procs.append(procs.popleft())
    else:
        total += q + procs[0][1]
        print(procs[0][0], total)
        procs.popleft() procs[0][1] > 0 procs[0][1] [0] procs 0 1 0 total += q total q procs.append(procs.popleft()) procs.append procs append procs.popleft() procs.popleft procs popleft total += q + procs[0][1] total q + procs[0][1] q procs[0][1] [0] procs 0 1 print(procs[0][0], total) print procs[0][0] [0] procs 0 0 total procs.popleft() procs.popleft procs popleft total += q q total procs = deque([]) deque([]) procs total = 0 0 total q = map(int, input().split()) map(int, input().split()) q time = input().split() input().split() time time = int(time) int(time) time total += q + procs[0][1] q + procs[0][1] total n, q = map(int, input().split()) map(int, input().split()) n name, time = input().split() input().split() name

from collections import deque

n, q = map(int, input().split())
procs = deque([])

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

total = 0

while procs:
    procs[0][1] -= q

    if procs[0][1] > 0:
        total += q
        procs.append(procs.popleft())
    else:
        total += q + procs[0][1]
        print(procs[0][0], total)
        procs.popleft()