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

public class Main {

	public static void main(String[] args) {
		
		Scanner in = new Scanner(System.in);
		int timePassed= 0;
		int n = in.nextInt();
		int q = in.nextInt();
		Queue<Integer> process = new LinkedList<Integer>();
		Queue<String> name = new LinkedList<String>();
		ArrayList<String> nameRt = new ArrayList<String>();
		ArrayList<Integer> processRt = new ArrayList<Integer>();
		for(int i = 0;i<n;i++) {
			name.add(in.next());
			process.add(in.nextInt());
		}
		while(!process.isEmpty()) {
			int number = process.remove();
			String nme = name.remove();
			if(number-q<=0) {
				processRt.add(number+timePassed);
				nameRt.add(nme);
				timePassed+=number;
			}
			else {
				process.add(number-q);
				name.add(nme);
				timePassed+=q;
			}
			
		}
		for(int i =0; i<n;i++) {
			System.out.println(nameRt.get(i)+" "+processRt.get(i));
		}
		//System.out.println(process.toString());
		//System.out.println(name.toString());
		
		/**
		int result = 0;
		Stack<Integer> stack = new Stack<Integer>(); 
		Scanner in = new Scanner(System.in);
		String stringIn = in.nextLine();
		String[] lineString = stringIn.split(" ");
		for(int i = 0; i<lineString.length;i++) {
			if(lineString[i].equals("*")) {
				int n = stack.pop()*stack.pop();
				stack.push(n);
			}
			else if(lineString[i].equals("+")) {
				int n = stack.pop()+stack.pop();
				stack.push(n);
			}
			else if(lineString[i].equals("-")) {
				int n1 = stack.pop();
				int n2 = stack.pop();
				int n = n2-n1;
				stack.push(n);
			}
			else {
			stack.push(Integer.parseInt(lineString[i]));	
			} 
			//System.out.println(stack.toString());
			
		}
		result = stack.pop();
		System.out.println(result);
		*/
	}

} import java.util.ArrayList; ArrayList java.util import java.util.LinkedList; LinkedList java.util import java.util.Queue; Queue java.util import java.util.Scanner; Scanner java.util import java.util.Stack; Stack java.util public class Main {

	public static void main(String[] args) {
		
		Scanner in = new Scanner(System.in);
		int timePassed= 0;
		int n = in.nextInt();
		int q = in.nextInt();
		Queue<Integer> process = new LinkedList<Integer>();
		Queue<String> name = new LinkedList<String>();
		ArrayList<String> nameRt = new ArrayList<String>();
		ArrayList<Integer> processRt = new ArrayList<Integer>();
		for(int i = 0;i<n;i++) {
			name.add(in.next());
			process.add(in.nextInt());
		}
		while(!process.isEmpty()) {
			int number = process.remove();
			String nme = name.remove();
			if(number-q<=0) {
				processRt.add(number+timePassed);
				nameRt.add(nme);
				timePassed+=number;
			}
			else {
				process.add(number-q);
				name.add(nme);
				timePassed+=q;
			}
			
		}
		for(int i =0; i<n;i++) {
			System.out.println(nameRt.get(i)+" "+processRt.get(i));
		}
		//System.out.println(process.toString());
		//System.out.println(name.toString());
		
		/**
		int result = 0;
		Stack<Integer> stack = new Stack<Integer>(); 
		Scanner in = new Scanner(System.in);
		String stringIn = in.nextLine();
		String[] lineString = stringIn.split(" ");
		for(int i = 0; i<lineString.length;i++) {
			if(lineString[i].equals("*")) {
				int n = stack.pop()*stack.pop();
				stack.push(n);
			}
			else if(lineString[i].equals("+")) {
				int n = stack.pop()+stack.pop();
				stack.push(n);
			}
			else if(lineString[i].equals("-")) {
				int n1 = stack.pop();
				int n2 = stack.pop();
				int n = n2-n1;
				stack.push(n);
			}
			else {
			stack.push(Integer.parseInt(lineString[i]));	
			} 
			//System.out.println(stack.toString());
			
		}
		result = stack.pop();
		System.out.println(result);
		*/
	}

} Main public static void main(String[] args) {
		
		Scanner in = new Scanner(System.in);
		int timePassed= 0;
		int n = in.nextInt();
		int q = in.nextInt();
		Queue<Integer> process = new LinkedList<Integer>();
		Queue<String> name = new LinkedList<String>();
		ArrayList<String> nameRt = new ArrayList<String>();
		ArrayList<Integer> processRt = new ArrayList<Integer>();
		for(int i = 0;i<n;i++) {
			name.add(in.next());
			process.add(in.nextInt());
		}
		while(!process.isEmpty()) {
			int number = process.remove();
			String nme = name.remove();
			if(number-q<=0) {
				processRt.add(number+timePassed);
				nameRt.add(nme);
				timePassed+=number;
			}
			else {
				process.add(number-q);
				name.add(nme);
				timePassed+=q;
			}
			
		}
		for(int i =0; i<n;i++) {
			System.out.println(nameRt.get(i)+" "+processRt.get(i));
		}
		//System.out.println(process.toString());
		//System.out.println(name.toString());
		
		/**
		int result = 0;
		Stack<Integer> stack = new Stack<Integer>(); 
		Scanner in = new Scanner(System.in);
		String stringIn = in.nextLine();
		String[] lineString = stringIn.split(" ");
		for(int i = 0; i<lineString.length;i++) {
			if(lineString[i].equals("*")) {
				int n = stack.pop()*stack.pop();
				stack.push(n);
			}
			else if(lineString[i].equals("+")) {
				int n = stack.pop()+stack.pop();
				stack.push(n);
			}
			else if(lineString[i].equals("-")) {
				int n1 = stack.pop();
				int n2 = stack.pop();
				int n = n2-n1;
				stack.push(n);
			}
			else {
			stack.push(Integer.parseInt(lineString[i]));	
			} 
			//System.out.println(stack.toString());
			
		}
		result = stack.pop();
		System.out.println(result);
		*/
	} main {
		
		Scanner in = new Scanner(System.in);
		int timePassed= 0;
		int n = in.nextInt();
		int q = in.nextInt();
		Queue<Integer> process = new LinkedList<Integer>();
		Queue<String> name = new LinkedList<String>();
		ArrayList<String> nameRt = new ArrayList<String>();
		ArrayList<Integer> processRt = new ArrayList<Integer>();
		for(int i = 0;i<n;i++) {
			name.add(in.next());
			process.add(in.nextInt());
		}
		while(!process.isEmpty()) {
			int number = process.remove();
			String nme = name.remove();
			if(number-q<=0) {
				processRt.add(number+timePassed);
				nameRt.add(nme);
				timePassed+=number;
			}
			else {
				process.add(number-q);
				name.add(nme);
				timePassed+=q;
			}
			
		}
		for(int i =0; i<n;i++) {
			System.out.println(nameRt.get(i)+" "+processRt.get(i));
		}
		//System.out.println(process.toString());
		//System.out.println(name.toString());
		
		/**
		int result = 0;
		Stack<Integer> stack = new Stack<Integer>(); 
		Scanner in = new Scanner(System.in);
		String stringIn = in.nextLine();
		String[] lineString = stringIn.split(" ");
		for(int i = 0; i<lineString.length;i++) {
			if(lineString[i].equals("*")) {
				int n = stack.pop()*stack.pop();
				stack.push(n);
			}
			else if(lineString[i].equals("+")) {
				int n = stack.pop()+stack.pop();
				stack.push(n);
			}
			else if(lineString[i].equals("-")) {
				int n1 = stack.pop();
				int n2 = stack.pop();
				int n = n2-n1;
				stack.push(n);
			}
			else {
			stack.push(Integer.parseInt(lineString[i]));	
			} 
			//System.out.println(stack.toString());
			
		}
		result = stack.pop();
		System.out.println(result);
		*/
	} Scanner in = new Scanner(System.in); in new Scanner(System.in) int timePassed= 0; timePassed 0 int n = in.nextInt(); n in.nextInt() in.nextInt in int q = in.nextInt(); q in.nextInt() in.nextInt in Queue<Integer> process = new LinkedList<Integer>(); process new LinkedList<Integer>() Queue<String> name = new LinkedList<String>(); name new LinkedList<String>() ArrayList<String> nameRt = new ArrayList<String>(); nameRt new ArrayList<String>() ArrayList<Integer> processRt = new ArrayList<Integer>(); processRt new ArrayList<Integer>() for(int i = 0;i<n;i++) {
			name.add(in.next());
			process.add(in.nextInt());
		} int i = 0; int i = 0; i 0 i<n i n i++ i++ i {
			name.add(in.next());
			process.add(in.nextInt());
		} {
			name.add(in.next());
			process.add(in.nextInt());
		} name.add(in.next()) name.add name in.next() in.next in process.add(in.nextInt()) process.add process in.nextInt() in.nextInt in while(!process.isEmpty()) {
			int number = process.remove();
			String nme = name.remove();
			if(number-q<=0) {
				processRt.add(number+timePassed);
				nameRt.add(nme);
				timePassed+=number;
			}
			else {
				process.add(number-q);
				name.add(nme);
				timePassed+=q;
			}
			
		} !process.isEmpty() process.isEmpty() process.isEmpty process {
			int number = process.remove();
			String nme = name.remove();
			if(number-q<=0) {
				processRt.add(number+timePassed);
				nameRt.add(nme);
				timePassed+=number;
			}
			else {
				process.add(number-q);
				name.add(nme);
				timePassed+=q;
			}
			
		} int number = process.remove(); number process.remove() process.remove process String nme = name.remove(); nme name.remove() name.remove name if(number-q<=0) {
				processRt.add(number+timePassed);
				nameRt.add(nme);
				timePassed+=number;
			}
			else {
				process.add(number-q);
				name.add(nme);
				timePassed+=q;
			} number-q<=0 number-q number q 0 {
				processRt.add(number+timePassed);
				nameRt.add(nme);
				timePassed+=number;
			} processRt.add(number+timePassed) processRt.add processRt number+timePassed number timePassed nameRt.add(nme) nameRt.add nameRt nme timePassed+=number timePassed number {
				process.add(number-q);
				name.add(nme);
				timePassed+=q;
			} process.add(number-q) process.add process number-q number q name.add(nme) name.add name nme timePassed+=q timePassed q for(int i =0; i<n;i++) {
			System.out.println(nameRt.get(i)+" "+processRt.get(i));
		} int i =0; int i =0; i 0 i<n i n i++ i++ i {
			System.out.println(nameRt.get(i)+" "+processRt.get(i));
		} {
			System.out.println(nameRt.get(i)+" "+processRt.get(i));
		} System.out.println(nameRt.get(i)+" "+processRt.get(i)) System.out.println System.out System System.out nameRt.get(i)+" "+processRt.get(i) nameRt.get(i)+" "+processRt.get(i) nameRt.get(i) nameRt.get nameRt i " " processRt.get(i) processRt.get processRt i String[] args args public class Main {

	public static void main(String[] args) {
		
		Scanner in = new Scanner(System.in);
		int timePassed= 0;
		int n = in.nextInt();
		int q = in.nextInt();
		Queue<Integer> process = new LinkedList<Integer>();
		Queue<String> name = new LinkedList<String>();
		ArrayList<String> nameRt = new ArrayList<String>();
		ArrayList<Integer> processRt = new ArrayList<Integer>();
		for(int i = 0;i<n;i++) {
			name.add(in.next());
			process.add(in.nextInt());
		}
		while(!process.isEmpty()) {
			int number = process.remove();
			String nme = name.remove();
			if(number-q<=0) {
				processRt.add(number+timePassed);
				nameRt.add(nme);
				timePassed+=number;
			}
			else {
				process.add(number-q);
				name.add(nme);
				timePassed+=q;
			}
			
		}
		for(int i =0; i<n;i++) {
			System.out.println(nameRt.get(i)+" "+processRt.get(i));
		}
		//System.out.println(process.toString());
		//System.out.println(name.toString());
		
		/**
		int result = 0;
		Stack<Integer> stack = new Stack<Integer>(); 
		Scanner in = new Scanner(System.in);
		String stringIn = in.nextLine();
		String[] lineString = stringIn.split(" ");
		for(int i = 0; i<lineString.length;i++) {
			if(lineString[i].equals("*")) {
				int n = stack.pop()*stack.pop();
				stack.push(n);
			}
			else if(lineString[i].equals("+")) {
				int n = stack.pop()+stack.pop();
				stack.push(n);
			}
			else if(lineString[i].equals("-")) {
				int n1 = stack.pop();
				int n2 = stack.pop();
				int n = n2-n1;
				stack.push(n);
			}
			else {
			stack.push(Integer.parseInt(lineString[i]));	
			} 
			//System.out.println(stack.toString());
			
		}
		result = stack.pop();
		System.out.println(result);
		*/
	}

} public class Main {

	public static void main(String[] args) {
		
		Scanner in = new Scanner(System.in);
		int timePassed= 0;
		int n = in.nextInt();
		int q = in.nextInt();
		Queue<Integer> process = new LinkedList<Integer>();
		Queue<String> name = new LinkedList<String>();
		ArrayList<String> nameRt = new ArrayList<String>();
		ArrayList<Integer> processRt = new ArrayList<Integer>();
		for(int i = 0;i<n;i++) {
			name.add(in.next());
			process.add(in.nextInt());
		}
		while(!process.isEmpty()) {
			int number = process.remove();
			String nme = name.remove();
			if(number-q<=0) {
				processRt.add(number+timePassed);
				nameRt.add(nme);
				timePassed+=number;
			}
			else {
				process.add(number-q);
				name.add(nme);
				timePassed+=q;
			}
			
		}
		for(int i =0; i<n;i++) {
			System.out.println(nameRt.get(i)+" "+processRt.get(i));
		}
		//System.out.println(process.toString());
		//System.out.println(name.toString());
		
		/**
		int result = 0;
		Stack<Integer> stack = new Stack<Integer>(); 
		Scanner in = new Scanner(System.in);
		String stringIn = in.nextLine();
		String[] lineString = stringIn.split(" ");
		for(int i = 0; i<lineString.length;i++) {
			if(lineString[i].equals("*")) {
				int n = stack.pop()*stack.pop();
				stack.push(n);
			}
			else if(lineString[i].equals("+")) {
				int n = stack.pop()+stack.pop();
				stack.push(n);
			}
			else if(lineString[i].equals("-")) {
				int n1 = stack.pop();
				int n2 = stack.pop();
				int n = n2-n1;
				stack.push(n);
			}
			else {
			stack.push(Integer.parseInt(lineString[i]));	
			} 
			//System.out.println(stack.toString());
			
		}
		result = stack.pop();
		System.out.println(result);
		*/
	}

} Main
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
import java.util.Stack;

