# coding: utf-8
from collections import deque
n, quantum = [int(i) for i in input().split()]
dq = deque()
for i in range(n):
    p, time = [str(i) for i in input().split()]
    dq.append([p, int(time)])
time = 0
while(len(dq) != 0):
    #引き算処理
    #処理が終了しない場合
    if dq[0][1] > quantum:
        dq[0][1] -= quantum
        dq.rotate(-1)
        time += quantum
    #処理が終了する場合
    else:
        time += dq[0][1]
        print("{} {}".format(dq[0][0], time))
        dq.popleft() from collections import deque 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, quantum = [int(i) for i in input().split()] n [int(i) for i in input().split()] quantum dq = deque() dq deque() deque for i in range(n):
    p, time = [str(i) for i in input().split()]
    dq.append([p, int(time)]) i range(n) range n str(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() str(i) str i p, time = [str(i) for i in input().split()] p [str(i) for i in input().split()] time dq.append([p, int(time)]) dq.append dq append [p, int(time)] p int(time) int time time = 0 time 0 while(len(dq) != 0):
    #引き算処理
    #処理が終了しない場合
    if dq[0][1] > quantum:
        dq[0][1] -= quantum
        dq.rotate(-1)
        time += quantum
    #処理が終了する場合
    else:
        time += dq[0][1]
        print("{} {}".format(dq[0][0], time))
        dq.popleft() len(dq) != 0 len(dq) len dq 0 if dq[0][1] > quantum:
        dq[0][1] -= quantum
        dq.rotate(-1)
        time += quantum
    #処理が終了する場合
    else:
        time += dq[0][1]
        print("{} {}".format(dq[0][0], time))
        dq.popleft() dq[0][1] > quantum dq[0][1] [0] dq 0 1 quantum dq[0][1] -= quantum dq[0][1] [0] dq 0 1 quantum dq.rotate(-1) dq.rotate dq rotate -1 time += quantum time quantum time += dq[0][1] time dq[0][1] [0] dq 0 1 print("{} {}".format(dq[0][0], time)) print "{} {}".format(dq[0][0], time) "{} {}".format "{} {}" format dq[0][0] [0] dq 0 0 time dq.popleft() dq.popleft dq popleft time = 0 0 time time += quantum quantum time n, quantum = [int(i) for i in input().split()] [int(i) for i in input().split()] n quantum = [int(i) for i in input().split()] [int(i) for i in input().split()] quantum p, time = [str(i) for i in input().split()] [str(i) for i in input().split()] p dq = deque() deque() dq time = [str(i) for i in input().split()] [str(i) for i in input().split()] time time += dq[0][1] dq[0][1] time
# coding: utf-8
from collections import deque
n, quantum = [int(i) for i in input().split()]
dq = deque()
for i in range(n):
    p, time = [str(i) for i in input().split()]
    dq.append([p, int(time)])
time = 0
while(len(dq) != 0):
    #引き算処理
    #処理が終了しない場合
    if dq[0][1] > quantum:
        dq[0][1] -= quantum
        dq.rotate(-1)
        time += quantum
    #処理が終了する場合
    else:
        time += dq[0][1]
        print("{} {}".format(dq[0][0], time))
        dq.popleft()