import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception{
		BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
		String str[] = r.readLine().split(" ");
		int max = Integer.parseInt(str[0]);
		Queue q = new Queue(max);
		int qtime = Integer.parseInt(str[1]);

		for(int i = 0 ; i < max ; i++ ){
			str = r.readLine().split(" ");
			q.enqueue(new Process(str[0], Integer.parseInt(str[1])));
		}

		int elapsedTime = 0;

		int count = 0;
		//?????\?????¬????????§???
		while(true){
			if(max <= count) break;
			Process p = q.dequeue();
			int time = p.getTime();

			if(time <= qtime){
				elapsedTime+= time;
				count++;
				System.out.println(p.getName() +" "+elapsedTime);
			}else{
				p.setTime(time - qtime);
				elapsedTime += qtime;
				q.enqueue(p);
			}

		}
	}

}

class Queue{

	Process[] processAry;
	int top;
	int tail;
	int max;

	public Queue(int max){
		top = tail = 0;
		processAry = new Process[max];
		this.max = max;
	}

	public void enqueue(Process process) throws Exception{
			processAry[top] = process;
			top = (top + 1) % max;
	}

	public Process dequeue() throws Exception{

			Process p = processAry[tail];
			tail = (tail + 1) % max;
			return p;

	}

}

class Process{
	private String name;
	private int time;

	public Process(String name,int time) {
		this.name = name;
		this.time = time;
	}

	public String getName() {
		return name;
	}

	public int getTime() {
		return time;
	}

