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

def queue(q, ps):
    time = 0
    while len(ps) != 0:
        p = ps.pop(0)
        if p.time > q:
            p.time -= q
            time += q
            ps.append(p)
        else:
            time += p.time
            print p.name + " " + str(time)

if __name__ == "__main__":
    L = map(int, raw_input().split())
    N = L[0]
    q = L[1]
    processes = []
    for i in range(N):
        L = raw_input().split()
        processes.append(process(L[0], int(L[1])))
    queue(q, processes) class process:
    def __init__(self, name, time):
        self.name = name
        self.time = time process def __init__(self, name, time):
        self.name = name
        self.time = time __init__ self.name = name self.name self name name self.time = time self.time self time time self self name name time time def queue(q, ps):
    time = 0
    while len(ps) != 0:
        p = ps.pop(0)
        if p.time > q:
            p.time -= q
            time += q
            ps.append(p)
        else:
            time += p.time
            print p.name + " " + str(time) queue time = 0 time 0 while len(ps) != 0:
        p = ps.pop(0)
        if p.time > q:
            p.time -= q
            time += q
            ps.append(p)
        else:
            time += p.time
            print p.name + " " + str(time) len(ps) != 0 len(ps) len ps 0 p = ps.pop(0) p ps.pop(0) ps.pop ps pop 0 if p.time > q:
            p.time -= q
            time += q
            ps.append(p)
        else:
            time += p.time
            print p.name + " " + str(time) p.time > q p.time p time q p.time -= q p.time p time q time += q time q ps.append(p) ps.append ps append p time += p.time time p.time p time print p.name + " " + str(time) p.name + " " p.name p name " " str(time) str time q q ps ps if __name__ == "__main__":
    L = map(int, raw_input().split())
    N = L[0]
    q = L[1]
    processes = []
    for i in range(N):
        L = raw_input().split()
        processes.append(process(L[0], int(L[1])))
    queue(q, processes) __name__ == "__main__" __name__ "__main__" L = map(int, raw_input().split()) L map(int, raw_input().split()) map int raw_input().split() ().split () raw_input split N = L[0] N L[0] L 0 q = L[1] q L[1] L 1 processes = [] processes [] for i in range(N):
        L = raw_input().split()
        processes.append(process(L[0], int(L[1])))
     i range(N) range N L = raw_input().split() L raw_input().split() ().split () raw_input split processes.append(process(L[0], int(L[1]))) processes.append processes append process(L[0], int(L[1])) process L[0] L 0 int(L[1]) int L[1] L 1 queue(q, processes) queue q processes L = raw_input().split() raw_input().split() L class process:
    def __init__(self, name, time):
        self.name = name
        self.time = time class process:
    def __init__(self, name, time):
        self.name = name
        self.time = time process N = L[0] L[0] N def queue(q, ps):
    time = 0
    while len(ps) != 0:
        p = ps.pop(0)
        if p.time > q:
            p.time -= q
            time += q
            ps.append(p)
        else:
            time += p.time
            print p.name + " " + str(time) def queue(q, ps):
    time = 0
    while len(ps) != 0:
        p = ps.pop(0)
        if p.time > q:
            p.time -= q
            time += q
            ps.append(p)
        else:
            time += p.time
            print p.name + " " + str(time) queue L = map(int, raw_input().split()) map(int, raw_input().split()) L q = L[1] L[1] q processes = [] [] processes
class process:
    def __init__(self, name, time):
        self.name = name
        self.time = time

def queue(q, ps):
    time = 0
    while len(ps) != 0:
        p = ps.pop(0)
        if p.time > q:
            p.time -= q
            time += q
            ps.append(p)
        else:
            time += p.time
            print p.name + " " + str(time)

if __name__ == "__main__":
    L = map(int, raw_input().split())
    N = L[0]
    q = L[1]
    processes = []
    for i in range(N):
        L = raw_input().split()
        processes.append(process(L[0], int(L[1])))
    queue(q, processes)