import queue
n, q = map(int, input().split(" "))
plist = queue.Queue()
for i in range(n):
    plist.put((lambda l: [l[0], int(l[1])])(input().split(" ")))
time = 0
history = queue.Queue()
while not plist.empty():
    p = plist.get()
    if p[1] <= q:
        time += p[1]
        history.put([p[0], time])
    else:
        p[1] -= q
        plist.put(p)
        time += q
while not history.empty():
    p = history.get()
    print("%s %d" % (p[0], p[1])) import queue queue n, q = map(int, input().split(" ")) n map(int, input().split(" ")) map int input().split(" ") ().split () input split " " q plist = queue.Queue() plist queue.Queue() queue.Queue queue Queue for i in range(n):
    plist.put((lambda l: [l[0], int(l[1])])(input().split(" "))) i range(n) range n plist.put((lambda l: [l[0], int(l[1])])(input().split(" "))) plist.put plist put (lambda l: [l[0], int(l[1])])(input().split(" ")) lambda l: [l[0], int(l[1])] [l[0], int(l[1])] l[0] l 0 int(l[1]) int l[1] l 1 l input().split(" ") ().split () input split " " time = 0 time 0 history = queue.Queue() history queue.Queue() queue.Queue queue Queue while not plist.empty():
    p = plist.get()
    if p[1] <= q:
        time += p[1]
        history.put([p[0], time])
    else:
        p[1] -= q
        plist.put(p)
        time += q not plist.empty() plist.empty() plist.empty plist empty p = plist.get() p plist.get() plist.get plist get if p[1] <= q:
        time += p[1]
        history.put([p[0], time])
    else:
        p[1] -= q
        plist.put(p)
        time += q p[1] <= q p[1] p 1 q time += p[1] time p[1] p 1 history.put([p[0], time]) history.put history put [p[0], time] p[0] p 0 time p[1] -= q p[1] p 1 q plist.put(p) plist.put plist put p time += q time q while not history.empty():
    p = history.get()
    print("%s %d" % (p[0], p[1])) not history.empty() history.empty() history.empty history empty p = history.get() p history.get() history.get history get print("%s %d" % (p[0], p[1])) print "%s %d" % (p[0], p[1]) "%s %d" (p[0], p[1]) p[0] p 0 p[1] p 1 n, q = map(int, input().split(" ")) map(int, input().split(" ")) n q = map(int, input().split(" ")) map(int, input().split(" ")) q p = history.get() history.get() p plist = queue.Queue() queue.Queue() plist history = queue.Queue() queue.Queue() history time = 0 0 time p = plist.get() plist.get() p time += p[1] p[1] time time += q q time
import queue
n, q = map(int, input().split(" "))
plist = queue.Queue()
for i in range(n):
    plist.put((lambda l: [l[0], int(l[1])])(input().split(" ")))
time = 0
history = queue.Queue()
while not plist.empty():
    p = plist.get()
    if p[1] <= q:
        time += p[1]
        history.put([p[0], time])
    else:
        p[1] -= q
        plist.put(p)
        time += q
while not history.empty():
    p = history.get()
    print("%s %d" % (p[0], p[1]))