import collections
import sys

p_q = collections.deque(maxlen = 100000)

e_time = 0

n, q = map(int, sys.stdin.readline().split())

for i in range(n):
    p_name, r_time = sys.stdin.readline().split()
    p_q.append([p_name, int(r_time)])

while p_q:
    t_p = p_q.popleft()
    if t_p[1] > q:
        t_p[1] -= q
        e_time += q
        p_q.append(t_p)
    else:
        e_time += t_p[1]
        print(t_p[0], e_time) import collections collections import sys sys p_q = collections.deque(maxlen = 100000) p_q collections.deque(maxlen = 100000) collections.deque collections deque maxlen = 100000 maxlen 100000 e_time = 0 e_time 0 n, q = map(int, sys.stdin.readline().split()) n map(int, sys.stdin.readline().split()) map int sys.stdin.readline().split() sys.stdin.readline().split sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline split q for i in range(n):
    p_name, r_time = sys.stdin.readline().split()
    p_q.append([p_name, int(r_time)]) i range(n) range n p_name, r_time = sys.stdin.readline().split() p_name sys.stdin.readline().split() sys.stdin.readline().split sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline split r_time p_q.append([p_name, int(r_time)]) p_q.append p_q append [p_name, int(r_time)] p_name int(r_time) int r_time while p_q:
    t_p = p_q.popleft()
    if t_p[1] > q:
        t_p[1] -= q
        e_time += q
        p_q.append(t_p)
    else:
        e_time += t_p[1]
        print(t_p[0], e_time) p_q t_p = p_q.popleft() t_p p_q.popleft() p_q.popleft p_q popleft if t_p[1] > q:
        t_p[1] -= q
        e_time += q
        p_q.append(t_p)
    else:
        e_time += t_p[1]
        print(t_p[0], e_time) t_p[1] > q t_p[1] t_p 1 q t_p[1] -= q t_p[1] t_p 1 q e_time += q e_time q p_q.append(t_p) p_q.append p_q append t_p e_time += t_p[1] e_time t_p[1] t_p 1 print(t_p[0], e_time) print t_p[0] t_p 0 e_time r_time = sys.stdin.readline().split() sys.stdin.readline().split() r_time e_time += t_p[1] t_p[1] e_time p_q = collections.deque(maxlen = 100000) collections.deque(maxlen = 100000) p_q e_time = 0 0 e_time q = map(int, sys.stdin.readline().split()) map(int, sys.stdin.readline().split()) q t_p = p_q.popleft() p_q.popleft() t_p e_time += q q e_time n, q = map(int, sys.stdin.readline().split()) map(int, sys.stdin.readline().split()) n p_name, r_time = sys.stdin.readline().split() sys.stdin.readline().split() p_name
import collections
import sys

p_q = collections.deque(maxlen = 100000)

e_time = 0

n, q = map(int, sys.stdin.readline().split())

for i in range(n):
    p_name, r_time = sys.stdin.readline().split()
    p_q.append([p_name, int(r_time)])

while p_q:
    t_p = p_q.popleft()
    if t_p[1] > q:
        t_p[1] -= q
        e_time += q
        p_q.append(t_p)
    else:
        e_time += t_p[1]
        print(t_p[0], e_time)