from collections import deque

n,limit = map(int,input().split())
total_time = 0
queue = deque()
for _ in range(n):
    p,t = input().split()
    queue.append([p,int(t)])

while len(queue) > 0:
    head = queue.popleft()
    if head[1] <= limit:
        total_time += head[1]
        print('{} {}'.format(head[0],total_time))
    else:
        head[1] -= limit
        total_time += limit
        queue.append(head) from collections import deque n,limit = map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split limit total_time = 0 total_time 0 queue = deque() queue deque() deque for _ in range(n):
    p,t = input().split()
    queue.append([p,int(t)]) _ range(n) range n p,t = input().split() p input().split() ().split () input split t queue.append([p,int(t)]) queue.append queue append [p,int(t)] p int(t) int t while len(queue) > 0:
    head = queue.popleft()
    if head[1] <= limit:
        total_time += head[1]
        print('{} {}'.format(head[0],total_time))
    else:
        head[1] -= limit
        total_time += limit
        queue.append(head) len(queue) > 0 len(queue) len queue 0 head = queue.popleft() head queue.popleft() queue.popleft queue popleft if head[1] <= limit:
        total_time += head[1]
        print('{} {}'.format(head[0],total_time))
    else:
        head[1] -= limit
        total_time += limit
        queue.append(head) head[1] <= limit head[1] head 1 limit total_time += head[1] total_time head[1] head 1 print('{} {}'.format(head[0],total_time)) print '{} {}'.format(head[0],total_time) '{} {}'.format '{} {}' format head[0] head 0 total_time head[1] -= limit head[1] head 1 limit total_time += limit total_time limit queue.append(head) queue.append queue append head t = input().split() input().split() t total_time = 0 0 total_time total_time += limit limit total_time n,limit = map(int,input().split()) map(int,input().split()) n p,t = input().split() input().split() p queue = deque() deque() queue head = queue.popleft() queue.popleft() head total_time += head[1] head[1] total_time limit = map(int,input().split()) map(int,input().split()) limit
from collections import deque

n,limit = map(int,input().split())
total_time = 0
queue = deque()
for _ in range(n):
    p,t = input().split()
    queue.append([p,int(t)])

while len(queue) > 0:
    head = queue.popleft()
    if head[1] <= limit:
        total_time += head[1]
        print('{} {}'.format(head[0],total_time))
    else:
        head[1] -= limit
        total_time += limit
        queue.append(head)
