from collections import deque

n, q = map(int, input().split())
ps = [input().split() for _ in range(n)]

que = deque(ps)
time = 0

while que:

    p, rest = que.popleft()

    elapsed = min(q, int(rest))
    time += elapsed
    rest = str(int(rest) - elapsed)

    if int(rest) > 0:
        que.append([p, rest])
    else:
        print(p, time) from collections import deque n, q = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split q input().split() for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) input().split() ().split () input split ps = [input().split() for _ in range(n)] ps [input().split() for _ in range(n)] que = deque(ps) que deque(ps) deque ps time = 0 time 0 while que:

    p, rest = que.popleft()

    elapsed = min(q, int(rest))
    time += elapsed
    rest = str(int(rest) - elapsed)

    if int(rest) > 0:
        que.append([p, rest])
    else:
        print(p, time) que p, rest = que.popleft() p que.popleft() que.popleft que popleft rest elapsed = min(q, int(rest)) elapsed min(q, int(rest)) min q int(rest) int rest time += elapsed time elapsed rest = str(int(rest) - elapsed) rest str(int(rest) - elapsed) str int(rest) - elapsed int(rest) int rest elapsed if int(rest) > 0:
        que.append([p, rest])
    else:
        print(p, time) int(rest) > 0 int(rest) int rest 0 que.append([p, rest]) que.append que append [p, rest] p rest print(p, time) print p time time = 0 0 time q = map(int, input().split()) map(int, input().split()) q p, rest = que.popleft() que.popleft() p elapsed = min(q, int(rest)) min(q, int(rest)) elapsed time += elapsed elapsed time rest = que.popleft() que.popleft() rest rest = str(int(rest) - elapsed) str(int(rest) - elapsed) rest que = deque(ps) deque(ps) que ps = [input().split() for _ in range(n)] [input().split() for _ in range(n)] ps n, q = map(int, input().split()) map(int, input().split()) n
from collections import deque

n, q = map(int, input().split())
ps = [input().split() for _ in range(n)]

que = deque(ps)
time = 0

while que:

    p, rest = que.popleft()

    elapsed = min(q, int(rest))
    time += elapsed
    rest = str(int(rest) - elapsed)

    if int(rest) > 0:
        que.append([p, rest])
    else:
        print(p, time)
