import Queue
import sys

class Proc:
    def __init__(self, name, time):
        self.time = time
        self.name = name

def main():
    array = map(lambda x: int(x), sys.stdin.readline().strip().split(" "))
    p_num = array[0]
    q_time = array[1]
    p_queue = Queue.Queue()
    for i in range(0, p_num):
        array = sys.stdin.readline().strip().split(" ")
        p_queue.put(Proc(array[0], int(array[1])))
    t = 0
    while not p_queue.empty():
        p = p_queue.get()
        if p.time > q_time:
            p.time = p.time - q_time
            p_queue.put(p)
            t += q_time
        else:
            t += p.time
            print p.name + " " + str(t)
    
if __name__ == "__main__":
    main() import Queue Queue import sys sys class Proc:
    def __init__(self, name, time):
        self.time = time
        self.name = name Proc def __init__(self, name, time):
        self.time = time
        self.name = name __init__ self.time = time self.time self time time self.name = name self.name self name name self self name name time time def main():
    array = map(lambda x: int(x), sys.stdin.readline().strip().split(" "))
    p_num = array[0]
    q_time = array[1]
    p_queue = Queue.Queue()
    for i in range(0, p_num):
        array = sys.stdin.readline().strip().split(" ")
        p_queue.put(Proc(array[0], int(array[1])))
    t = 0
    while not p_queue.empty():
        p = p_queue.get()
        if p.time > q_time:
            p.time = p.time - q_time
            p_queue.put(p)
            t += q_time
        else:
            t += p.time
            print p.name + " " + str(t)
     main array = map(lambda x: int(x), sys.stdin.readline().strip().split(" ")) array map(lambda x: int(x), sys.stdin.readline().strip().split(" ")) map lambda x: int(x) int(x) int x x sys.stdin.readline().strip().split(" ") sys.stdin.readline().strip().split sys.stdin.readline().strip() sys.stdin.readline().strip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline strip split " " p_num = array[0] p_num array[0] array 0 q_time = array[1] q_time array[1] array 1 p_queue = Queue.Queue() p_queue Queue.Queue() Queue.Queue Queue Queue for i in range(0, p_num):
        array = sys.stdin.readline().strip().split(" ")
        p_queue.put(Proc(array[0], int(array[1])))
     i range(0, p_num) range 0 p_num array = sys.stdin.readline().strip().split(" ") array sys.stdin.readline().strip().split(" ") sys.stdin.readline().strip().split sys.stdin.readline().strip() sys.stdin.readline().strip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline strip split " " p_queue.put(Proc(array[0], int(array[1]))) p_queue.put p_queue put Proc(array[0], int(array[1])) Proc array[0] array 0 int(array[1]) int array[1] array 1 t = 0 t 0 while not p_queue.empty():
        p = p_queue.get()
        if p.time > q_time:
            p.time = p.time - q_time
            p_queue.put(p)
            t += q_time
        else:
            t += p.time
            print p.name + " " + str(t)
     not p_queue.empty() p_queue.empty() p_queue.empty p_queue empty p = p_queue.get() p p_queue.get() p_queue.get p_queue get if p.time > q_time:
            p.time = p.time - q_time
            p_queue.put(p)
            t += q_time
        else:
            t += p.time
            print p.name + " " + str(t)
     p.time > q_time p.time p time q_time p.time = p.time - q_time p.time p time p.time - q_time p.time p time q_time p_queue.put(p) p_queue.put p_queue put p t += q_time t q_time t += p.time t p.time p time print p.name + " " + str(t) p.name + " " p.name p name " " str(t) str t if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main class Proc:
    def __init__(self, name, time):
        self.time = time
        self.name = name class Proc:
    def __init__(self, name, time):
        self.time = time
        self.name = name Proc def main():
    array = map(lambda x: int(x), sys.stdin.readline().strip().split(" "))
    p_num = array[0]
    q_time = array[1]
    p_queue = Queue.Queue()
    for i in range(0, p_num):
        array = sys.stdin.readline().strip().split(" ")
        p_queue.put(Proc(array[0], int(array[1])))
    t = 0
    while not p_queue.empty():
        p = p_queue.get()
        if p.time > q_time:
            p.time = p.time - q_time
            p_queue.put(p)
            t += q_time
        else:
            t += p.time
            print p.name + " " + str(t)
     def main():
    array = map(lambda x: int(x), sys.stdin.readline().strip().split(" "))
    p_num = array[0]
    q_time = array[1]
    p_queue = Queue.Queue()
    for i in range(0, p_num):
        array = sys.stdin.readline().strip().split(" ")
        p_queue.put(Proc(array[0], int(array[1])))
    t = 0
    while not p_queue.empty():
        p = p_queue.get()
        if p.time > q_time:
            p.time = p.time - q_time
            p_queue.put(p)
            t += q_time
        else:
            t += p.time
            print p.name + " " + str(t)
     main
import Queue
import sys

class Proc:
    def __init__(self, name, time):
        self.time = time
        self.name = name

def main():
    array = map(lambda x: int(x), sys.stdin.readline().strip().split(" "))
    p_num = array[0]
    q_time = array[1]
    p_queue = Queue.Queue()
    for i in range(0, p_num):
        array = sys.stdin.readline().strip().split(" ")
        p_queue.put(Proc(array[0], int(array[1])))
    t = 0
    while not p_queue.empty():
        p = p_queue.get()
        if p.time > q_time:
            p.time = p.time - q_time
            p_queue.put(p)
            t += q_time
        else:
            t += p.time
            print p.name + " " + str(t)
    
if __name__ == "__main__":
    main()