#include <cassert>
#include <memory>
#include <type_traits>
#include <utility>

template <class T> class persistent_queue {
public:
	static_assert(::std::is_copy_constructible<T>::value,
		"T must be copy constructible");

	using value_type = T;
	using const_reference = const value_type &;

private:
	class node_type;
	using node_ptr = ::std::shared_ptr<node_type>;
	using raw_ptr = node_type *;
	class stream_type;
	using stream_ptr = ::std::shared_ptr<stream_type>;

	template <class... Args> static node_ptr make_node(Args &&... args) {
		return ::std::make_shared<node_type>(::std::forward<Args>(args)...);
	}
	template <class... Args> static stream_ptr make_stream(Args &&... args) {
		return ::std::make_shared<stream_type>(::std::forward<Args>(args)...);
	}

	class node_type {
	public:
		template <class Nptr>
		node_type(Nptr &&n, const value_type &v)
			: next(::std::forward<Nptr>(n)), value(v) {}
		node_ptr next;
		value_type value;
	};
	class stream_type {
	public:
		template <class Rptr>
		stream_type(const node_ptr &s, Rptr &&r)
			: scan(s), rotate(::std::forward<Rptr>(r)) {}

		node_ptr scan, rotate;

		node_ptr next() {
			node_ptr ret;
			if (scan) {
				ret = make_node(nullptr, scan->value);
				scan = scan->next;
			}
			else {
				while (rotate) {
					ret = make_node(::std::move(ret), rotate->value);
					rotate = rotate->next;
				}
			}
			return ::std::move(ret);
		}
	};
	node_ptr f_st;
	raw_ptr proc;
	stream_ptr stream;
	node_ptr b_st;

	explicit persistent_queue(::std::shared_ptr<stream_type> &&st)
		: f_st(st->next()), proc(f_st.get()), stream(::std::move(st)), b_st() {}
	template <class Bptr>
	explicit persistent_queue(const node_ptr &f, const raw_ptr &p,
		const stream_ptr &s, Bptr &&b)
		: f_st(f), proc(p), stream(s), b_st(::std::forward<Bptr>(b)) {}

public:
	constexpr persistent_queue() noexcept
		: f_st(), proc(nullptr), stream(), b_st() {}

	constexpr bool empty() const noexcept { return !static_cast<bool>(f_st); }

	const_reference front() const {
		assert(("called persistent_queue::front on an empty queue", !empty()));
		return f_st->value;
	}

	persistent_queue push(const value_type &x) const {
		if (!proc) {
			return persistent_queue(make_stream(f_st, make_node(b_st, x)));
		}
		if (!proc->next) {
			proc->next = stream->next();
		}
		return persistent_queue(f_st, proc->next.get(), stream, make_node(b_st, x));
	}
	persistent_queue pop() const {
		assert(("called persistent_queue::pop on an empty queue", !empty()));
		if (!proc) {
			return persistent_queue(make_stream(f_st->next, b_st));
		}
		if (!proc->next) {
			proc->next = stream->next();
		}
		return persistent_queue(f_st->next, proc->next.get(), stream, b_st);
	}
};

#include <iostream>
#include <string>
#include <utility>

int main() {
	struct process {
		::std::string name;
		int time;
	};

	int n, q;
	::std::cin >> n >> q;

	persistent_queue<process> que;

	while(n--) {
		process p;
		::std::cin >> p.name >> p.time;

		que = que.push(p);
	}

	int now = 0;

	while (!que.empty()) {
		process p = que.front();
		que = que.pop();
		if (p.time <= q) {
			now += p.time;
			::std::cout << p.name << " " << now << ::std::endl;
		}
		else {
			now += q;
			p.time -= q;
			que = que.push(p);
		}
	}

	return 0;
}



Measured memory_bytes: 8580