import std.stdio;
import std.string;
import std.conv;
import std.algorithm;

class Process{
	private:
		string _name;
		int _time;
	public:
		@property{
			string name() const { return _name; }
			int time() const { return _time; }
		}

		this(string n, int t){
			_name = n;
			_time = t;
		}
		void print(int t) {
			writeln(name, " ", t);
		}
		void sub(int a){
			_time -= a;
		}
}

int main(char[][]argv)
{
	string[] str = readln.split();
	int n = str[0].to!int(), q = str[1].to!int(), t = 0;

	Process[] p;
	for(int i = 0; i < n; ++i){
		str = readln.split();
		p ~= new Process(str[0], str[1].to!int());
	}

	while(p.length != 0){
		//writeln("t : ", t);
		//foreach(e; p){
		//    writeln("p.name : ", e.name, " p.time : ", e.time);
		//}
		//writeln();
		p[0].sub(q);
		if(p[0].time <= 0){
			p[0].print(p[0].time + t + q);
			t += p[0].time + q;
			p = p[1..$];
		}
		else{
			t += q;
			auto tmp = p[0];
			p = p[1..$];
			p ~= tmp;
		}
	}

    return 0;
}