n,q = map(int,input().split())
process = []
for i in range(n):
    name,time = input().split()
    process.append([name,int(time)])
elap = 0
out = []
while len(process) > 0:
    name,time = process.pop(0)
    temp_q = q
    while True:
        if time <= 0:
            out.append([name,elap])
            break
        if temp_q <= 0:
            process.append([name,time])
            break
        time -= 1
        temp_q -= 1
        elap += 1
for name,time in out:
    print(name,time) n,q = map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split q process = [] process [] for i in range(n):
    name,time = input().split()
    process.append([name,int(time)]) i range(n) range n name,time = input().split() name input().split() ().split () input split time process.append([name,int(time)]) process.append process append [name,int(time)] name int(time) int time elap = 0 elap 0 out = [] out [] while len(process) > 0:
    name,time = process.pop(0)
    temp_q = q
    while True:
        if time <= 0:
            out.append([name,elap])
            break
        if temp_q <= 0:
            process.append([name,time])
            break
        time -= 1
        temp_q -= 1
        elap += 1 len(process) > 0 len(process) len process 0 name,time = process.pop(0) name process.pop(0) process.pop process pop 0 time temp_q = q temp_q q while True:
        if time <= 0:
            out.append([name,elap])
            break
        if temp_q <= 0:
            process.append([name,time])
            break
        time -= 1
        temp_q -= 1
        elap += 1 True if time <= 0:
            out.append([name,elap])
            break
         time <= 0 time 0 out.append([name,elap]) out.append out append [name,elap] name elap break if temp_q <= 0:
            process.append([name,time])
            break
         temp_q <= 0 temp_q 0 process.append([name,time]) process.append process append [name,time] name time break time -= 1 time 1 temp_q -= 1 temp_q 1 elap += 1 elap 1 for name,time in out:
    print(name,time) name time out print(name,time) print name time n,q = map(int,input().split()) map(int,input().split()) n name,time = process.pop(0) process.pop(0) name elap = 0 0 elap name,time = input().split() input().split() name out = [] [] out temp_q = q q temp_q elap += 1 1 elap q = map(int,input().split()) map(int,input().split()) q process = [] [] process temp_q -= 1 1 temp_q time = input().split() input().split() time time = process.pop(0) process.pop(0) time time -= 1 1 time
n,q = map(int,input().split())
process = []
for i in range(n):
    name,time = input().split()
    process.append([name,int(time)])
elap = 0
out = []
while len(process) > 0:
    name,time = process.pop(0)
    temp_q = q
    while True:
        if time <= 0:
            out.append([name,elap])
            break
        if temp_q <= 0:
            process.append([name,time])
            break
        time -= 1
        temp_q -= 1
        elap += 1
for name,time in out:
    print(name,time)
