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

def main():
    n, q = map(int, raw_input().split())
    p = list()
    for i in range(n):
        name, time = raw_input().split()
        p.append(process(name, int(time)))

    s = 0
    while len(p) > 0:
        e = p.pop(0)
        if e.time - q <= 0:
            s += e.time
            print(e.name + " " + str(s))
        else:
            s += q
            e.time -= q
            p.append(e)

main() 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 main():
    n, q = map(int, raw_input().split())
    p = list()
    for i in range(n):
        name, time = raw_input().split()
        p.append(process(name, int(time)))

    s = 0
    while len(p) > 0:
        e = p.pop(0)
        if e.time - q <= 0:
            s += e.time
            print(e.name + " " + str(s))
        else:
            s += q
            e.time -= q
            p.append(e) main n, q = map(int, raw_input().split()) n map(int, raw_input().split()) map int raw_input().split() ().split () raw_input split q p = list() p list() list for i in range(n):
        name, time = raw_input().split()
        p.append(process(name, int(time)))

     i range(n) range n name, time = raw_input().split() name raw_input().split() ().split () raw_input split time p.append(process(name, int(time))) p.append p append process(name, int(time)) process name int(time) int time s = 0 s 0 while len(p) > 0:
        e = p.pop(0)
        if e.time - q <= 0:
            s += e.time
            print(e.name + " " + str(s))
        else:
            s += q
            e.time -= q
            p.append(e) len(p) > 0 len(p) len p 0 e = p.pop(0) e p.pop(0) p.pop p pop 0 if e.time - q <= 0:
            s += e.time
            print(e.name + " " + str(s))
        else:
            s += q
            e.time -= q
            p.append(e) e.time - q <= 0 e.time - q e.time e time q 0 s += e.time s e.time e time print(e.name + " " + str(s)) print e.name + " " + str(s) e.name + " " e.name e name " " str(s) str s s += q s q e.time -= q e.time e time q p.append(e) p.append p append e main() main def main():
    n, q = map(int, raw_input().split())
    p = list()
    for i in range(n):
        name, time = raw_input().split()
        p.append(process(name, int(time)))

    s = 0
    while len(p) > 0:
        e = p.pop(0)
        if e.time - q <= 0:
            s += e.time
            print(e.name + " " + str(s))
        else:
            s += q
            e.time -= q
            p.append(e) def main():
    n, q = map(int, raw_input().split())
    p = list()
    for i in range(n):
        name, time = raw_input().split()
        p.append(process(name, int(time)))

    s = 0
    while len(p) > 0:
        e = p.pop(0)
        if e.time - q <= 0:
            s += e.time
            print(e.name + " " + str(s))
        else:
            s += q
            e.time -= q
            p.append(e) main 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
class process:
    def __init__(self, name, time):
        self.name = name
        self.time = time

def main():
    n, q = map(int, raw_input().split())
    p = list()
    for i in range(n):
        name, time = raw_input().split()
        p.append(process(name, int(time)))

    s = 0
    while len(p) > 0:
        e = p.pop(0)
        if e.time - q <= 0:
            s += e.time
            print(e.name + " " + str(s))
        else:
            s += q
            e.time -= q
            p.append(e)

main()