from collections import deque


def run_process(processes, slot):
    """Simulate the round-robin scheduler.
    Returns a list of (process, elapsed_time).

    >>> ps = [('p1', 150), ('p2', 80), ('p3', 200), ('p4', 350), ('p5', 20)]
    >>> run_process(ps, 100)
    [('p2', 180), ('p5', 400), ('p1', 450), ('p3', 550), ('p4', 800)]
    """
    ps = deque(processes)
    tot = 0
    finish = []

    while len(ps) > 0:
        p, t = ps.popleft()
        dt = min(t, slot)
        if dt == t:
            finish.append((p, tot+dt))
        else:
            ps.append((p, t-dt))

        tot += dt

    return finish


def run():
    count, slot = [int(i) for i in input().split()]
    ps = []

    for _ in range(count):
        p, t = input().split()
        ps.append((p, int(t)))

    for p, t in run_process(ps, slot):
        print(p, t)


if __name__ == '__main__':
    run()
 from collections import deque def run_process(processes, slot):
    """Simulate the round-robin scheduler.
    Returns a list of (process, elapsed_time).

    >>> ps = [('p1', 150), ('p2', 80), ('p3', 200), ('p4', 350), ('p5', 20)]
    >>> run_process(ps, 100)
    [('p2', 180), ('p5', 400), ('p1', 450), ('p3', 550), ('p4', 800)]
    """
    ps = deque(processes)
    tot = 0
    finish = []

    while len(ps) > 0:
        p, t = ps.popleft()
        dt = min(t, slot)
        if dt == t:
            finish.append((p, tot+dt))
        else:
            ps.append((p, t-dt))

        tot += dt

    return finish run_process """Simulate the round-robin scheduler.
    Returns a list of (process, elapsed_time).

    >>> ps = [('p1', 150), ('p2', 80), ('p3', 200), ('p4', 350), ('p5', 20)]
    >>> run_process(ps, 100)
    [('p2', 180), ('p5', 400), ('p1', 450), ('p3', 550), ('p4', 800)]
    """ ps = deque(processes) ps deque(processes) deque processes tot = 0 tot 0 finish = [] finish [] while len(ps) > 0:
        p, t = ps.popleft()
        dt = min(t, slot)
        if dt == t:
            finish.append((p, tot+dt))
        else:
            ps.append((p, t-dt))

        tot += dt

     len(ps) > 0 len(ps) len ps 0 p, t = ps.popleft() p ps.popleft() ps.popleft ps popleft t dt = min(t, slot) dt min(t, slot) min t slot if dt == t:
            finish.append((p, tot+dt))
        else:
            ps.append((p, t-dt))

         dt == t dt t finish.append((p, tot+dt)) finish.append finish append (p, tot+dt) p tot+dt tot dt ps.append((p, t-dt)) ps.append ps append (p, t-dt) p t-dt t dt tot += dt tot dt return finish finish processes processes slot slot def run():
    count, slot = [int(i) for i in input().split()]
    ps = []

    for _ in range(count):
        p, t = input().split()
        ps.append((p, int(t)))

    for p, t in run_process(ps, slot):
        print(p, t) run int(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() int(i) int i count, slot = [int(i) for i in input().split()] count [int(i) for i in input().split()] slot ps = [] ps [] for _ in range(count):
        p, t = input().split()
        ps.append((p, int(t)))

     _ range(count) range count p, t = input().split() p input().split() ().split () input split t ps.append((p, int(t))) ps.append ps append (p, int(t)) p int(t) int t for p, t in run_process(ps, slot):
        print(p, t) p t run_process(ps, slot) run_process ps slot print(p, t) print p t if __name__ == '__main__':
    run() __name__ == '__main__' __name__ '__main__' run() run def run():
    count, slot = [int(i) for i in input().split()]
    ps = []

    for _ in range(count):
        p, t = input().split()
        ps.append((p, int(t)))

    for p, t in run_process(ps, slot):
        print(p, t) def run():
    count, slot = [int(i) for i in input().split()]
    ps = []

    for _ in range(count):
        p, t = input().split()
        ps.append((p, int(t)))

    for p, t in run_process(ps, slot):
        print(p, t) run def run_process(processes, slot):
    """Simulate the round-robin scheduler.
    Returns a list of (process, elapsed_time).

    >>> ps = [('p1', 150), ('p2', 80), ('p3', 200), ('p4', 350), ('p5', 20)]
    >>> run_process(ps, 100)
    [('p2', 180), ('p5', 400), ('p1', 450), ('p3', 550), ('p4', 800)]
    """
    ps = deque(processes)
    tot = 0
    finish = []

    while len(ps) > 0:
        p, t = ps.popleft()
        dt = min(t, slot)
        if dt == t:
            finish.append((p, tot+dt))
        else:
            ps.append((p, t-dt))

        tot += dt

    return finish def run_process(processes, slot):
    """Simulate the round-robin scheduler.
    Returns a list of (process, elapsed_time).

    >>> ps = [('p1', 150), ('p2', 80), ('p3', 200), ('p4', 350), ('p5', 20)]
    >>> run_process(ps, 100)
    [('p2', 180), ('p5', 400), ('p1', 450), ('p3', 550), ('p4', 800)]
    """
    ps = deque(processes)
    tot = 0
    finish = []

    while len(ps) > 0:
        p, t = ps.popleft()
        dt = min(t, slot)
        if dt == t:
            finish.append((p, tot+dt))
        else:
            ps.append((p, t-dt))

        tot += dt

    return finish run_process
from collections import deque


def run_process(processes, slot):
    """Simulate the round-robin scheduler.
    Returns a list of (process, elapsed_time).

    >>> ps = [('p1', 150), ('p2', 80), ('p3', 200), ('p4', 350), ('p5', 20)]
    >>> run_process(ps, 100)
    [('p2', 180), ('p5', 400), ('p1', 450), ('p3', 550), ('p4', 800)]
    """
    ps = deque(processes)
    tot = 0
    finish = []

    while len(ps) > 0:
        p, t = ps.popleft()
        dt = min(t, slot)
        if dt == t:
            finish.append((p, tot+dt))
        else:
            ps.append((p, t-dt))

        tot += dt

    return finish


def run():
    count, slot = [int(i) for i in input().split()]
    ps = []

    for _ in range(count):
        p, t = input().split()
        ps.append((p, int(t)))

    for p, t in run_process(ps, slot):
        print(p, t)


if __name__ == '__main__':
    run()