	public void setTime(int time) {
		this.time = time;
	}

} import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {

	public static void main(String[] args) throws Exception{
		BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
		String str[] = r.readLine().split(" ");
		int max = Integer.parseInt(str[0]);
		Queue q = new Queue(max);
		int qtime = Integer.parseInt(str[1]);

		for(int i = 0 ; i < max ; i++ ){
			str = r.readLine().split(" ");
			q.enqueue(new Process(str[0], Integer.parseInt(str[1])));
		}

		int elapsedTime = 0;

		int count = 0;
		//?????\?????¬????????§???
		while(true){
			if(max <= count) break;
			Process p = q.dequeue();
			int time = p.getTime();

			if(time <= qtime){
				elapsedTime+= time;
				count++;
				System.out.println(p.getName() +" "+elapsedTime);
			}else{
				p.setTime(time - qtime);
				elapsedTime += qtime;
				q.enqueue(p);
			}

		}
	}

} Main public static void main(String[] args) throws Exception{
		BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
		String str[] = r.readLine().split(" ");
		int max = Integer.parseInt(str[0]);
		Queue q = new Queue(max);
		int qtime = Integer.parseInt(str[1]);

		for(int i = 0 ; i < max ; i++ ){
			str = r.readLine().split(" ");
			q.enqueue(new Process(str[0], Integer.parseInt(str[1])));
		}

		int elapsedTime = 0;

		int count = 0;
		//?????\?????¬????????§???
		while(true){
			if(max <= count) break;
			Process p = q.dequeue();
			int time = p.getTime();

			if(time <= qtime){
				elapsedTime+= time;
				count++;
				System.out.println(p.getName() +" "+elapsedTime);
			}else{
				p.setTime(time - qtime);
				elapsedTime += qtime;
				q.enqueue(p);
			}

		}
	} main {
		BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
		String str[] = r.readLine().split(" ");
		int max = Integer.parseInt(str[0]);
		Queue q = new Queue(max);
		int qtime = Integer.parseInt(str[1]);

		for(int i = 0 ; i < max ; i++ ){
			str = r.readLine().split(" ");
			q.enqueue(new Process(str[0], Integer.parseInt(str[1])));
		}

		int elapsedTime = 0;

		int count = 0;
		//?????\?????¬????????§???
		while(true){
			if(max <= count) break;
			Process p = q.dequeue();
			int time = p.getTime();

			if(time <= qtime){
				elapsedTime+= time;
				count++;
				System.out.println(p.getName() +" "+elapsedTime);
			}else{
				p.setTime(time - qtime);
				elapsedTime += qtime;
				q.enqueue(p);
			}

		}
	} BufferedReader r = new BufferedReader(new InputStreamReader(System.in)); r new BufferedReader(new InputStreamReader(System.in)) String str[] = r.readLine().split(" "); str r.readLine().split(" ") r.readLine().split r.readLine() r.readLine r " " int max = Integer.parseInt(str[0]); max Integer.parseInt(str[0]) Integer.parseInt Integer str[0] str 0 Queue q = new Queue(max); q new Queue(max) int qtime = Integer.parseInt(str[1]); qtime Integer.parseInt(str[1]) Integer.parseInt Integer str[1] str 1 for(int i = 0 ; i < max ; i++ ){
			str = r.readLine().split(" ");
			q.enqueue(new Process(str[0], Integer.parseInt(str[1])));
		} int i = 0 ; int i = 0 ; i 0 i < max i max i++ i++ i {
			str = r.readLine().split(" ");
			q.enqueue(new Process(str[0], Integer.parseInt(str[1])));
		} {
			str = r.readLine().split(" ");
			q.enqueue(new Process(str[0], Integer.parseInt(str[1])));
		} str = r.readLine().split(" ") str r.readLine().split(" ") r.readLine().split r.readLine() r.readLine r " " q.enqueue(new Process(str[0], Integer.parseInt(str[1]))) q.enqueue q new Process(str[0], Integer.parseInt(str[1])) int elapsedTime = 0; elapsedTime 0 int count = 0; count 0 while(true){
			if(max <= count) break;
			Process p = q.dequeue();
			int time = p.getTime();

			if(time <= qtime){
				elapsedTime+= time;
				count++;
				System.out.println(p.getName() +" "+elapsedTime);
			}else{
				p.setTime(time - qtime);
				elapsedTime += qtime;
				q.enqueue(p);
			}

		} true {
			if(max <= count) break;
			Process p = q.dequeue();
			int time = p.getTime();

			if(time <= qtime){
				elapsedTime+= time;
				count++;
				System.out.println(p.getName() +" "+elapsedTime);
			}else{
				p.setTime(time - qtime);
				elapsedTime += qtime;
				q.enqueue(p);
			}

		} if(max <= count) break; max <= count max count break; Process p = q.dequeue(); p q.dequeue() q.dequeue q int time = p.getTime(); time p.getTime() p.getTime p if(time <= qtime){
				elapsedTime+= time;
				count++;
				System.out.println(p.getName() +" "+elapsedTime);
			}else{
				p.setTime(time - qtime);
				elapsedTime += qtime;
				q.enqueue(p);
			} time <= qtime time qtime {
				elapsedTime+= time;
				count++;
				System.out.println(p.getName() +" "+elapsedTime);
			} elapsedTime+= time elapsedTime time count++ count System.out.println(p.getName() +" "+elapsedTime) System.out.println System.out System System.out p.getName() +" "+elapsedTime p.getName() +" "+elapsedTime p.getName() p.getName p " " elapsedTime {
				p.setTime(time - qtime);
				elapsedTime += qtime;
				q.enqueue(p);
			} p.setTime(time - qtime) p.setTime p time - qtime time qtime elapsedTime += qtime elapsedTime qtime q.enqueue(p) q.enqueue q p String[] args args class Queue{

	Process[] processAry;
	int top;
	int tail;
	int max;

	public Queue(int max){
		top = tail = 0;
		processAry = new Process[max];
		this.max = max;
	}

	public void enqueue(Process process) throws Exception{
			processAry[top] = process;
			top = (top + 1) % max;
	}

	public Process dequeue() throws Exception{

			Process p = processAry[tail];
			tail = (tail + 1) % max;
			return p;

	}

} Queue Process[] processAry; processAry int top; top int tail; tail int max; max public Queue(int max){
		top = tail = 0;
		processAry = new Process[max];
		this.max = max;
	} Queue {
		top = tail = 0;
		processAry = new Process[max];
		this.max = max;
	} top = tail = 0 top tail = 0 tail 0 processAry = new Process[max] processAry new Process[max] max this.max = max this.max this this.max max int max max public void enqueue(Process process) throws Exception{
			processAry[top] = process;
			top = (top + 1) % max;
	} enqueue {
			processAry[top] = process;
			top = (top + 1) % max;
	} processAry[top] = process processAry[top] processAry top process top = (top + 1) % max top (top + 1) % max (top + 1) top 1 max Process process process public Process dequeue() throws Exception{

			Process p = processAry[tail];
			tail = (tail + 1) % max;
			return p;

	} dequeue {

			Process p = processAry[tail];
			tail = (tail + 1) % max;
			return p;

	} Process p = processAry[tail]; p processAry[tail] processAry tail tail = (tail + 1) % max tail (tail + 1) % max (tail + 1) tail 1 max return p; p class Process{
	private String name;
	private int time;

	public Process(String name,int time) {
		this.name = name;
		this.time = time;
	}

	public String getName() {
		return name;
	}

	public int getTime() {
		return time;
	}

	public void setTime(int time) {
		this.time = time;
	}

} Process private String name; name private int time; time public Process(String name,int time) {
		this.name = name;
		this.time = time;
	} Process {
		this.name = name;
		this.time = time;
	} this.name = name this.name this this.name name this.time = time this.time this this.time time String name name int time time public String getName() {
		return name;
	} getName {
		return name;
	} return name; name public int getTime() {
		return time;
	} getTime {
		return time;
	} return time; time public void setTime(int time) {
		this.time = time;
	} setTime {
		this.time = time;
	} this.time = time this.time this this.time time int time time public class Main {

	public static void main(String[] args) throws Exception{
		BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
		String str[] = r.readLine().split(" ");
		int max = Integer.parseInt(str[0]);
		Queue q = new Queue(max);
		int qtime = Integer.parseInt(str[1]);

		for(int i = 0 ; i < max ; i++ ){
			str = r.readLine().split(" ");
			q.enqueue(new Process(str[0], Integer.parseInt(str[1])));
		}

		int elapsedTime = 0;

		int count = 0;
		//?????\?????¬????????§???
		while(true){
			if(max <= count) break;
			Process p = q.dequeue();
			int time = p.getTime();

			if(time <= qtime){
				elapsedTime+= time;
				count++;
				System.out.println(p.getName() +" "+elapsedTime);
			}else{
				p.setTime(time - qtime);
				elapsedTime += qtime;
				q.enqueue(p);
			}

		}
	}

} public class Main {

	public static void main(String[] args) throws Exception{
		BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
		String str[] = r.readLine().split(" ");
		int max = Integer.parseInt(str[0]);
		Queue q = new Queue(max);
		int qtime = Integer.parseInt(str[1]);

		for(int i = 0 ; i < max ; i++ ){
			str = r.readLine().split(" ");
			q.enqueue(new Process(str[0], Integer.parseInt(str[1])));
		}

		int elapsedTime = 0;

		int count = 0;
		//?????\?????¬????????§???
		while(true){
			if(max <= count) break;
			Process p = q.dequeue();
			int time = p.getTime();

			if(time <= qtime){
				elapsedTime+= time;
				count++;
				System.out.println(p.getName() +" "+elapsedTime);
			}else{
				p.setTime(time - qtime);
				elapsedTime += qtime;
				q.enqueue(p);
			}

		}
	}

} Main
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception{
		BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
		String str[] = r.readLine().split(" ");
		int max = Integer.parseInt(str[0]);
		Queue q = new Queue(max);
		int qtime = Integer.parseInt(str[1]);

		for(int i = 0 ; i < max ; i++ ){
			str = r.readLine().split(" ");
			q.enqueue(new Process(str[0], Integer.parseInt(str[1])));
		}

		int elapsedTime = 0;

		int count = 0;
		//?????\?????¬????????§???
		while(true){
			if(max <= count) break;
			Process p = q.dequeue();
			int time = p.getTime();

			if(time <= qtime){
				elapsedTime+= time;
				count++;
				System.out.println(p.getName() +" "+elapsedTime);
			}else{
				p.setTime(time - qtime);
				elapsedTime += qtime;
				q.enqueue(p);
			}

		}
	}

}

class Queue{

	Process[] processAry;
	int top;
	int tail;
	int max;

	public Queue(int max){
		top = tail = 0;
		processAry = new Process[max];
		this.max = max;
	}

	public void enqueue(Process process) throws Exception{
			processAry[top] = process;
			top = (top + 1) % max;
	}

	public Process dequeue() throws Exception{

			Process p = processAry[tail];
			tail = (tail + 1) % max;
			return p;

	}

}

class Process{
	private String name;
	private int time;

	public Process(String name,int time) {
		this.name = name;
		this.time = time;
	}

	public String getName() {
		return name;
	}

	public int getTime() {
		return time;
	}

	public void setTime(int time) {
		this.time = time;
	}

}