from collections import deque

n, q = map(int, input().split())
dq = deque()

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

cnt = 0

while dq:
    qt = dq.popleft()
    if qt[1] <= q:
        cnt += qt[1]
        print(qt[0], cnt)
    else:
        cnt += q
        qt[1] -= q
        dq.append(qt) from collections import deque n, q = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split q dq = deque() dq deque() deque for _ in range(n):
    name, time = input().split()
    dq.append([name, int(time)]) _ range(n) range n name, time = input().split() name input().split() ().split () input split time dq.append([name, int(time)]) dq.append dq append [name, int(time)] name int(time) int time cnt = 0 cnt 0 while dq:
    qt = dq.popleft()
    if qt[1] <= q:
        cnt += qt[1]
        print(qt[0], cnt)
    else:
        cnt += q
        qt[1] -= q
        dq.append(qt) dq qt = dq.popleft() qt dq.popleft() dq.popleft dq popleft if qt[1] <= q:
        cnt += qt[1]
        print(qt[0], cnt)
    else:
        cnt += q
        qt[1] -= q
        dq.append(qt) qt[1] <= q qt[1] qt 1 q cnt += qt[1] cnt qt[1] qt 1 print(qt[0], cnt) print qt[0] qt 0 cnt cnt += q cnt q qt[1] -= q qt[1] qt 1 q dq.append(qt) dq.append dq append qt time = input().split() input().split() time dq = deque() deque() dq q = map(int, input().split()) map(int, input().split()) q cnt += qt[1] qt[1] cnt cnt = 0 0 cnt name, time = input().split() input().split() name qt = dq.popleft() dq.popleft() qt n, q = map(int, input().split()) map(int, input().split()) n cnt += q q cnt
from collections import deque

n, q = map(int, input().split())
dq = deque()

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

cnt = 0

while dq:
    qt = dq.popleft()
    if qt[1] <= q:
        cnt += qt[1]
        print(qt[0], cnt)
    else:
        cnt += q
        qt[1] -= q
        dq.append(qt)