def main() :
    n, q = [int(i) for i in input().split()]
    names = []
    times = []
    elapsed_time = 0
    for i in range(n) :
        inp = input().split()
        names.append(inp[0])
        times.append(int(inp[1]))


    while len(names) != 0 :
        if times[0] > q :
            tmp1 = names.pop(0)
            names.append(tmp1)
            tmp2 = times.pop(0) - q
            times.append(tmp2)
            elapsed_time += q
        else :
            tmp = names.pop(0)
            elapsed_time += times[0]
            times.pop(0)
            print(tmp, elapsed_time)


if __name__ == '__main__' :
    main() def main() :
    n, q = [int(i) for i in input().split()]
    names = []
    times = []
    elapsed_time = 0
    for i in range(n) :
        inp = input().split()
        names.append(inp[0])
        times.append(int(inp[1]))


    while len(names) != 0 :
        if times[0] > q :
            tmp1 = names.pop(0)
            names.append(tmp1)
            tmp2 = times.pop(0) - q
            times.append(tmp2)
            elapsed_time += q
        else :
            tmp = names.pop(0)
            elapsed_time += times[0]
            times.pop(0)
            print(tmp, elapsed_time) main int(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() int(i) int i n, q = [int(i) for i in input().split()] n [int(i) for i in input().split()] q names = [] names [] times = [] times [] elapsed_time = 0 elapsed_time 0 for i in range(n) :
        inp = input().split()
        names.append(inp[0])
        times.append(int(inp[1]))


     i range(n) range n inp = input().split() inp input().split() ().split () input split names.append(inp[0]) names.append names append inp[0] inp 0 times.append(int(inp[1])) times.append times append int(inp[1]) int inp[1] inp 1 while len(names) != 0 :
        if times[0] > q :
            tmp1 = names.pop(0)
            names.append(tmp1)
            tmp2 = times.pop(0) - q
            times.append(tmp2)
            elapsed_time += q
        else :
            tmp = names.pop(0)
            elapsed_time += times[0]
            times.pop(0)
            print(tmp, elapsed_time) len(names) != 0 len(names) len names 0 if times[0] > q :
            tmp1 = names.pop(0)
            names.append(tmp1)
            tmp2 = times.pop(0) - q
            times.append(tmp2)
            elapsed_time += q
        else :
            tmp = names.pop(0)
            elapsed_time += times[0]
            times.pop(0)
            print(tmp, elapsed_time) times[0] > q times[0] times 0 q tmp1 = names.pop(0) tmp1 names.pop(0) names.pop names pop 0 names.append(tmp1) names.append names append tmp1 tmp2 = times.pop(0) - q tmp2 times.pop(0) - q times.pop(0) times.pop times pop 0 q times.append(tmp2) times.append times append tmp2 elapsed_time += q elapsed_time q tmp = names.pop(0) tmp names.pop(0) names.pop names pop 0 elapsed_time += times[0] elapsed_time times[0] times 0 times.pop(0) times.pop times pop 0 print(tmp, elapsed_time) print tmp elapsed_time if __name__ == '__main__' :
    main() __name__ == '__main__' __name__ '__main__' main() main def main() :
    n, q = [int(i) for i in input().split()]
    names = []
    times = []
    elapsed_time = 0
    for i in range(n) :
        inp = input().split()
        names.append(inp[0])
        times.append(int(inp[1]))


    while len(names) != 0 :
        if times[0] > q :
            tmp1 = names.pop(0)
            names.append(tmp1)
            tmp2 = times.pop(0) - q
            times.append(tmp2)
            elapsed_time += q
        else :
            tmp = names.pop(0)
            elapsed_time += times[0]
            times.pop(0)
            print(tmp, elapsed_time) def main() :
    n, q = [int(i) for i in input().split()]
    names = []
    times = []
    elapsed_time = 0
    for i in range(n) :
        inp = input().split()
        names.append(inp[0])
        times.append(int(inp[1]))


    while len(names) != 0 :
        if times[0] > q :
            tmp1 = names.pop(0)
            names.append(tmp1)
            tmp2 = times.pop(0) - q
            times.append(tmp2)
            elapsed_time += q
        else :
            tmp = names.pop(0)
            elapsed_time += times[0]
            times.pop(0)
            print(tmp, elapsed_time) main
def main() :
    n, q = [int(i) for i in input().split()]
    names = []
    times = []
    elapsed_time = 0
    for i in range(n) :
        inp = input().split()
        names.append(inp[0])
        times.append(int(inp[1]))


    while len(names) != 0 :
        if times[0] > q :
            tmp1 = names.pop(0)
            names.append(tmp1)
            tmp2 = times.pop(0) - q
            times.append(tmp2)
            elapsed_time += q
        else :
            tmp = names.pop(0)
            elapsed_time += times[0]
            times.pop(0)
            print(tmp, elapsed_time)


if __name__ == '__main__' :
    main()