n, q = list(map(int, input().split()))

data = []

for i in range(n):

    tmp = input().split()

    tmp[1] = int(tmp[1])

    data.append(tmp)



dt_out = []

time_count = 0



while len(data) > 0 :

    tmp = data.pop(0)

    if(tmp[1] <= q):

        time_count += tmp[1]

        dt_out.append([tmp[0],time_count])

    else:

        tmp[1] -= q

        time_count += q

        data.append(tmp)



for tmp in dt_out:

    print((tmp[0]+" "+str(tmp[1])))
from collections import deque



def doRoundRobin(nt,q):

    result = []



    countTime = 0



    while len(nt) > 0:

        tmp = nt.popleft()

        if tmp[1] <= q:

            countTime += tmp[1]

            result.append([tmp[0],countTime])

        else:

            tmp[1] -= q

            countTime += q

            nt.append(tmp)

    return result





if __name__ == '__main__':

    n, q = list(map(int,input().split()))

    

    nameTime = deque()

    for _ in range(n):

        a, b =  input().split()

        nameTime.append([a,(int)(b)])



    resultNameTime = doRoundRobin(nameTime,q)



    for x in resultNameTime:

        print((x[0],x[1]))
n, q = list(map(int, input().split()))
data = []
for i in range(n):
    tmp = input().split()
    tmp[1] = int(tmp[1])
    data.append(tmp)
dt_out = []
time_count = 0
while len(data) > 0:
    tmp = data.pop(0)
    if tmp[1] <= q:
        time_count += tmp[1]
        dt_out.append([tmp[0], time_count])
    else:
        tmp[1] -= q
        time_count += q
        data.append(tmp)
for tmp in dt_out:
    print((tmp[0] + " " + str(tmp[1])))

from collections import deque


def doRoundRobin(nt, q):
    result = []
    countTime = 0
    while len(nt) > 0:
        tmp = nt.popleft()
        if tmp[1] <= q:
            countTime += tmp[1]
            result.append([tmp[0], countTime])
        else:
            tmp[1] -= q
            countTime += q
            nt.append(tmp)
    return result


if __name__ == "__main__":
    n, q = list(map(int, input().split()))
    nameTime = deque()
    for _ in range(n):
        a, b = input().split()
        nameTime.append([a, (int)(b)])
    resultNameTime = doRoundRobin(nameTime, q)
    for x in resultNameTime:
        print((x[0], x[1]))

-n, q = list(map(int, input().split())) -data = [] -for i in range(n): -    tmp = input().split() -    tmp[1] = int(tmp[1]) -    data.append(tmp) -dt_out = [] -time_count = 0 -while len(data) > 0: -    tmp = data.pop(0) -    if tmp[1] <= q: -        time_count += tmp[1] -        dt_out.append([tmp[0], time_count]) -    else: -        tmp[1] -= q -        time_count += q -        data.append(tmp) -for tmp in dt_out: -    print((tmp[0] + " " + str(tmp[1]))) +from collections import deque + + +def doRoundRobin(nt, q): +    result = [] +    countTime = 0 +    while len(nt) > 0: +        tmp = nt.popleft() +        if tmp[1] <= q: +            countTime += tmp[1] +            result.append([tmp[0], countTime]) +        else: +            tmp[1] -= q +            countTime += q +            nt.append(tmp) +    return result + + +if __name__ == "__main__": +    n, q = list(map(int, input().split())) +    nameTime = deque() +    for _ in range(n): +        a, b = input().split() +        nameTime.append([a, (int)(b)]) +    resultNameTime = doRoundRobin(nameTime, q) +    for x in resultNameTime: +        print((x[0], x[1]))