from collections import deque
n, q = map(int, input().split())
f = lambda a, b: (a, int(b))
dq = deque(f(*input().split()) for _ in range(n))
cnt = 0
ans = []
while dq:
    s, t = dq.popleft()
    if t <= q:
        cnt += t
        ans.append(f"{s} {cnt}")
    else:
        cnt += q
        dq.append((s, t - q))
print(*ans, sep="\n")
 from collections import deque n, q = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split q f = lambda a, b: (a, int(b)) f lambda a, b: (a, int(b)) (a, int(b)) a int(b) int b a b dq = deque(f(*input().split()) for _ in range(n)) dq deque(f(*input().split()) for _ in range(n)) deque f(*input().split()) f *input().split() input().split() ().split () input split cnt = 0 cnt 0 ans = [] ans [] while dq:
    s, t = dq.popleft()
    if t <= q:
        cnt += t
        ans.append(f"{s} {cnt}")
    else:
        cnt += q
        dq.append((s, t - q)) dq s, t = dq.popleft() s dq.popleft() dq.popleft dq popleft t if t <= q:
        cnt += t
        ans.append(f"{s} {cnt}")
    else:
        cnt += q
        dq.append((s, t - q)) t <= q t q cnt += t cnt t ans.append(f"{s} {cnt}") ans.append ans append f"{s} {cnt}" cnt += q cnt q dq.append((s, t - q)) dq.append dq append (s, t - q) s t - q t q print(*ans, sep="\n") print *ans ans sep="\n" sep "\n" n, q = map(int, input().split()) map(int, input().split()) n q = map(int, input().split()) map(int, input().split()) q cnt = 0 0 cnt f = lambda a, b: (a, int(b)) lambda a, b: (a, int(b)) f dq = deque(f(*input().split()) for _ in range(n)) deque(f(*input().split()) for _ in range(n)) dq ans = [] [] ans s, t = dq.popleft() dq.popleft() s cnt += t t cnt cnt += q q cnt t = dq.popleft() dq.popleft() t
from collections import deque
n, q = map(int, input().split())
f = lambda a, b: (a, int(b))
dq = deque(f(*input().split()) for _ in range(n))
cnt = 0
ans = []
while dq:
    s, t = dq.popleft()
    if t <= q:
        cnt += t
        ans.append(f"{s} {cnt}")
    else:
        cnt += q
        dq.append((s, t - q))
print(*ans, sep="\n")

