from sys import stdin
def stdinput():
    return stdin.readline().strip()

from collections import deque

def main():
    n ,q = map(int, stdinput().split())
    ps = deque()
    for _ in range(n):
        p, t = stdinput().split()
        t = int(t)
        ps.append([p, t])

    ctime = 0
    while len(ps) > 0:
        p = ps.popleft()
        if p[1] <= q:
            ctime += p[1]
            print(f'{p[0]} {ctime}')
        else:
            ctime += q
            p[1] -= q
            ps.append(p)

if __name__ == '__main__':
    main() from sys import stdin def stdinput():
    return stdin.readline().strip() stdinput return stdin.readline().strip() stdin.readline().strip() stdin.readline().strip stdin.readline() stdin.readline stdin readline strip from collections import deque def main():
    n ,q = map(int, stdinput().split())
    ps = deque()
    for _ in range(n):
        p, t = stdinput().split()
        t = int(t)
        ps.append([p, t])

    ctime = 0
    while len(ps) > 0:
        p = ps.popleft()
        if p[1] <= q:
            ctime += p[1]
            print(f'{p[0]} {ctime}')
        else:
            ctime += q
            p[1] -= q
            ps.append(p) main n ,q = map(int, stdinput().split()) n map(int, stdinput().split()) map int stdinput().split() ().split () stdinput split q ps = deque() ps deque() deque for _ in range(n):
        p, t = stdinput().split()
        t = int(t)
        ps.append([p, t])

     _ range(n) range n p, t = stdinput().split() p stdinput().split() ().split () stdinput split t t = int(t) t int(t) int t ps.append([p, t]) ps.append ps append [p, t] p t ctime = 0 ctime 0 while len(ps) > 0:
        p = ps.popleft()
        if p[1] <= q:
            ctime += p[1]
            print(f'{p[0]} {ctime}')
        else:
            ctime += q
            p[1] -= q
            ps.append(p) len(ps) > 0 len(ps) len ps 0 p = ps.popleft() p ps.popleft() ps.popleft ps popleft if p[1] <= q:
            ctime += p[1]
            print(f'{p[0]} {ctime}')
        else:
            ctime += q
            p[1] -= q
            ps.append(p) p[1] <= q p[1] p 1 q ctime += p[1] ctime p[1] p 1 print(f'{p[0]} {ctime}') print f'{p[0]} {ctime}' ctime += q ctime q p[1] -= q p[1] p 1 q ps.append(p) ps.append ps append p if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def stdinput():
    return stdin.readline().strip() def stdinput():
    return stdin.readline().strip() stdinput def main():
    n ,q = map(int, stdinput().split())
    ps = deque()
    for _ in range(n):
        p, t = stdinput().split()
        t = int(t)
        ps.append([p, t])

    ctime = 0
    while len(ps) > 0:
        p = ps.popleft()
        if p[1] <= q:
            ctime += p[1]
            print(f'{p[0]} {ctime}')
        else:
            ctime += q
            p[1] -= q
            ps.append(p) def main():
    n ,q = map(int, stdinput().split())
    ps = deque()
    for _ in range(n):
        p, t = stdinput().split()
        t = int(t)
        ps.append([p, t])

    ctime = 0
    while len(ps) > 0:
        p = ps.popleft()
        if p[1] <= q:
            ctime += p[1]
            print(f'{p[0]} {ctime}')
        else:
            ctime += q
            p[1] -= q
            ps.append(p) main
from sys import stdin
def stdinput():
    return stdin.readline().strip()

from collections import deque

def main():
    n ,q = map(int, stdinput().split())
    ps = deque()
    for _ in range(n):
        p, t = stdinput().split()
        t = int(t)
        ps.append([p, t])

    ctime = 0
    while len(ps) > 0:
        p = ps.popleft()
        if p[1] <= q:
            ctime += p[1]
            print(f'{p[0]} {ctime}')
        else:
            ctime += q
            p[1] -= q
            ps.append(p)

if __name__ == '__main__':
    main()