public class Main {

	public static void main(String[] args) {
		
		Scanner in = new Scanner(System.in);
		int timePassed= 0;
		int n = in.nextInt();
		int q = in.nextInt();
		Queue<Integer> process = new LinkedList<Integer>();
		Queue<String> name = new LinkedList<String>();
		ArrayList<String> nameRt = new ArrayList<String>();
		ArrayList<Integer> processRt = new ArrayList<Integer>();
		for(int i = 0;i<n;i++) {
			name.add(in.next());
			process.add(in.nextInt());
		}
		while(!process.isEmpty()) {
			int number = process.remove();
			String nme = name.remove();
			if(number-q<=0) {
				processRt.add(number+timePassed);
				nameRt.add(nme);
				timePassed+=number;
			}
			else {
				process.add(number-q);
				name.add(nme);
				timePassed+=q;
			}
			
		}
		for(int i =0; i<n;i++) {
			System.out.println(nameRt.get(i)+" "+processRt.get(i));
		}
		//System.out.println(process.toString());
		//System.out.println(name.toString());
		
		/**
		int result = 0;
		Stack<Integer> stack = new Stack<Integer>(); 
		Scanner in = new Scanner(System.in);
		String stringIn = in.nextLine();
		String[] lineString = stringIn.split(" ");
		for(int i = 0; i<lineString.length;i++) {
			if(lineString[i].equals("*")) {
				int n = stack.pop()*stack.pop();
				stack.push(n);
			}
			else if(lineString[i].equals("+")) {
				int n = stack.pop()+stack.pop();
				stack.push(n);
			}
			else if(lineString[i].equals("-")) {
				int n1 = stack.pop();
				int n2 = stack.pop();
				int n = n2-n1;
				stack.push(n);
			}
			else {
			stack.push(Integer.parseInt(lineString[i]));	
			} 
			//System.out.println(stack.toString());
			
		}
		result = stack.pop();
		System.out.println(result);
		*/
	}

}
