import java.util.LinkedList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in); 

		LinkedList<Process> processQueue = new LinkedList<Process>();

		int n = sc.nextInt();
		int quantum = sc.nextInt();
		for (int i = 0; i < n; i++) {
			processQueue.add(new Process(sc.next(), sc.nextInt()));
		}
		
		for (int spendTime = 0; !processQueue.isEmpty(); ) {
			Process run = processQueue.remove();
			if (run.pRemain > quantum) {
				run.pRemain -= quantum;
				processQueue.add(run);
				spendTime += quantum;
			} else if (run.pRemain == quantum) {
				run.pRemain -= quantum;
				spendTime += quantum;
				printProcess(run, spendTime);
			} else {
				spendTime += run.pRemain;
				run.pRemain = 0;
				printProcess(run, spendTime);
			}
		}
    	
        sc.close();
	}

	private static void printProcess(Process run, int eTime) {
		StringBuffer str = new StringBuffer();

		str.append(run.pName);
		str.append(" ");
		str.append(eTime);

		System.out.println(str);
	}
}

class Process {
	String pName;
	int pRemain;
	int eTime;
	
	Process(String name, int time) {
		pName = name;
		pRemain = time;
		eTime = 0;
	}
} import java.util.LinkedList; LinkedList java.util import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in); 

		LinkedList<Process> processQueue = new LinkedList<Process>();

		int n = sc.nextInt();
		int quantum = sc.nextInt();
		for (int i = 0; i < n; i++) {
			processQueue.add(new Process(sc.next(), sc.nextInt()));
		}
		
		for (int spendTime = 0; !processQueue.isEmpty(); ) {
			Process run = processQueue.remove();
			if (run.pRemain > quantum) {
				run.pRemain -= quantum;
				processQueue.add(run);
				spendTime += quantum;
			} else if (run.pRemain == quantum) {
				run.pRemain -= quantum;
				spendTime += quantum;
				printProcess(run, spendTime);
			} else {
				spendTime += run.pRemain;
				run.pRemain = 0;
				printProcess(run, spendTime);
			}
		}
    	
        sc.close();
	}

	private static void printProcess(Process run, int eTime) {
		StringBuffer str = new StringBuffer();

		str.append(run.pName);
		str.append(" ");
		str.append(eTime);

		System.out.println(str);
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in); 

		LinkedList<Process> processQueue = new LinkedList<Process>();

		int n = sc.nextInt();
		int quantum = sc.nextInt();
		for (int i = 0; i < n; i++) {
			processQueue.add(new Process(sc.next(), sc.nextInt()));
		}
		
		for (int spendTime = 0; !processQueue.isEmpty(); ) {
			Process run = processQueue.remove();
			if (run.pRemain > quantum) {
				run.pRemain -= quantum;
				processQueue.add(run);
				spendTime += quantum;
			} else if (run.pRemain == quantum) {
				run.pRemain -= quantum;
				spendTime += quantum;
				printProcess(run, spendTime);
			} else {
				spendTime += run.pRemain;
				run.pRemain = 0;
				printProcess(run, spendTime);
			}
		}
    	
        sc.close();
	} main {
		Scanner sc = new Scanner(System.in); 

		LinkedList<Process> processQueue = new LinkedList<Process>();

		int n = sc.nextInt();
		int quantum = sc.nextInt();
		for (int i = 0; i < n; i++) {
			processQueue.add(new Process(sc.next(), sc.nextInt()));
		}
		
		for (int spendTime = 0; !processQueue.isEmpty(); ) {
			Process run = processQueue.remove();
			if (run.pRemain > quantum) {
				run.pRemain -= quantum;
				processQueue.add(run);
				spendTime += quantum;
			} else if (run.pRemain == quantum) {
				run.pRemain -= quantum;
				spendTime += quantum;
				printProcess(run, spendTime);
			} else {
				spendTime += run.pRemain;
				run.pRemain = 0;
				printProcess(run, spendTime);
			}
		}
    	
        sc.close();
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) LinkedList<Process> processQueue = new LinkedList<Process>(); processQueue new LinkedList<Process>() int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int quantum = sc.nextInt(); quantum sc.nextInt() sc.nextInt sc for (int i = 0; i < n; i++) {
			processQueue.add(new Process(sc.next(), sc.nextInt()));
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			processQueue.add(new Process(sc.next(), sc.nextInt()));
		} {
			processQueue.add(new Process(sc.next(), sc.nextInt()));
		} processQueue.add(new Process(sc.next(), sc.nextInt())) processQueue.add processQueue new Process(sc.next(), sc.nextInt()) for (int spendTime = 0; !processQueue.isEmpty(); ) {
			Process run = processQueue.remove();
			if (run.pRemain > quantum) {
				run.pRemain -= quantum;
				processQueue.add(run);
				spendTime += quantum;
			} else if (run.pRemain == quantum) {
				run.pRemain -= quantum;
				spendTime += quantum;
				printProcess(run, spendTime);
			} else {
				spendTime += run.pRemain;
				run.pRemain = 0;
				printProcess(run, spendTime);
			}
		} int spendTime = 0; int spendTime = 0; spendTime 0 !processQueue.isEmpty() processQueue.isEmpty() processQueue.isEmpty processQueue {
			Process run = processQueue.remove();
			if (run.pRemain > quantum) {
				run.pRemain -= quantum;
				processQueue.add(run);
				spendTime += quantum;
			} else if (run.pRemain == quantum) {
				run.pRemain -= quantum;
				spendTime += quantum;
				printProcess(run, spendTime);
			} else {
				spendTime += run.pRemain;
				run.pRemain = 0;
				printProcess(run, spendTime);
			}
		} {
			Process run = processQueue.remove();
			if (run.pRemain > quantum) {
				run.pRemain -= quantum;
				processQueue.add(run);
				spendTime += quantum;
			} else if (run.pRemain == quantum) {
				run.pRemain -= quantum;
				spendTime += quantum;
				printProcess(run, spendTime);
			} else {
				spendTime += run.pRemain;
				run.pRemain = 0;
				printProcess(run, spendTime);
			}
		} Process run = processQueue.remove(); run processQueue.remove() processQueue.remove processQueue if (run.pRemain > quantum) {
				run.pRemain -= quantum;
				processQueue.add(run);
				spendTime += quantum;
			} else if (run.pRemain == quantum) {
				run.pRemain -= quantum;
				spendTime += quantum;
				printProcess(run, spendTime);
			} else {
				spendTime += run.pRemain;
				run.pRemain = 0;
				printProcess(run, spendTime);
			} run.pRemain > quantum run.pRemain run run.pRemain quantum {
				run.pRemain -= quantum;
				processQueue.add(run);
				spendTime += quantum;
			} run.pRemain -= quantum run.pRemain run run.pRemain quantum processQueue.add(run) processQueue.add processQueue run spendTime += quantum spendTime quantum if (run.pRemain == quantum) {
				run.pRemain -= quantum;
				spendTime += quantum;
				printProcess(run, spendTime);
			} else {
				spendTime += run.pRemain;
				run.pRemain = 0;
				printProcess(run, spendTime);
			} run.pRemain == quantum run.pRemain run run.pRemain quantum {
				run.pRemain -= quantum;
				spendTime += quantum;
				printProcess(run, spendTime);
			} run.pRemain -= quantum run.pRemain run run.pRemain quantum spendTime += quantum spendTime quantum printProcess(run, spendTime) printProcess run spendTime {
				spendTime += run.pRemain;
				run.pRemain = 0;
				printProcess(run, spendTime);
			} spendTime += run.pRemain spendTime run.pRemain run run.pRemain run.pRemain = 0 run.pRemain run run.pRemain 0 printProcess(run, spendTime) printProcess run spendTime sc.close() sc.close sc String[] args args private static void printProcess(Process run, int eTime) {
		StringBuffer str = new StringBuffer();

		str.append(run.pName);
		str.append(" ");
		str.append(eTime);

		System.out.println(str);
	} printProcess {
		StringBuffer str = new StringBuffer();

		str.append(run.pName);
		str.append(" ");
		str.append(eTime);

		System.out.println(str);
	} StringBuffer str = new StringBuffer(); str new StringBuffer() str.append(run.pName) str.append str run.pName run run.pName str.append(" ") str.append str " " str.append(eTime) str.append str eTime System.out.println(str) System.out.println System.out System System.out str Process run run int eTime eTime class Process {
	String pName;
	int pRemain;
	int eTime;
	
	Process(String name, int time) {
		pName = name;
		pRemain = time;
		eTime = 0;
	}
} Process String pName; pName int pRemain; pRemain int eTime; eTime Process(String name, int time) {
		pName = name;
		pRemain = time;
		eTime = 0;
	} Process {
		pName = name;
		pRemain = time;
		eTime = 0;
	} pName = name pName name pRemain = time pRemain time eTime = 0 eTime 0 String name name int time time public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in); 

		LinkedList<Process> processQueue = new LinkedList<Process>();

		int n = sc.nextInt();
		int quantum = sc.nextInt();
		for (int i = 0; i < n; i++) {
			processQueue.add(new Process(sc.next(), sc.nextInt()));
		}
		
		for (int spendTime = 0; !processQueue.isEmpty(); ) {
			Process run = processQueue.remove();
			if (run.pRemain > quantum) {
				run.pRemain -= quantum;
				processQueue.add(run);
				spendTime += quantum;
			} else if (run.pRemain == quantum) {
				run.pRemain -= quantum;
				spendTime += quantum;
				printProcess(run, spendTime);
			} else {
				spendTime += run.pRemain;
				run.pRemain = 0;
				printProcess(run, spendTime);
			}
		}
    	
        sc.close();
	}

	private static void printProcess(Process run, int eTime) {
		StringBuffer str = new StringBuffer();

		str.append(run.pName);
		str.append(" ");
		str.append(eTime);

		System.out.println(str);
	}
} public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in); 

		LinkedList<Process> processQueue = new LinkedList<Process>();

		int n = sc.nextInt();
		int quantum = sc.nextInt();
		for (int i = 0; i < n; i++) {
			processQueue.add(new Process(sc.next(), sc.nextInt()));
		}
		
		for (int spendTime = 0; !processQueue.isEmpty(); ) {
			Process run = processQueue.remove();
			if (run.pRemain > quantum) {
				run.pRemain -= quantum;
				processQueue.add(run);
				spendTime += quantum;
			} else if (run.pRemain == quantum) {
				run.pRemain -= quantum;
				spendTime += quantum;
				printProcess(run, spendTime);
			} else {
				spendTime += run.pRemain;
				run.pRemain = 0;
				printProcess(run, spendTime);
			}
		}
    	
        sc.close();
	}

	private static void printProcess(Process run, int eTime) {
		StringBuffer str = new StringBuffer();

		str.append(run.pName);
		str.append(" ");
		str.append(eTime);

		System.out.println(str);
	}
} Main
import java.util.LinkedList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in); 

		LinkedList<Process> processQueue = new LinkedList<Process>();

		int n = sc.nextInt();
		int quantum = sc.nextInt();
		for (int i = 0; i < n; i++) {
			processQueue.add(new Process(sc.next(), sc.nextInt()));
		}
		
		for (int spendTime = 0; !processQueue.isEmpty(); ) {
			Process run = processQueue.remove();
			if (run.pRemain > quantum) {
				run.pRemain -= quantum;
				processQueue.add(run);
				spendTime += quantum;
			} else if (run.pRemain == quantum) {
				run.pRemain -= quantum;
				spendTime += quantum;
				printProcess(run, spendTime);
			} else {
				spendTime += run.pRemain;
				run.pRemain = 0;
				printProcess(run, spendTime);
			}
		}
    	
        sc.close();
	}

	private static void printProcess(Process run, int eTime) {
		StringBuffer str = new StringBuffer();

		str.append(run.pName);
		str.append(" ");
		str.append(eTime);

		System.out.println(str);
	}
}

class Process {
	String pName;
	int pRemain;
	int eTime;
	
	Process(String name, int time) {
		pName = name;
		pRemain = time;
		eTime = 0;
	}
}