from collections import deque, namedtuple

Process = namedtuple('Process', 'name, time')

def main():
    n, q = map(int, input().split())
    dq = deque()
    for _ in range(n):
        name, time = input().split()
        dq.append(Process(name, int(time)))
    cur_time = 0
    while len(dq) > 0:
        x = dq.popleft()
        if x.time > q:
            dq.append(Process(x.name, x.time-q))
            cur_time += q
        else:
            cur_time += x.time
            print(x.name, cur_time)


if __name__ == '__main__':
    main() from collections import deque, namedtuple Process = namedtuple('Process', 'name, time') Process namedtuple('Process', 'name, time') namedtuple 'Process' 'name, time' def main():
    n, q = map(int, input().split())
    dq = deque()
    for _ in range(n):
        name, time = input().split()
        dq.append(Process(name, int(time)))
    cur_time = 0
    while len(dq) > 0:
        x = dq.popleft()
        if x.time > q:
            dq.append(Process(x.name, x.time-q))
            cur_time += q
        else:
            cur_time += x.time
            print(x.name, cur_time) main n, q = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split q dq = deque() dq deque() deque for _ in range(n):
        name, time = input().split()
        dq.append(Process(name, int(time)))
     _ range(n) range n name, time = input().split() name input().split() ().split () input split time dq.append(Process(name, int(time))) dq.append dq append Process(name, int(time)) Process name int(time) int time cur_time = 0 cur_time 0 while len(dq) > 0:
        x = dq.popleft()
        if x.time > q:
            dq.append(Process(x.name, x.time-q))
            cur_time += q
        else:
            cur_time += x.time
            print(x.name, cur_time) len(dq) > 0 len(dq) len dq 0 x = dq.popleft() x dq.popleft() dq.popleft dq popleft if x.time > q:
            dq.append(Process(x.name, x.time-q))
            cur_time += q
        else:
            cur_time += x.time
            print(x.name, cur_time) x.time > q x.time x time q dq.append(Process(x.name, x.time-q)) dq.append dq append Process(x.name, x.time-q) Process x.name x name x.time-q x.time x time q cur_time += q cur_time q cur_time += x.time cur_time x.time x time print(x.name, cur_time) print x.name x name cur_time if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main Process = namedtuple('Process', 'name, time') namedtuple('Process', 'name, time') Process def main():
    n, q = map(int, input().split())
    dq = deque()
    for _ in range(n):
        name, time = input().split()
        dq.append(Process(name, int(time)))
    cur_time = 0
    while len(dq) > 0:
        x = dq.popleft()
        if x.time > q:
            dq.append(Process(x.name, x.time-q))
            cur_time += q
        else:
            cur_time += x.time
            print(x.name, cur_time) def main():
    n, q = map(int, input().split())
    dq = deque()
    for _ in range(n):
        name, time = input().split()
        dq.append(Process(name, int(time)))
    cur_time = 0
    while len(dq) > 0:
        x = dq.popleft()
        if x.time > q:
            dq.append(Process(x.name, x.time-q))
            cur_time += q
        else:
            cur_time += x.time
            print(x.name, cur_time) main
from collections import deque, namedtuple

Process = namedtuple('Process', 'name, time')

def main():
    n, q = map(int, input().split())
    dq = deque()
    for _ in range(n):
        name, time = input().split()
        dq.append(Process(name, int(time)))
    cur_time = 0
    while len(dq) > 0:
        x = dq.popleft()
        if x.time > q:
            dq.append(Process(x.name, x.time-q))
            cur_time += q
        else:
            cur_time += x.time
            print(x.name, cur_time)


if __name__ == '__main__':
    main()
