n, q = [int(i) for i in input().split()]

name = []
time = []

for i in range(n):
    x, y = [i for i in input().split()]
    y = int(y)
    name.append(x)
    time.append(y)

from collections import deque
time = deque(time)
name = deque(name)

count = 0
time_out = []
name_out = []

while len(time) > 0:
    a = time.popleft()
    b = name.popleft()
    if a > q:
        a -= q
        time.append(a)
        name.append(b)
        count += q
    else:
        count += a
        time_out.append(count)
        name_out.append(b)

for i, j in zip(name_out, time_out):
    print(i, j)
 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, q = [int(i) for i in input().split()] n [int(i) for i in input().split()] q name = [] name [] time = [] time [] for i in range(n):
    x, y = [i for i in input().split()]
    y = int(y)
    name.append(x)
    time.append(y) i range(n) range n i for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() i x, y = [i for i in input().split()] x [i for i in input().split()] y y = int(y) y int(y) int y name.append(x) name.append name append x time.append(y) time.append time append y from collections import deque time = deque(time) time deque(time) deque time name = deque(name) name deque(name) deque name count = 0 count 0 time_out = [] time_out [] name_out = [] name_out [] while len(time) > 0:
    a = time.popleft()
    b = name.popleft()
    if a > q:
        a -= q
        time.append(a)
        name.append(b)
        count += q
    else:
        count += a
        time_out.append(count)
        name_out.append(b) len(time) > 0 len(time) len time 0 a = time.popleft() a time.popleft() time.popleft time popleft b = name.popleft() b name.popleft() name.popleft name popleft if a > q:
        a -= q
        time.append(a)
        name.append(b)
        count += q
    else:
        count += a
        time_out.append(count)
        name_out.append(b) a > q a q a -= q a q time.append(a) time.append time append a name.append(b) name.append name append b count += q count q count += a count a time_out.append(count) time_out.append time_out append count name_out.append(b) name_out.append name_out append b for i, j in zip(name_out, time_out):
    print(i, j) i j zip(name_out, time_out) zip name_out time_out print(i, j) print i j name = deque(name) deque(name) name b = name.popleft() name.popleft() b time_out = [] [] time_out time = deque(time) deque(time) time count += a a count time = [] [] time x, y = [i for i in input().split()] [i for i in input().split()] x y = [i for i in input().split()] [i for i in input().split()] y n, q = [int(i) for i in input().split()] [int(i) for i in input().split()] n a = time.popleft() time.popleft() a name_out = [] [] name_out q = [int(i) for i in input().split()] [int(i) for i in input().split()] q a -= q q a count += q q count y = int(y) int(y) y name = [] [] name count = 0 0 count
n, q = [int(i) for i in input().split()]

name = []
time = []

for i in range(n):
    x, y = [i for i in input().split()]
    y = int(y)
    name.append(x)
    time.append(y)

from collections import deque
time = deque(time)
name = deque(name)

count = 0
time_out = []
name_out = []

while len(time) > 0:
    a = time.popleft()
    b = name.popleft()
    if a > q:
        a -= q
        time.append(a)
        name.append(b)
        count += q
    else:
        count += a
        time_out.append(count)
        name_out.append(b)

for i, j in zip(name_out, time_out):
    print(i, j)

