from collections import deque

n, q = list(map(int, input().split()))
que = deque([])
for _ in range(n):
    name, time = input().split()
    que.append([name, int(time)])
    
elapsed_time = 0
while que:
    name, time = que.popleft()
    dt = min(q, time)
    time -= dt
    elapsed_time += dt
    if time > 0:
        que.append([name, time])
    else:
        print (name, elapsed_time) from collections import deque n, q = list(map(int, input().split())) n list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split q que = deque([]) que deque([]) deque [] for _ in range(n):
    name, time = input().split()
    que.append([name, int(time)])
     _ range(n) range n name, time = input().split() name input().split() ().split () input split time que.append([name, int(time)]) que.append que append [name, int(time)] name int(time) int time elapsed_time = 0 elapsed_time 0 while que:
    name, time = que.popleft()
    dt = min(q, time)
    time -= dt
    elapsed_time += dt
    if time > 0:
        que.append([name, time])
    else:
        print (name, elapsed_time) que name, time = que.popleft() name que.popleft() que.popleft que popleft time dt = min(q, time) dt min(q, time) min q time time -= dt time dt elapsed_time += dt elapsed_time dt if time > 0:
        que.append([name, time])
    else:
        print (name, elapsed_time) time > 0 time 0 que.append([name, time]) que.append que append [name, time] name time print (name, elapsed_time) print name elapsed_time time = que.popleft() que.popleft() time elapsed_time += dt dt elapsed_time n, q = list(map(int, input().split())) list(map(int, input().split())) n elapsed_time = 0 0 elapsed_time name, time = input().split() input().split() name dt = min(q, time) min(q, time) dt que = deque([]) deque([]) que time -= dt dt time time = input().split() input().split() time q = list(map(int, input().split())) list(map(int, input().split())) q name, time = que.popleft() que.popleft() name
from collections import deque

n, q = list(map(int, input().split()))
que = deque([])
for _ in range(n):
    name, time = input().split()
    que.append([name, int(time)])
    
elapsed_time = 0
while que:
    name, time = que.popleft()
    dt = min(q, time)
    time -= dt
    elapsed_time += dt
    if time > 0:
        que.append([name, time])
    else:
        print (name, elapsed_time)