from collections import deque

n, q = map(int, input().split())
p_que = deque([])

for _ in range(n):
    name, t = map(str, input().split())
    p_que.append([name, int(t)])

sum_time = 0
while True:
    p = p_que.popleft()
    if p[1] <= q:
        sum_time += p[1]
        print(p[0], sum_time)
    else:
        sum_time += q
        p[1] -= q
        p_que.append(p)
    if len(p_que) == 0:
        break from collections import deque n, q = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split q p_que = deque([]) p_que deque([]) deque [] for _ in range(n):
    name, t = map(str, input().split())
    p_que.append([name, int(t)]) _ range(n) range n name, t = map(str, input().split()) name map(str, input().split()) map str input().split() ().split () input split t p_que.append([name, int(t)]) p_que.append p_que append [name, int(t)] name int(t) int t sum_time = 0 sum_time 0 while True:
    p = p_que.popleft()
    if p[1] <= q:
        sum_time += p[1]
        print(p[0], sum_time)
    else:
        sum_time += q
        p[1] -= q
        p_que.append(p)
    if len(p_que) == 0:
        break True p = p_que.popleft() p p_que.popleft() p_que.popleft p_que popleft if p[1] <= q:
        sum_time += p[1]
        print(p[0], sum_time)
    else:
        sum_time += q
        p[1] -= q
        p_que.append(p)
     p[1] <= q p[1] p 1 q sum_time += p[1] sum_time p[1] p 1 print(p[0], sum_time) print p[0] p 0 sum_time sum_time += q sum_time q p[1] -= q p[1] p 1 q p_que.append(p) p_que.append p_que append p if len(p_que) == 0:
        break len(p_que) == 0 len(p_que) len p_que 0 break t = map(str, input().split()) map(str, input().split()) t sum_time = 0 0 sum_time p = p_que.popleft() p_que.popleft() p sum_time += p[1] p[1] sum_time n, q = map(int, input().split()) map(int, input().split()) n sum_time += q q sum_time p_que = deque([]) deque([]) p_que name, t = map(str, input().split()) map(str, input().split()) name q = map(int, input().split()) map(int, input().split()) q
from collections import deque

n, q = map(int, input().split())
p_que = deque([])

for _ in range(n):
    name, t = map(str, input().split())
    p_que.append([name, int(t)])

sum_time = 0
while True:
    p = p_que.popleft()
    if p[1] <= q:
        sum_time += p[1]
        print(p[0], sum_time)
    else:
        sum_time += q
        p[1] -= q
        p_que.append(p)
    if len(p_que) == 0:
        break
