[n, q] = [int(x) for x in input().split()]
qs = []
for _ in range(n):
    al = input().split()
    qs.append([al[0], int(al[1])])

t = 0
while len(qs) > 0:
    task = qs.pop(0)
    if task[1] <= q:
        t += task[1]
        print(task[0], t)
    else:
        t += q
        task[1] -= q
        qs.append(task) int(x) for x in input().split() for x in input().split() x input().split() ().split () input split for x in input().split() int(x) int x [n, q] = [int(x) for x in input().split()] [n, q] n q [int(x) for x in input().split()] qs = [] qs [] for _ in range(n):
    al = input().split()
    qs.append([al[0], int(al[1])]) _ range(n) range n al = input().split() al input().split() ().split () input split qs.append([al[0], int(al[1])]) qs.append qs append [al[0], int(al[1])] al[0] al 0 int(al[1]) int al[1] al 1 t = 0 t 0 while len(qs) > 0:
    task = qs.pop(0)
    if task[1] <= q:
        t += task[1]
        print(task[0], t)
    else:
        t += q
        task[1] -= q
        qs.append(task) len(qs) > 0 len(qs) len qs 0 task = qs.pop(0) task qs.pop(0) qs.pop qs pop 0 if task[1] <= q:
        t += task[1]
        print(task[0], t)
    else:
        t += q
        task[1] -= q
        qs.append(task) task[1] <= q task[1] task 1 q t += task[1] t task[1] task 1 print(task[0], t) print task[0] task 0 t t += q t q task[1] -= q task[1] task 1 q qs.append(task) qs.append qs append task al = input().split() input().split() al task = qs.pop(0) qs.pop(0) task qs = [] [] qs t = 0 0 t t += task[1] task[1] t t += q q t
[n, q] = [int(x) for x in input().split()]
qs = []
for _ in range(n):
    al = input().split()
    qs.append([al[0], int(al[1])])

t = 0
while len(qs) > 0:
    task = qs.pop(0)
    if task[1] <= q:
        t += task[1]
        print(task[0], t)
    else:
        t += q
        task[1] -= q
        qs.append(task)
