from collections import deque;

count, time_slice = map(int, input().split(" "));

data = [];
for i in range(count):
    data += input().split(" ");

def round_robin(data, count, time_slice):
    t = 0;
    data = [[data[i], int(data[i + 1])] for i in range(0, len(data), 2)];
    que = deque(data);
    while len(que) > 0:
        current = que.popleft();
        if current[1] > time_slice:
            current[1] -= time_slice;
            t += time_slice;
            que.append(current);
        else:
            t += current[1];
            print(current[0], t);


round_robin(data, count, time_slice); from collections import deque count, time_slice = map(int, input().split(" ")) count map(int, input().split(" ")) map int input().split(" ") ().split () input split " " time_slice data = [] data [] for i in range(count):
    data += input().split(" "); i range(count) range count data += input().split(" ") data input().split(" ") ().split () input split " " def round_robin(data, count, time_slice):
    t = 0;
    data = [[data[i], int(data[i + 1])] for i in range(0, len(data), 2)];
    que = deque(data);
    while len(que) > 0:
        current = que.popleft();
        if current[1] > time_slice:
            current[1] -= time_slice;
            t += time_slice;
            que.append(current);
        else:
            t += current[1];
            print(current[0], t); round_robin t = 0 t 0 [data[i], int(data[i + 1])] for i in range(0, len(data), 2) for i in range(0, len(data), 2) i range(0, len(data), 2) range 0 len(data) len data 2 for i in range(0, len(data), 2) [data[i], int(data[i + 1])] data[i] data i int(data[i + 1]) int data[i + 1] data i + 1 i 1 data = [[data[i], int(data[i + 1])] for i in range(0, len(data), 2)] data [[data[i], int(data[i + 1])] for i in range(0, len(data), 2)] que = deque(data) que deque(data) deque data while len(que) > 0:
        current = que.popleft();
        if current[1] > time_slice:
            current[1] -= time_slice;
            t += time_slice;
            que.append(current);
        else:
            t += current[1];
            print(current[0], t); len(que) > 0 len(que) len que 0 current = que.popleft() current que.popleft() que.popleft que popleft if current[1] > time_slice:
            current[1] -= time_slice;
            t += time_slice;
            que.append(current);
        else:
            t += current[1];
            print(current[0], t); current[1] > time_slice current[1] current 1 time_slice current[1] -= time_slice current[1] current 1 time_slice t += time_slice t time_slice que.append(current) que.append que append current t += current[1] t current[1] current 1 print(current[0], t) print current[0] current 0 t data data count count time_slice time_slice round_robin(data, count, time_slice) round_robin data count time_slice data += input().split(" ") input().split(" ") data data = [] [] data def round_robin(data, count, time_slice):
    t = 0;
    data = [[data[i], int(data[i + 1])] for i in range(0, len(data), 2)];
    que = deque(data);
    while len(que) > 0:
        current = que.popleft();
        if current[1] > time_slice:
            current[1] -= time_slice;
            t += time_slice;
            que.append(current);
        else:
            t += current[1];
            print(current[0], t); def round_robin(data, count, time_slice):
    t = 0;
    data = [[data[i], int(data[i + 1])] for i in range(0, len(data), 2)];
    que = deque(data);
    while len(que) > 0:
        current = que.popleft();
        if current[1] > time_slice:
            current[1] -= time_slice;
            t += time_slice;
            que.append(current);
        else:
            t += current[1];
            print(current[0], t); round_robin time_slice = map(int, input().split(" ")) map(int, input().split(" ")) time_slice count, time_slice = map(int, input().split(" ")) map(int, input().split(" ")) count
from collections import deque;

count, time_slice = map(int, input().split(" "));

data = [];
for i in range(count):
    data += input().split(" ");

def round_robin(data, count, time_slice):
    t = 0;
    data = [[data[i], int(data[i + 1])] for i in range(0, len(data), 2)];
    que = deque(data);
    while len(que) > 0:
        current = que.popleft();
        if current[1] > time_slice:
            current[1] -= time_slice;
            t += time_slice;
            que.append(current);
        else:
            t += current[1];
            print(current[0], t);


round_robin(data, count, time_slice);
