class Process:
    def __init__(self, data):
        self.name = data[0]
        self.time = int(data[1])

    def process(self, quantum):
        if self.time <= quantum:
            time, self.time = self.time, 0
            return time

        self.time -= quantum
        return quantum

    def isProcessed(self):
        return self.time == 0

    def getName(self):
        return self.name

def main():
    n, q = map(int, input().split())

    queue = []
    for _ in range(n):
        queue.append(Process(input().split()))

    elapsed = 0
    while len(queue) > 0:
        p = queue.pop(0)
        elapsed += p.process(q)

        if p.isProcessed():
            print('{} {}'.format(p.getName(), elapsed))
        else:
            queue.append(p)

if __name__ == '__main__':
    main()
 class Process:
    def __init__(self, data):
        self.name = data[0]
        self.time = int(data[1])

    def process(self, quantum):
        if self.time <= quantum:
            time, self.time = self.time, 0
            return time

        self.time -= quantum
        return quantum

    def isProcessed(self):
        return self.time == 0

    def getName(self):
        return self.name Process def __init__(self, data):
        self.name = data[0]
        self.time = int(data[1])

     __init__ self.name = data[0] self.name self name data[0] data 0 self.time = int(data[1]) self.time self time int(data[1]) int data[1] data 1 self self data data def process(self, quantum):
        if self.time <= quantum:
            time, self.time = self.time, 0
            return time

        self.time -= quantum
        return quantum

     process if self.time <= quantum:
            time, self.time = self.time, 0
            return time

         self.time <= quantum self.time self time quantum time, self.time = self.time, 0 time self.time self time self.time self time 0 return time time self.time -= quantum self.time self time quantum return quantum quantum self self quantum quantum def isProcessed(self):
        return self.time == 0

     isProcessed return self.time == 0 self.time == 0 self.time self time 0 self self def getName(self):
        return self.name getName return self.name self.name self name self self def main():
    n, q = map(int, input().split())

    queue = []
    for _ in range(n):
        queue.append(Process(input().split()))

    elapsed = 0
    while len(queue) > 0:
        p = queue.pop(0)
        elapsed += p.process(q)

        if p.isProcessed():
            print('{} {}'.format(p.getName(), elapsed))
        else:
            queue.append(p) main n, q = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split q queue = [] queue [] for _ in range(n):
        queue.append(Process(input().split()))

     _ range(n) range n queue.append(Process(input().split())) queue.append queue append Process(input().split()) Process input().split() ().split () input split elapsed = 0 elapsed 0 while len(queue) > 0:
        p = queue.pop(0)
        elapsed += p.process(q)

        if p.isProcessed():
            print('{} {}'.format(p.getName(), elapsed))
        else:
            queue.append(p) len(queue) > 0 len(queue) len queue 0 p = queue.pop(0) p queue.pop(0) queue.pop queue pop 0 elapsed += p.process(q) elapsed p.process(q) p.process p process q if p.isProcessed():
            print('{} {}'.format(p.getName(), elapsed))
        else:
            queue.append(p) p.isProcessed() p.isProcessed p isProcessed print('{} {}'.format(p.getName(), elapsed)) print '{} {}'.format(p.getName(), elapsed) '{} {}'.format '{} {}' format p.getName() p.getName p getName elapsed queue.append(p) queue.append queue append p if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main class Process:
    def __init__(self, data):
        self.name = data[0]
        self.time = int(data[1])

    def process(self, quantum):
        if self.time <= quantum:
            time, self.time = self.time, 0
            return time

        self.time -= quantum
        return quantum

    def isProcessed(self):
        return self.time == 0

    def getName(self):
        return self.name class Process:
    def __init__(self, data):
        self.name = data[0]
        self.time = int(data[1])

    def process(self, quantum):
        if self.time <= quantum:
            time, self.time = self.time, 0
            return time

        self.time -= quantum
        return quantum

    def isProcessed(self):
        return self.time == 0

    def getName(self):
        return self.name Process def main():
    n, q = map(int, input().split())

    queue = []
    for _ in range(n):
        queue.append(Process(input().split()))

    elapsed = 0
    while len(queue) > 0:
        p = queue.pop(0)
        elapsed += p.process(q)

        if p.isProcessed():
            print('{} {}'.format(p.getName(), elapsed))
        else:
            queue.append(p) def main():
    n, q = map(int, input().split())

    queue = []
    for _ in range(n):
        queue.append(Process(input().split()))

    elapsed = 0
    while len(queue) > 0:
        p = queue.pop(0)
        elapsed += p.process(q)

        if p.isProcessed():
            print('{} {}'.format(p.getName(), elapsed))
        else:
            queue.append(p) main
class Process:
    def __init__(self, data):
        self.name = data[0]
        self.time = int(data[1])

    def process(self, quantum):
        if self.time <= quantum:
            time, self.time = self.time, 0
            return time

        self.time -= quantum
        return quantum

    def isProcessed(self):
        return self.time == 0

    def getName(self):
        return self.name

def main():
    n, q = map(int, input().split())

    queue = []
    for _ in range(n):
        queue.append(Process(input().split()))

    elapsed = 0
    while len(queue) > 0:
        p = queue.pop(0)
        elapsed += p.process(q)

        if p.isProcessed():
            print('{} {}'.format(p.getName(), elapsed))
        else:
            queue.append(p)

if __name__ == '__main__':
    main()

