# -*- coding: utf-8 -*-


def simu(pro, q):
    end_time = 0

    while bool(pro):
        if pro[1] > q:
            end_time += q
            pro.append(pro[0])
            pro.append(pro[1] - q)
            pro.pop(0)
            pro.pop(0)

        elif pro[1] <= q:
            end_time += pro[1]
            print('{0} {1}'.format(pro[0], end_time))
            pro.pop(0)
            pro.pop(0)


n, q = list(map(int, input().split()))

pro = []
for i in range(n):
    name, time = list(input().split())
    pro.append(name)
    pro.append(int(time))

simu(pro, q)
 def simu(pro, q):
    end_time = 0

    while bool(pro):
        if pro[1] > q:
            end_time += q
            pro.append(pro[0])
            pro.append(pro[1] - q)
            pro.pop(0)
            pro.pop(0)

        elif pro[1] <= q:
            end_time += pro[1]
            print('{0} {1}'.format(pro[0], end_time))
            pro.pop(0)
            pro.pop(0) simu end_time = 0 end_time 0 while bool(pro):
        if pro[1] > q:
            end_time += q
            pro.append(pro[0])
            pro.append(pro[1] - q)
            pro.pop(0)
            pro.pop(0)

        elif pro[1] <= q:
            end_time += pro[1]
            print('{0} {1}'.format(pro[0], end_time))
            pro.pop(0)
            pro.pop(0) bool(pro) bool pro if pro[1] > q:
            end_time += q
            pro.append(pro[0])
            pro.append(pro[1] - q)
            pro.pop(0)
            pro.pop(0)

        elif pro[1] <= q:
            end_time += pro[1]
            print('{0} {1}'.format(pro[0], end_time))
            pro.pop(0)
            pro.pop(0) pro[1] > q pro[1] pro 1 q end_time += q end_time q pro.append(pro[0]) pro.append pro append pro[0] pro 0 pro.append(pro[1] - q) pro.append pro append pro[1] - q pro[1] pro 1 q pro.pop(0) pro.pop pro pop 0 pro.pop(0) pro.pop pro pop 0 elif pro[1] <= q:
            end_time += pro[1]
            print('{0} {1}'.format(pro[0], end_time))
            pro.pop(0)
            pro.pop(0) pro[1] <= q pro[1] pro 1 q end_time += pro[1] end_time pro[1] pro 1 print('{0} {1}'.format(pro[0], end_time)) print '{0} {1}'.format(pro[0], end_time) '{0} {1}'.format '{0} {1}' format pro[0] pro 0 end_time pro.pop(0) pro.pop pro pop 0 pro.pop(0) pro.pop pro pop 0 pro pro q q 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 pro = [] pro [] for i in range(n):
    name, time = list(input().split())
    pro.append(name)
    pro.append(int(time)) i range(n) range n name, time = list(input().split()) name list(input().split()) list input().split() ().split () input split time pro.append(name) pro.append pro append name pro.append(int(time)) pro.append pro append int(time) int time simu(pro, q) simu pro q name, time = list(input().split()) list(input().split()) name q = list(map(int, input().split())) list(map(int, input().split())) q n, q = list(map(int, input().split())) list(map(int, input().split())) n def simu(pro, q):
    end_time = 0

    while bool(pro):
        if pro[1] > q:
            end_time += q
            pro.append(pro[0])
            pro.append(pro[1] - q)
            pro.pop(0)
            pro.pop(0)

        elif pro[1] <= q:
            end_time += pro[1]
            print('{0} {1}'.format(pro[0], end_time))
            pro.pop(0)
            pro.pop(0) def simu(pro, q):
    end_time = 0

    while bool(pro):
        if pro[1] > q:
            end_time += q
            pro.append(pro[0])
            pro.append(pro[1] - q)
            pro.pop(0)
            pro.pop(0)

        elif pro[1] <= q:
            end_time += pro[1]
            print('{0} {1}'.format(pro[0], end_time))
            pro.pop(0)
            pro.pop(0) simu pro = [] [] pro time = list(input().split()) list(input().split()) time
# -*- coding: utf-8 -*-


def simu(pro, q):
    end_time = 0

    while bool(pro):
        if pro[1] > q:
            end_time += q
            pro.append(pro[0])
            pro.append(pro[1] - q)
            pro.pop(0)
            pro.pop(0)

        elif pro[1] <= q:
            end_time += pro[1]
            print('{0} {1}'.format(pro[0], end_time))
            pro.pop(0)
            pro.pop(0)


n, q = list(map(int, input().split()))

pro = []
for i in range(n):
    name, time = list(input().split())
    pro.append(name)
    pro.append(int(time))

simu(pro, q)

