#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import collections


class Process(object):

    def __init__(self, name, time):
        self.name = name
        self.time = int(time)


def schedule(processes, quantum):
    queue = collections.deque(processes)
    time = 0
    while len(queue) > 0:
        p = queue.popleft()
        rest_time = p.time - quantum
        if rest_time > 0:
            time += quantum
            queue.append(Process(p.name, rest_time))
        else:
            time += p.time
            print("{name} {time:d}".format(name=p.name, time=time))


def main():
    [n, q] = list(map(int, input().split()))
    processes = [Process(*input().split()) for i in range(n)]
    schedule(processes, q)


if __name__ == "__main__":
    main() import collections collections class Process(object):

    def __init__(self, name, time):
        self.name = name
        self.time = int(time) Process def __init__(self, name, time):
        self.name = name
        self.time = int(time) __init__ self.name = name self.name self name name self.time = int(time) self.time self time int(time) int time self self name name time time object def schedule(processes, quantum):
    queue = collections.deque(processes)
    time = 0
    while len(queue) > 0:
        p = queue.popleft()
        rest_time = p.time - quantum
        if rest_time > 0:
            time += quantum
            queue.append(Process(p.name, rest_time))
        else:
            time += p.time
            print("{name} {time:d}".format(name=p.name, time=time)) schedule queue = collections.deque(processes) queue collections.deque(processes) collections.deque collections deque processes time = 0 time 0 while len(queue) > 0:
        p = queue.popleft()
        rest_time = p.time - quantum
        if rest_time > 0:
            time += quantum
            queue.append(Process(p.name, rest_time))
        else:
            time += p.time
            print("{name} {time:d}".format(name=p.name, time=time)) len(queue) > 0 len(queue) len queue 0 p = queue.popleft() p queue.popleft() queue.popleft queue popleft rest_time = p.time - quantum rest_time p.time - quantum p.time p time quantum if rest_time > 0:
            time += quantum
            queue.append(Process(p.name, rest_time))
        else:
            time += p.time
            print("{name} {time:d}".format(name=p.name, time=time)) rest_time > 0 rest_time 0 time += quantum time quantum queue.append(Process(p.name, rest_time)) queue.append queue append Process(p.name, rest_time) Process p.name p name rest_time time += p.time time p.time p time print("{name} {time:d}".format(name=p.name, time=time)) print "{name} {time:d}".format(name=p.name, time=time) "{name} {time:d}".format "{name} {time:d}" format name=p.name name p.name p name time=time time time processes processes quantum quantum def main():
    [n, q] = list(map(int, input().split()))
    processes = [Process(*input().split()) for i in range(n)]
    schedule(processes, q) main [n, q] = list(map(int, input().split())) [n, q] n q list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split Process(*input().split()) for i in range(n) for i in range(n) i range(n) range n for i in range(n) Process(*input().split()) Process *input().split() input().split() ().split () input split processes = [Process(*input().split()) for i in range(n)] processes [Process(*input().split()) for i in range(n)] schedule(processes, q) schedule processes q if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main def main():
    [n, q] = list(map(int, input().split()))
    processes = [Process(*input().split()) for i in range(n)]
    schedule(processes, q) def main():
    [n, q] = list(map(int, input().split()))
    processes = [Process(*input().split()) for i in range(n)]
    schedule(processes, q) main def schedule(processes, quantum):
    queue = collections.deque(processes)
    time = 0
    while len(queue) > 0:
        p = queue.popleft()
        rest_time = p.time - quantum
        if rest_time > 0:
            time += quantum
            queue.append(Process(p.name, rest_time))
        else:
            time += p.time
            print("{name} {time:d}".format(name=p.name, time=time)) def schedule(processes, quantum):
    queue = collections.deque(processes)
    time = 0
    while len(queue) > 0:
        p = queue.popleft()
        rest_time = p.time - quantum
        if rest_time > 0:
            time += quantum
            queue.append(Process(p.name, rest_time))
        else:
            time += p.time
            print("{name} {time:d}".format(name=p.name, time=time)) schedule class Process(object):

    def __init__(self, name, time):
        self.name = name
        self.time = int(time) class Process(object):

    def __init__(self, name, time):
        self.name = name
        self.time = int(time) Process
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import collections


class Process(object):

    def __init__(self, name, time):
        self.name = name
        self.time = int(time)


def schedule(processes, quantum):
    queue = collections.deque(processes)
    time = 0
    while len(queue) > 0:
        p = queue.popleft()
        rest_time = p.time - quantum
        if rest_time > 0:
            time += quantum
            queue.append(Process(p.name, rest_time))
        else:
            time += p.time
            print("{name} {time:d}".format(name=p.name, time=time))


def main():
    [n, q] = list(map(int, input().split()))
    processes = [Process(*input().split()) for i in range(n)]
    schedule(processes, q)


if __name__ == "__main__":
    main()