from collections import deque

def main():
    N, Q = [int(i) for i in input().split()]
    Ts = deque([])

    for _ in range(N):
        name, time = [i for i in input().split()]
        Ts.append({
            "name": name,
            "time": int(time)
        })

    cur_t = 0

    while len(Ts):
        task = Ts.popleft()

        # 終わらない
        if task["time"] > Q:
            task["time"] -= Q
            cur_t += Q
            Ts.append(task)
        else:
            cur_t += task["time"]
            print(task["name"], cur_t)


main()
 from collections import deque def main():
    N, Q = [int(i) for i in input().split()]
    Ts = deque([])

    for _ in range(N):
        name, time = [i for i in input().split()]
        Ts.append({
            "name": name,
            "time": int(time)
        })

    cur_t = 0

    while len(Ts):
        task = Ts.popleft()

        # 終わらない
        if task["time"] > Q:
            task["time"] -= Q
            cur_t += Q
            Ts.append(task)
        else:
            cur_t += task["time"]
            print(task["name"], cur_t) main int(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() int(i) int i N, Q = [int(i) for i in input().split()] N [int(i) for i in input().split()] Q Ts = deque([]) Ts deque([]) deque [] for _ in range(N):
        name, time = [i for i in input().split()]
        Ts.append({
            "name": name,
            "time": int(time)
        })

     _ range(N) range N i for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() i name, time = [i for i in input().split()] name [i for i in input().split()] time Ts.append({
            "name": name,
            "time": int(time)
        }) Ts.append Ts append {
            "name": name,
            "time": int(time)
        } "name" "name" name "time" "time" int(time) int time cur_t = 0 cur_t 0 while len(Ts):
        task = Ts.popleft()

        # 終わらない
        if task["time"] > Q:
            task["time"] -= Q
            cur_t += Q
            Ts.append(task)
        else:
            cur_t += task["time"]
            print(task["name"], cur_t) len(Ts) len Ts task = Ts.popleft() task Ts.popleft() Ts.popleft Ts popleft if task["time"] > Q:
            task["time"] -= Q
            cur_t += Q
            Ts.append(task)
        else:
            cur_t += task["time"]
            print(task["name"], cur_t) task["time"] > Q task["time"] task "time" Q task["time"] -= Q task["time"] task "time" Q cur_t += Q cur_t Q Ts.append(task) Ts.append Ts append task cur_t += task["time"] cur_t task["time"] task "time" print(task["name"], cur_t) print task["name"] task "name" cur_t main() main def main():
    N, Q = [int(i) for i in input().split()]
    Ts = deque([])

    for _ in range(N):
        name, time = [i for i in input().split()]
        Ts.append({
            "name": name,
            "time": int(time)
        })

    cur_t = 0

    while len(Ts):
        task = Ts.popleft()

        # 終わらない
        if task["time"] > Q:
            task["time"] -= Q
            cur_t += Q
            Ts.append(task)
        else:
            cur_t += task["time"]
            print(task["name"], cur_t) def main():
    N, Q = [int(i) for i in input().split()]
    Ts = deque([])

    for _ in range(N):
        name, time = [i for i in input().split()]
        Ts.append({
            "name": name,
            "time": int(time)
        })

    cur_t = 0

    while len(Ts):
        task = Ts.popleft()

        # 終わらない
        if task["time"] > Q:
            task["time"] -= Q
            cur_t += Q
            Ts.append(task)
        else:
            cur_t += task["time"]
            print(task["name"], cur_t) main
from collections import deque

def main():
    N, Q = [int(i) for i in input().split()]
    Ts = deque([])

    for _ in range(N):
        name, time = [i for i in input().split()]
        Ts.append({
            "name": name,
            "time": int(time)
        })

    cur_t = 0

    while len(Ts):
        task = Ts.popleft()

        # 終わらない
        if task["time"] > Q:
            task["time"] -= Q
            cur_t += Q
            Ts.append(task)
        else:
            cur_t += task["time"]
            print(task["name"], cur_t)


main()

