# ALDS1_3_B
# coding: utf-8

from collections import deque

n, q = [int(i) for i in raw_input().split()]
d = deque()
for i in range(n):
    name, time = raw_input().split()
    time = int(time)
    d.append([name, time])

total = 0
while len(d) > 0:
    p = d.popleft()
    if p[1] <= q: # 終わり
        total += p[1]
        print "{} {}".format(p[0], total)
    else:
        total += q
        p[1] -= q
        d.append(p) from collections import deque int(i) for i in raw_input().split() for i in raw_input().split() i raw_input().split() ().split () raw_input split for i in raw_input().split() int(i) int i n, q = [int(i) for i in raw_input().split()] n [int(i) for i in raw_input().split()] q d = deque() d deque() deque for i in range(n):
    name, time = raw_input().split()
    time = int(time)
    d.append([name, time]) i range(n) range n name, time = raw_input().split() name raw_input().split() ().split () raw_input split time time = int(time) time int(time) int time d.append([name, time]) d.append d append [name, time] name time total = 0 total 0 while len(d) > 0:
    p = d.popleft()
    if p[1] <= q: # 終わり
        total += p[1]
        print "{} {}".format(p[0], total)
    else:
        total += q
        p[1] -= q
        d.append(p) len(d) > 0 len(d) len d 0 p = d.popleft() p d.popleft() d.popleft d popleft if p[1] <= q: # 終わり
        total += p[1]
        print "{} {}".format(p[0], total)
    else:
        total += q
        p[1] -= q
        d.append(p) p[1] <= q p[1] p 1 q total += p[1] total p[1] p 1 print "{} {}".format(p[0], total) "{} {}".format "{} {}" format p[0] p 0 total total += q total q p[1] -= q p[1] p 1 q d.append(p) d.append d append p time = raw_input().split() raw_input().split() time p = d.popleft() d.popleft() p n, q = [int(i) for i in raw_input().split()] [int(i) for i in raw_input().split()] n name, time = raw_input().split() raw_input().split() name q = [int(i) for i in raw_input().split()] [int(i) for i in raw_input().split()] q total += p[1] p[1] total total += q q total time = int(time) int(time) time d = deque() deque() d total = 0 0 total
# ALDS1_3_B
# coding: utf-8

from collections import deque

n, q = [int(i) for i in raw_input().split()]
d = deque()
for i in range(n):
    name, time = raw_input().split()
    time = int(time)
    d.append([name, time])

total = 0
while len(d) > 0:
    p = d.popleft()
    if p[1] <= q: # 終わり
        total += p[1]
        print "{} {}".format(p[0], total)
    else:
        total += q
        p[1] -= q
        d.append(p)
