def main():
    n, q = map(int, input().split())
    queue = [[x for x in input().split()] for _ in range(n)]
    queue = [(x[0], int(x[1])) for x in queue]

    elapsed_time = 0
    while len(queue) > 0:
        process, time = queue.pop(0)
        if time > q:
            queue.append((process, time - q))
            elapsed_time += q
        else:
            elapsed_time += time
            print('{} {}'.format(process, str(elapsed_time)))
            
    return


main() def main():
    n, q = map(int, input().split())
    queue = [[x for x in input().split()] for _ in range(n)]
    queue = [(x[0], int(x[1])) for x in queue]

    elapsed_time = 0
    while len(queue) > 0:
        process, time = queue.pop(0)
        if time > q:
            queue.append((process, time - q))
            elapsed_time += q
        else:
            elapsed_time += time
            print('{} {}'.format(process, str(elapsed_time)))
            
    return main n, q = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split q [x for x in input().split()] for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [x for x in input().split()] queue = [[x for x in input().split()] for _ in range(n)] queue [[x for x in input().split()] for _ in range(n)] (x[0], int(x[1])) for x in queue for x in queue x queue for x in queue (x[0], int(x[1])) x[0] x 0 int(x[1]) int x[1] x 1 queue = [(x[0], int(x[1])) for x in queue] queue [(x[0], int(x[1])) for x in queue] elapsed_time = 0 elapsed_time 0 while len(queue) > 0:
        process, time = queue.pop(0)
        if time > q:
            queue.append((process, time - q))
            elapsed_time += q
        else:
            elapsed_time += time
            print('{} {}'.format(process, str(elapsed_time)))
            
     len(queue) > 0 len(queue) len queue 0 process, time = queue.pop(0) process queue.pop(0) queue.pop queue pop 0 time if time > q:
            queue.append((process, time - q))
            elapsed_time += q
        else:
            elapsed_time += time
            print('{} {}'.format(process, str(elapsed_time)))
            
     time > q time q queue.append((process, time - q)) queue.append queue append (process, time - q) process time - q time q elapsed_time += q elapsed_time q elapsed_time += time elapsed_time time print('{} {}'.format(process, str(elapsed_time))) print '{} {}'.format(process, str(elapsed_time)) '{} {}'.format '{} {}' format process str(elapsed_time) str elapsed_time return main() main def main():
    n, q = map(int, input().split())
    queue = [[x for x in input().split()] for _ in range(n)]
    queue = [(x[0], int(x[1])) for x in queue]

    elapsed_time = 0
    while len(queue) > 0:
        process, time = queue.pop(0)
        if time > q:
            queue.append((process, time - q))
            elapsed_time += q
        else:
            elapsed_time += time
            print('{} {}'.format(process, str(elapsed_time)))
            
    return def main():
    n, q = map(int, input().split())
    queue = [[x for x in input().split()] for _ in range(n)]
    queue = [(x[0], int(x[1])) for x in queue]

    elapsed_time = 0
    while len(queue) > 0:
        process, time = queue.pop(0)
        if time > q:
            queue.append((process, time - q))
            elapsed_time += q
        else:
            elapsed_time += time
            print('{} {}'.format(process, str(elapsed_time)))
            
    return main
def main():
    n, q = map(int, input().split())
    queue = [[x for x in input().split()] for _ in range(n)]
    queue = [(x[0], int(x[1])) for x in queue]

    elapsed_time = 0
    while len(queue) > 0:
        process, time = queue.pop(0)
        if time > q:
            queue.append((process, time - q))
            elapsed_time += q
        else:
            elapsed_time += time
            print('{} {}'.format(process, str(elapsed_time)))
            
    return


main()
