n,q = map(int, input().split())
name = []
time = []
for i in range(n):
    x = input().split()
    name.append(x[0])
    time.append(int(x[1]))

t = 0
n_end = []
t_end = []
while(len(time) > 0):
    if time[0] <= q:
        t += time[0]
        n_end.append(name.pop(0))
        time.pop(0)
        t_end.append(t)
    else :
        t += q
        time[0] -= q
        a = time.pop(0)
        b = name.pop(0)
        time.append(a)
        name.append(b)

for i in range(len(n_end)):
    print(n_end[i],t_end[i])
 n,q = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split q name = [] name [] time = [] time [] for i in range(n):
    x = input().split()
    name.append(x[0])
    time.append(int(x[1])) i range(n) range n x = input().split() x input().split() ().split () input split name.append(x[0]) name.append name append x[0] x 0 time.append(int(x[1])) time.append time append int(x[1]) int x[1] x 1 t = 0 t 0 n_end = [] n_end [] t_end = [] t_end [] while(len(time) > 0):
    if time[0] <= q:
        t += time[0]
        n_end.append(name.pop(0))
        time.pop(0)
        t_end.append(t)
    else :
        t += q
        time[0] -= q
        a = time.pop(0)
        b = name.pop(0)
        time.append(a)
        name.append(b) len(time) > 0 len(time) len time 0 if time[0] <= q:
        t += time[0]
        n_end.append(name.pop(0))
        time.pop(0)
        t_end.append(t)
    else :
        t += q
        time[0] -= q
        a = time.pop(0)
        b = name.pop(0)
        time.append(a)
        name.append(b) time[0] <= q time[0] time 0 q t += time[0] t time[0] time 0 n_end.append(name.pop(0)) n_end.append n_end append name.pop(0) name.pop name pop 0 time.pop(0) time.pop time pop 0 t_end.append(t) t_end.append t_end append t t += q t q time[0] -= q time[0] time 0 q a = time.pop(0) a time.pop(0) time.pop time pop 0 b = name.pop(0) b name.pop(0) name.pop name pop 0 time.append(a) time.append time append a name.append(b) name.append name append b for i in range(len(n_end)):
    print(n_end[i],t_end[i]) i range(len(n_end)) range len(n_end) len n_end print(n_end[i],t_end[i]) print n_end[i] n_end i t_end[i] t_end i n,q = map(int, input().split()) map(int, input().split()) n n_end = [] [] n_end x = input().split() input().split() x t_end = [] [] t_end name = [] [] name t += time[0] time[0] t a = time.pop(0) time.pop(0) a t = 0 0 t time = [] [] time q = map(int, input().split()) map(int, input().split()) q t += q q t b = name.pop(0) name.pop(0) b
n,q = map(int, input().split())
name = []
time = []
for i in range(n):
    x = input().split()
    name.append(x[0])
    time.append(int(x[1]))

t = 0
n_end = []
t_end = []
while(len(time) > 0):
    if time[0] <= q:
        t += time[0]
        n_end.append(name.pop(0))
        time.pop(0)
        t_end.append(t)
    else :
        t += q
        time[0] -= q
        a = time.pop(0)
        b = name.pop(0)
        time.append(a)
        name.append(b)

for i in range(len(n_end)):
    print(n_end[i],t_end[i])

