from collections import deque

n,q = tuple([int(i) for i in input().split()])
lines = [input().split() for i in range(n)]
pro = deque([[i[0], int(i[1])] for i in lines])
time = 0

while True:
    left = pro.popleft()

    if left[1] - q > 0:
        time += q
        pro.append([left[0], left[1] - q])
    else:
        time += left[1]
        print(' '.join([left[0], str(time)]))

    if len(pro) == 0:
        break; 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,q = tuple([int(i) for i in input().split()]) n tuple([int(i) for i in input().split()]) tuple [int(i) for i in input().split()] q input().split() for i in range(n) for i in range(n) i range(n) range n for i in range(n) input().split() ().split () input split lines = [input().split() for i in range(n)] lines [input().split() for i in range(n)] [i[0], int(i[1])] for i in lines for i in lines i lines for i in lines [i[0], int(i[1])] i[0] i 0 int(i[1]) int i[1] i 1 pro = deque([[i[0], int(i[1])] for i in lines]) pro deque([[i[0], int(i[1])] for i in lines]) deque [[i[0], int(i[1])] for i in lines] time = 0 time 0 while True:
    left = pro.popleft()

    if left[1] - q > 0:
        time += q
        pro.append([left[0], left[1] - q])
    else:
        time += left[1]
        print(' '.join([left[0], str(time)]))

    if len(pro) == 0:
        break; True left = pro.popleft() left pro.popleft() pro.popleft pro popleft if left[1] - q > 0:
        time += q
        pro.append([left[0], left[1] - q])
    else:
        time += left[1]
        print(' '.join([left[0], str(time)]))

     left[1] - q > 0 left[1] - q left[1] left 1 q 0 time += q time q pro.append([left[0], left[1] - q]) pro.append pro append [left[0], left[1] - q] left[0] left 0 left[1] - q left[1] left 1 q time += left[1] time left[1] left 1 print(' '.join([left[0], str(time)])) print ' '.join([left[0], str(time)]) ' '.join ' ' join [left[0], str(time)] left[0] left 0 str(time) str time if len(pro) == 0:
        break; len(pro) == 0 len(pro) len pro 0 break pro = deque([[i[0], int(i[1])] for i in lines]) deque([[i[0], int(i[1])] for i in lines]) pro lines = [input().split() for i in range(n)] [input().split() for i in range(n)] lines n,q = tuple([int(i) for i in input().split()]) tuple([int(i) for i in input().split()]) n time = 0 0 time time += q q time left = pro.popleft() pro.popleft() left q = tuple([int(i) for i in input().split()]) tuple([int(i) for i in input().split()]) q time += left[1] left[1] time
from collections import deque

n,q = tuple([int(i) for i in input().split()])
lines = [input().split() for i in range(n)]
pro = deque([[i[0], int(i[1])] for i in lines])
time = 0

while True:
    left = pro.popleft()

    if left[1] - q > 0:
        time += q
        pro.append([left[0], left[1] - q])
    else:
        time += left[1]
        print(' '.join([left[0], str(time)]))

    if len(pro) == 0:
        break;