from collections import deque


def main():
    process_count, process_time, processes = get_input()
    result = run_roundrobin(processes=processes, time=process_time)
    for r in result:
        print(r.name, r.time)


def run_roundrobin(processes, time, total_time=0, result=[]):
    while processes:
        p = processes.popleft()
        if p.time <= time:
            total_time += p.time
            p.time = total_time
            result.append(p)
        else:
            total_time += time
            p.time -= time
            processes.append(p)

    return result


def get_input():
    count, time = list(map(lambda x: int(x), input().split(' ')))

    processes = deque([])
    for _ in range(count):
        im = input().split(' ')
        p = Process(im[0], int(im[1]))
        processes.append(p)

    return count, time, processes


class Process():

    def __init__(self, name, time):
        self.name = name
        self.time = time


main() from collections import deque def main():
    process_count, process_time, processes = get_input()
    result = run_roundrobin(processes=processes, time=process_time)
    for r in result:
        print(r.name, r.time) main process_count, process_time, processes = get_input() process_count get_input() get_input process_time processes result = run_roundrobin(processes=processes, time=process_time) result run_roundrobin(processes=processes, time=process_time) run_roundrobin processes=processes processes processes time=process_time time process_time for r in result:
        print(r.name, r.time) r result print(r.name, r.time) print r.name r name r.time r time def run_roundrobin(processes, time, total_time=0, result=[]):
    while processes:
        p = processes.popleft()
        if p.time <= time:
            total_time += p.time
            p.time = total_time
            result.append(p)
        else:
            total_time += time
            p.time -= time
            processes.append(p)

    return result run_roundrobin while processes:
        p = processes.popleft()
        if p.time <= time:
            total_time += p.time
            p.time = total_time
            result.append(p)
        else:
            total_time += time
            p.time -= time
            processes.append(p)

     processes p = processes.popleft() p processes.popleft() processes.popleft processes popleft if p.time <= time:
            total_time += p.time
            p.time = total_time
            result.append(p)
        else:
            total_time += time
            p.time -= time
            processes.append(p)

     p.time <= time p.time p time time total_time += p.time total_time p.time p time p.time = total_time p.time p time total_time result.append(p) result.append result append p total_time += time total_time time p.time -= time p.time p time time processes.append(p) processes.append processes append p return result result processes processes time time total_time=0 total_time 0 result=[] result [] def get_input():
    count, time = list(map(lambda x: int(x), input().split(' ')))

    processes = deque([])
    for _ in range(count):
        im = input().split(' ')
        p = Process(im[0], int(im[1]))
        processes.append(p)

    return count, time, processes get_input count, time = list(map(lambda x: int(x), input().split(' '))) count list(map(lambda x: int(x), input().split(' '))) list map(lambda x: int(x), input().split(' ')) map lambda x: int(x) int(x) int x x input().split(' ') ().split () input split ' ' time processes = deque([]) processes deque([]) deque [] for _ in range(count):
        im = input().split(' ')
        p = Process(im[0], int(im[1]))
        processes.append(p)

     _ range(count) range count im = input().split(' ') im input().split(' ') ().split () input split ' ' p = Process(im[0], int(im[1])) p Process(im[0], int(im[1])) Process im[0] im 0 int(im[1]) int im[1] im 1 processes.append(p) processes.append processes append p return count, time, processes return count, time, processes count time processes class Process():

    def __init__(self, name, time):
        self.name = name
        self.time = time Process def __init__(self, name, time):
        self.name = name
        self.time = time __init__ self.name = name self.name self name name self.time = time self.time self time time self self name name time time main() main def get_input():
    count, time = list(map(lambda x: int(x), input().split(' ')))

    processes = deque([])
    for _ in range(count):
        im = input().split(' ')
        p = Process(im[0], int(im[1]))
        processes.append(p)

    return count, time, processes def get_input():
    count, time = list(map(lambda x: int(x), input().split(' ')))

    processes = deque([])
    for _ in range(count):
        im = input().split(' ')
        p = Process(im[0], int(im[1]))
        processes.append(p)

    return count, time, processes get_input def main():
    process_count, process_time, processes = get_input()
    result = run_roundrobin(processes=processes, time=process_time)
    for r in result:
        print(r.name, r.time) def main():
    process_count, process_time, processes = get_input()
    result = run_roundrobin(processes=processes, time=process_time)
    for r in result:
        print(r.name, r.time) main def run_roundrobin(processes, time, total_time=0, result=[]):
    while processes:
        p = processes.popleft()
        if p.time <= time:
            total_time += p.time
            p.time = total_time
            result.append(p)
        else:
            total_time += time
            p.time -= time
            processes.append(p)

    return result def run_roundrobin(processes, time, total_time=0, result=[]):
    while processes:
        p = processes.popleft()
        if p.time <= time:
            total_time += p.time
            p.time = total_time
            result.append(p)
        else:
            total_time += time
            p.time -= time
            processes.append(p)

    return result run_roundrobin class Process():

    def __init__(self, name, time):
        self.name = name
        self.time = time class Process():

    def __init__(self, name, time):
        self.name = name
        self.time = time Process
from collections import deque


def main():
    process_count, process_time, processes = get_input()
    result = run_roundrobin(processes=processes, time=process_time)
    for r in result:
        print(r.name, r.time)


def run_roundrobin(processes, time, total_time=0, result=[]):
    while processes:
        p = processes.popleft()
        if p.time <= time:
            total_time += p.time
            p.time = total_time
            result.append(p)
        else:
            total_time += time
            p.time -= time
            processes.append(p)

    return result


def get_input():
    count, time = list(map(lambda x: int(x), input().split(' ')))

    processes = deque([])
    for _ in range(count):
        im = input().split(' ')
        p = Process(im[0], int(im[1]))
        processes.append(p)

    return count, time, processes


class Process():

    def __init__(self, name, time):
        self.name = name
        self.time = time


main()