def robin(process, q):
    if int(process[0][1]) - q > 0:
        process[0][1] = int(process[0][1]) - q
        process.append([process[0][0],process[0][1]])
        process.pop(0)
        return process, q
    else:
        q = int(process[0][1])
        process.pop(0)
        return process, q


n, q = input().split()
n, q = int(n), int(q)
process = []
for i in range(n):
    process.append([i for i in input().split()])


time = 0
while len(process) != 0:
    length = len(process)
    name = process[0][0]
    process, process_time = robin(process, q)
    time += process_time
    if length > len(process):
        print(name,time) def robin(process, q):
    if int(process[0][1]) - q > 0:
        process[0][1] = int(process[0][1]) - q
        process.append([process[0][0],process[0][1]])
        process.pop(0)
        return process, q
    else:
        q = int(process[0][1])
        process.pop(0)
        return process, q robin if int(process[0][1]) - q > 0:
        process[0][1] = int(process[0][1]) - q
        process.append([process[0][0],process[0][1]])
        process.pop(0)
        return process, q
    else:
        q = int(process[0][1])
        process.pop(0)
        return process, q int(process[0][1]) - q > 0 int(process[0][1]) - q int(process[0][1]) int process[0][1] [0] process 0 1 q 0 process[0][1] = int(process[0][1]) - q process[0][1] [0] process 0 1 int(process[0][1]) - q int(process[0][1]) int process[0][1] [0] process 0 1 q process.append([process[0][0],process[0][1]]) process.append process append [process[0][0],process[0][1]] process[0][0] [0] process 0 0 process[0][1] [0] process 0 1 process.pop(0) process.pop process pop 0 return process, q return process, q process q q = int(process[0][1]) q int(process[0][1]) int process[0][1] [0] process 0 1 process.pop(0) process.pop process pop 0 return process, q return process, q process q process process q q n, q = input().split() n input().split() ().split () input split q n, q = int(n), int(q) n int(n) int n q int(q) int q process = [] process [] for i in range(n):
    process.append([i for i in input().split()]) i range(n) range n i for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() i process.append([i for i in input().split()]) process.append process append [i for i in input().split()] time = 0 time 0 while len(process) != 0:
    length = len(process)
    name = process[0][0]
    process, process_time = robin(process, q)
    time += process_time
    if length > len(process):
        print(name,time) len(process) != 0 len(process) len process 0 length = len(process) length len(process) len process name = process[0][0] name process[0][0] [0] process 0 0 process, process_time = robin(process, q) process robin(process, q) robin process q process_time time += process_time time process_time if length > len(process):
        print(name,time) length > len(process) length len(process) len process print(name,time) print name time n, q = int(n), int(q) int(n) n process = [] [] process length = len(process) len(process) length q = input().split() input().split() q process_time = robin(process, q) robin(process, q) process_time n, q = input().split() input().split() n time = 0 0 time process, process_time = robin(process, q) robin(process, q) process name = process[0][0] process[0][0] name def robin(process, q):
    if int(process[0][1]) - q > 0:
        process[0][1] = int(process[0][1]) - q
        process.append([process[0][0],process[0][1]])
        process.pop(0)
        return process, q
    else:
        q = int(process[0][1])
        process.pop(0)
        return process, q def robin(process, q):
    if int(process[0][1]) - q > 0:
        process[0][1] = int(process[0][1]) - q
        process.append([process[0][0],process[0][1]])
        process.pop(0)
        return process, q
    else:
        q = int(process[0][1])
        process.pop(0)
        return process, q robin q = int(n), int(q) int(q) q time += process_time process_time time
def robin(process, q):
    if int(process[0][1]) - q > 0:
        process[0][1] = int(process[0][1]) - q
        process.append([process[0][0],process[0][1]])
        process.pop(0)
        return process, q
    else:
        q = int(process[0][1])
        process.pop(0)
        return process, q


n, q = input().split()
n, q = int(n), int(q)
process = []
for i in range(n):
    process.append([i for i in input().split()])


time = 0
while len(process) != 0:
    length = len(process)
    name = process[0][0]
    process, process_time = robin(process, q)
    time += process_time
    if length > len(process):
        print(name,time)