import sys
from collections import deque
readline = sys.stdin.readline
n, q = map(int, input().split())
f = lambda a, b: (a, int(b))
dq = deque(f(*readline().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")
 import sys sys from collections import deque readline = sys.stdin.readline readline sys.stdin.readline sys.stdin sys stdin readline 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(*readline().split()) for _ in range(n)) dq deque(f(*readline().split()) for _ in range(n)) deque f(*readline().split()) f *readline().split() readline().split() ().split () readline 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" f = lambda a, b: (a, int(b)) lambda a, b: (a, int(b)) f q = map(int, input().split()) map(int, input().split()) q s, t = dq.popleft() dq.popleft() s t = dq.popleft() dq.popleft() t n, q = map(int, input().split()) map(int, input().split()) n cnt += q q cnt dq = deque(f(*readline().split()) for _ in range(n)) deque(f(*readline().split()) for _ in range(n)) dq cnt = 0 0 cnt cnt += t t cnt readline = sys.stdin.readline sys.stdin.readline readline ans = [] [] ans
import sys
from collections import deque
readline = sys.stdin.readline
n, q = map(int, input().split())
f = lambda a, b: (a, int(b))
dq = deque(f(*readline().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")

