from collections import deque

n, q = (int(s) for s in input().split())

que = deque()
for i in range(n):
    name, ts = input().split()
    que.append((name, int(ts)))

t = 0
while que:
    name, time = que.popleft()
    if time <= q:
        t += time
        print(name, t)
    else:
        t += q
        que.append((name, time - q)) from collections import deque int(s) for s in input().split() for s in input().split() s input().split() ().split () input split for s in input().split() int(s) int s n, q = (int(s) for s in input().split()) n (int(s) for s in input().split()) q que = deque() que deque() deque for i in range(n):
    name, ts = input().split()
    que.append((name, int(ts))) i range(n) range n name, ts = input().split() name input().split() ().split () input split ts que.append((name, int(ts))) que.append que append (name, int(ts)) name int(ts) int ts t = 0 t 0 while que:
    name, time = que.popleft()
    if time <= q:
        t += time
        print(name, t)
    else:
        t += q
        que.append((name, time - q)) que name, time = que.popleft() name que.popleft() que.popleft que popleft time if time <= q:
        t += time
        print(name, t)
    else:
        t += q
        que.append((name, time - q)) time <= q time q t += time t time print(name, t) print name t t += q t q que.append((name, time - q)) que.append que append (name, time - q) name time - q time q t = 0 0 t time = que.popleft() que.popleft() time que = deque() deque() que t += time time t name, ts = input().split() input().split() name name, time = que.popleft() que.popleft() name q = (int(s) for s in input().split()) (int(s) for s in input().split()) q ts = input().split() input().split() ts t += q q t n, q = (int(s) for s in input().split()) (int(s) for s in input().split()) n
from collections import deque

n, q = (int(s) for s in input().split())

que = deque()
for i in range(n):
    name, ts = input().split()
    que.append((name, int(ts)))

t = 0
while que:
    name, time = que.popleft()
    if time <= q:
        t += time
        print(name, t)
    else:
        t += q
        que.append((name, time - q))