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

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int ts = 0;
		
		Queue<Integer> qN = new LinkedList<>(); 
		Queue<String> qP = new LinkedList<>(); 
		
		String line = sc.nextLine();
		
		String[] lineList = line.split(" ");
		String[] itemsList = new String[Integer.parseInt(lineList[0])*2];
		
		int q = Integer.parseInt(lineList[1]);
		
		String[] items = new String[Integer.parseInt(lineList[0])];
		
		//add everything into queues
		for(int i = 0; i < Integer.parseInt(lineList[0]); i++) {
			items[i] = sc.nextLine();
			itemsList = items[i].split(" ");
			qP.add(itemsList[0]);
			qN.add(Integer.parseInt(itemsList[1]));
		}
		
		while(!qP.isEmpty()){
			if(q - qN.peek() < 0) {
				qN.add(-1*(q-qN.remove()));
				qP.add(qP.remove());
				ts += q;
			}
			else {
				ts += qN.remove();
				System.out.println(qP.remove() + " " + ts);
			}
		}
		
	}
}
 import java.util.Scanner; Scanner java.util import java.util.LinkedList; LinkedList java.util import java.util.Queue; Queue java.util public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int ts = 0;
		
		Queue<Integer> qN = new LinkedList<>(); 
		Queue<String> qP = new LinkedList<>(); 
		
		String line = sc.nextLine();
		
		String[] lineList = line.split(" ");
		String[] itemsList = new String[Integer.parseInt(lineList[0])*2];
		
		int q = Integer.parseInt(lineList[1]);
		
		String[] items = new String[Integer.parseInt(lineList[0])];
		
		//add everything into queues
		for(int i = 0; i < Integer.parseInt(lineList[0]); i++) {
			items[i] = sc.nextLine();
			itemsList = items[i].split(" ");
			qP.add(itemsList[0]);
			qN.add(Integer.parseInt(itemsList[1]));
		}
		
		while(!qP.isEmpty()){
			if(q - qN.peek() < 0) {
				qN.add(-1*(q-qN.remove()));
				qP.add(qP.remove());
				ts += q;
			}
			else {
				ts += qN.remove();
				System.out.println(qP.remove() + " " + ts);
			}
		}
		
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int ts = 0;
		
		Queue<Integer> qN = new LinkedList<>(); 
		Queue<String> qP = new LinkedList<>(); 
		
		String line = sc.nextLine();
		
		String[] lineList = line.split(" ");
		String[] itemsList = new String[Integer.parseInt(lineList[0])*2];
		
		int q = Integer.parseInt(lineList[1]);
		
		String[] items = new String[Integer.parseInt(lineList[0])];
		
		//add everything into queues
		for(int i = 0; i < Integer.parseInt(lineList[0]); i++) {
			items[i] = sc.nextLine();
			itemsList = items[i].split(" ");
			qP.add(itemsList[0]);
			qN.add(Integer.parseInt(itemsList[1]));
		}
		
		while(!qP.isEmpty()){
			if(q - qN.peek() < 0) {
				qN.add(-1*(q-qN.remove()));
				qP.add(qP.remove());
				ts += q;
			}
			else {
				ts += qN.remove();
				System.out.println(qP.remove() + " " + ts);
			}
		}
		
	} main {
		Scanner sc = new Scanner(System.in);
		int ts = 0;
		
		Queue<Integer> qN = new LinkedList<>(); 
		Queue<String> qP = new LinkedList<>(); 
		
		String line = sc.nextLine();
		
		String[] lineList = line.split(" ");
		String[] itemsList = new String[Integer.parseInt(lineList[0])*2];
		
		int q = Integer.parseInt(lineList[1]);
		
		String[] items = new String[Integer.parseInt(lineList[0])];
		
		//add everything into queues
		for(int i = 0; i < Integer.parseInt(lineList[0]); i++) {
			items[i] = sc.nextLine();
			itemsList = items[i].split(" ");
			qP.add(itemsList[0]);
			qN.add(Integer.parseInt(itemsList[1]));
		}
		
		while(!qP.isEmpty()){
			if(q - qN.peek() < 0) {
				qN.add(-1*(q-qN.remove()));
				qP.add(qP.remove());
				ts += q;
			}
			else {
				ts += qN.remove();
				System.out.println(qP.remove() + " " + ts);
			}
		}
		
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int ts = 0; ts 0 Queue<Integer> qN = new LinkedList<>(); qN new LinkedList<>() Queue<String> qP = new LinkedList<>(); qP new LinkedList<>() String line = sc.nextLine(); line sc.nextLine() sc.nextLine sc String[] lineList = line.split(" "); lineList line.split(" ") line.split line " " String[] itemsList = new String[Integer.parseInt(lineList[0])*2]; itemsList new String[Integer.parseInt(lineList[0])*2] Integer.parseInt(lineList[0])*2 Integer.parseInt(lineList[0]) Integer.parseInt Integer lineList[0] lineList 0 2 int q = Integer.parseInt(lineList[1]); q Integer.parseInt(lineList[1]) Integer.parseInt Integer lineList[1] lineList 1 String[] items = new String[Integer.parseInt(lineList[0])]; items new String[Integer.parseInt(lineList[0])] Integer.parseInt(lineList[0]) Integer.parseInt Integer lineList[0] lineList 0 for(int i = 0; i < Integer.parseInt(lineList[0]); i++) {
			items[i] = sc.nextLine();
			itemsList = items[i].split(" ");
			qP.add(itemsList[0]);
			qN.add(Integer.parseInt(itemsList[1]));
		} int i = 0; int i = 0; i 0 i < Integer.parseInt(lineList[0]) i Integer.parseInt(lineList[0]) Integer.parseInt Integer lineList[0] lineList 0 i++ i++ i {
			items[i] = sc.nextLine();
			itemsList = items[i].split(" ");
			qP.add(itemsList[0]);
			qN.add(Integer.parseInt(itemsList[1]));
		} {
			items[i] = sc.nextLine();
			itemsList = items[i].split(" ");
			qP.add(itemsList[0]);
			qN.add(Integer.parseInt(itemsList[1]));
		} items[i] = sc.nextLine() items[i] items i sc.nextLine() sc.nextLine sc itemsList = items[i].split(" ") itemsList items[i].split(" ") items[i].split items[i] items i " " qP.add(itemsList[0]) qP.add qP itemsList[0] itemsList 0 qN.add(Integer.parseInt(itemsList[1])) qN.add qN Integer.parseInt(itemsList[1]) Integer.parseInt Integer itemsList[1] itemsList 1 while(!qP.isEmpty()){
			if(q - qN.peek() < 0) {
				qN.add(-1*(q-qN.remove()));
				qP.add(qP.remove());
				ts += q;
			}
			else {
				ts += qN.remove();
				System.out.println(qP.remove() + " " + ts);
			}
		} !qP.isEmpty() qP.isEmpty() qP.isEmpty qP {
			if(q - qN.peek() < 0) {
				qN.add(-1*(q-qN.remove()));
				qP.add(qP.remove());
				ts += q;
			}
			else {
				ts += qN.remove();
				System.out.println(qP.remove() + " " + ts);
			}
		} if(q - qN.peek() < 0) {
				qN.add(-1*(q-qN.remove()));
				qP.add(qP.remove());
				ts += q;
			}
			else {
				ts += qN.remove();
				System.out.println(qP.remove() + " " + ts);
			} q - qN.peek() < 0 q - qN.peek() q qN.peek() qN.peek qN 0 {
				qN.add(-1*(q-qN.remove()));
				qP.add(qP.remove());
				ts += q;
			} qN.add(-1*(q-qN.remove())) qN.add qN -1*(q-qN.remove()) -1 1 (q-qN.remove()) q qN.remove() qN.remove qN qP.add(qP.remove()) qP.add qP qP.remove() qP.remove qP ts += q ts q {
				ts += qN.remove();
				System.out.println(qP.remove() + " " + ts);
			} ts += qN.remove() ts qN.remove() qN.remove qN System.out.println(qP.remove() + " " + ts) System.out.println System.out System System.out qP.remove() + " " + ts qP.remove() + " " + ts qP.remove() qP.remove qP " " ts String[] args args public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int ts = 0;
		
		Queue<Integer> qN = new LinkedList<>(); 
		Queue<String> qP = new LinkedList<>(); 
		
		String line = sc.nextLine();
		
		String[] lineList = line.split(" ");
		String[] itemsList = new String[Integer.parseInt(lineList[0])*2];
		
		int q = Integer.parseInt(lineList[1]);
		
		String[] items = new String[Integer.parseInt(lineList[0])];
		
		//add everything into queues
		for(int i = 0; i < Integer.parseInt(lineList[0]); i++) {
			items[i] = sc.nextLine();
			itemsList = items[i].split(" ");
			qP.add(itemsList[0]);
			qN.add(Integer.parseInt(itemsList[1]));
		}
		
		while(!qP.isEmpty()){
			if(q - qN.peek() < 0) {
				qN.add(-1*(q-qN.remove()));
				qP.add(qP.remove());
				ts += q;
			}
			else {
				ts += qN.remove();
				System.out.println(qP.remove() + " " + ts);
			}
		}
		
	}
} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int ts = 0;
		
		Queue<Integer> qN = new LinkedList<>(); 
		Queue<String> qP = new LinkedList<>(); 
		
		String line = sc.nextLine();
		
		String[] lineList = line.split(" ");
		String[] itemsList = new String[Integer.parseInt(lineList[0])*2];
		
		int q = Integer.parseInt(lineList[1]);
		
		String[] items = new String[Integer.parseInt(lineList[0])];
		
		//add everything into queues
		for(int i = 0; i < Integer.parseInt(lineList[0]); i++) {
			items[i] = sc.nextLine();
			itemsList = items[i].split(" ");
			qP.add(itemsList[0]);
			qN.add(Integer.parseInt(itemsList[1]));
		}
		
		while(!qP.isEmpty()){
			if(q - qN.peek() < 0) {
				qN.add(-1*(q-qN.remove()));
				qP.add(qP.remove());
				ts += q;
			}
			else {
				ts += qN.remove();
				System.out.println(qP.remove() + " " + ts);
			}
		}
		
	}
} Main
import java.util.Scanner;
import java.util.LinkedList; 
import java.util.Queue; 

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int ts = 0;
		
		Queue<Integer> qN = new LinkedList<>(); 
		Queue<String> qP = new LinkedList<>(); 
		
		String line = sc.nextLine();
		
		String[] lineList = line.split(" ");
		String[] itemsList = new String[Integer.parseInt(lineList[0])*2];
		
		int q = Integer.parseInt(lineList[1]);
		
		String[] items = new String[Integer.parseInt(lineList[0])];
		
		//add everything into queues
		for(int i = 0; i < Integer.parseInt(lineList[0]); i++) {
			items[i] = sc.nextLine();
			itemsList = items[i].split(" ");
			qP.add(itemsList[0]);
			qN.add(Integer.parseInt(itemsList[1]));
		}
		
		while(!qP.isEmpty()){
			if(q - qN.peek() < 0) {
				qN.add(-1*(q-qN.remove()));
				qP.add(qP.remove());
				ts += q;
			}
			else {
				ts += qN.remove();
				System.out.println(qP.remove() + " " + ts);
			}
		}
		
	}
}

