import sys
import collections

(n, quantum) = map(int, input().split())
processes = [input().split() for i in range(n)]
for p in processes:
    p[1] = int(p[1])
queue = collections.deque(processes)
elapsed = 0
while queue:
    head = queue.popleft()
    if head[1] > quantum:
        head[1] -= quantum
        queue.append(head)
        elapsed += quantum
    else:
        elapsed += head[1]
        print(head[0], elapsed) import sys sys import collections collections (n, quantum) = map(int, input().split()) (n, quantum) n quantum map(int, input().split()) map int input().split() ().split () input split 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 processes = [input().split() for i in range(n)] processes [input().split() for i in range(n)] for p in processes:
    p[1] = int(p[1]) p processes p[1] = int(p[1]) p[1] p 1 int(p[1]) int p[1] p 1 queue = collections.deque(processes) queue collections.deque(processes) collections.deque collections deque processes elapsed = 0 elapsed 0 while queue:
    head = queue.popleft()
    if head[1] > quantum:
        head[1] -= quantum
        queue.append(head)
        elapsed += quantum
    else:
        elapsed += head[1]
        print(head[0], elapsed) queue head = queue.popleft() head queue.popleft() queue.popleft queue popleft if head[1] > quantum:
        head[1] -= quantum
        queue.append(head)
        elapsed += quantum
    else:
        elapsed += head[1]
        print(head[0], elapsed) head[1] > quantum head[1] head 1 quantum head[1] -= quantum head[1] head 1 quantum queue.append(head) queue.append queue append head elapsed += quantum elapsed quantum elapsed += head[1] elapsed head[1] head 1 print(head[0], elapsed) print head[0] head 0 elapsed processes = [input().split() for i in range(n)] [input().split() for i in range(n)] processes elapsed += quantum quantum elapsed queue = collections.deque(processes) collections.deque(processes) queue head = queue.popleft() queue.popleft() head elapsed = 0 0 elapsed elapsed += head[1] head[1] elapsed
import sys
import collections

(n, quantum) = map(int, input().split())
processes = [input().split() for i in range(n)]
for p in processes:
    p[1] = int(p[1])
queue = collections.deque(processes)
elapsed = 0
while queue:
    head = queue.popleft()
    if head[1] > quantum:
        head[1] -= quantum
        queue.append(head)
        elapsed += quantum
    else:
        elapsed += head[1]
        print(head[0], elapsed)