import java.util.Scanner;
import java.util.Queue;
import java.util.ArrayDeque;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String input = in.nextLine();
		Scanner setsinput = new Scanner(input);
		int n = setsinput.nextInt();
		int quantum_time = setsinput.nextInt();
		Queue<Process> q = new ArrayDeque<Process>();
		for(int i = 0; i < n; i++) {
			String setsStr = in.nextLine();
			//System.out.println(setsStr.charAt(0));
			Scanner setsLine = new Scanner(setsStr);
			q.add(new Process(setsLine.next(),setsLine.nextInt()));
		}
		
		Process tmp = new Process();
		StringBuilder ans = new StringBuilder();
		int total_time = 0;
		
		while (!q.isEmpty()) {
			tmp = q.peek();
			q.poll();
			if(tmp.get_time() <= quantum_time) {
				total_time += tmp.get_time();
				ans.append(tmp.get_Name()).append(" ").append(Integer.toString(total_time)).append("\n");
			}else {
				total_time += quantum_time;
				q.add(new Process(tmp.get_Name(), tmp.get_time() - quantum_time));
			}
		}
		System.out.print(ans.toString());
	}
}

class Process {
	String name;
	int time;
	
	Process(){
		
	}
	
	Process(String init_name, int init_time){
		name = init_name;
		time = init_time;
	}
	
	public String get_Name() {
		return name;
	}
	
	public int get_time() {
		return time;
	}
	
}

	
 import java.util.Scanner; Scanner java.util import java.util.Queue; Queue java.util import java.util.ArrayDeque; ArrayDeque java.util public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String input = in.nextLine();
		Scanner setsinput = new Scanner(input);
		int n = setsinput.nextInt();
		int quantum_time = setsinput.nextInt();
		Queue<Process> q = new ArrayDeque<Process>();
		for(int i = 0; i < n; i++) {
			String setsStr = in.nextLine();
			//System.out.println(setsStr.charAt(0));
			Scanner setsLine = new Scanner(setsStr);
			q.add(new Process(setsLine.next(),setsLine.nextInt()));
		}
		
		Process tmp = new Process();
		StringBuilder ans = new StringBuilder();
		int total_time = 0;
		
		while (!q.isEmpty()) {
			tmp = q.peek();
			q.poll();
			if(tmp.get_time() <= quantum_time) {
				total_time += tmp.get_time();
				ans.append(tmp.get_Name()).append(" ").append(Integer.toString(total_time)).append("\n");
			}else {
				total_time += quantum_time;
				q.add(new Process(tmp.get_Name(), tmp.get_time() - quantum_time));
			}
		}
		System.out.print(ans.toString());
	}
} Main public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String input = in.nextLine();
		Scanner setsinput = new Scanner(input);
		int n = setsinput.nextInt();
		int quantum_time = setsinput.nextInt();
		Queue<Process> q = new ArrayDeque<Process>();
		for(int i = 0; i < n; i++) {
			String setsStr = in.nextLine();
			//System.out.println(setsStr.charAt(0));
			Scanner setsLine = new Scanner(setsStr);
			q.add(new Process(setsLine.next(),setsLine.nextInt()));
		}
		
		Process tmp = new Process();
		StringBuilder ans = new StringBuilder();
		int total_time = 0;
		
		while (!q.isEmpty()) {
			tmp = q.peek();
			q.poll();
			if(tmp.get_time() <= quantum_time) {
				total_time += tmp.get_time();
				ans.append(tmp.get_Name()).append(" ").append(Integer.toString(total_time)).append("\n");
			}else {
				total_time += quantum_time;
				q.add(new Process(tmp.get_Name(), tmp.get_time() - quantum_time));
			}
		}
		System.out.print(ans.toString());
	} main {
		Scanner in = new Scanner(System.in);
		String input = in.nextLine();
		Scanner setsinput = new Scanner(input);
		int n = setsinput.nextInt();
		int quantum_time = setsinput.nextInt();
		Queue<Process> q = new ArrayDeque<Process>();
		for(int i = 0; i < n; i++) {
			String setsStr = in.nextLine();
			//System.out.println(setsStr.charAt(0));
			Scanner setsLine = new Scanner(setsStr);
			q.add(new Process(setsLine.next(),setsLine.nextInt()));
		}
		
		Process tmp = new Process();
		StringBuilder ans = new StringBuilder();
		int total_time = 0;
		
		while (!q.isEmpty()) {
			tmp = q.peek();
			q.poll();
			if(tmp.get_time() <= quantum_time) {
				total_time += tmp.get_time();
				ans.append(tmp.get_Name()).append(" ").append(Integer.toString(total_time)).append("\n");
			}else {
				total_time += quantum_time;
				q.add(new Process(tmp.get_Name(), tmp.get_time() - quantum_time));
			}
		}
		System.out.print(ans.toString());
	} Scanner in = new Scanner(System.in); in new Scanner(System.in) String input = in.nextLine(); input in.nextLine() in.nextLine in Scanner setsinput = new Scanner(input); setsinput new Scanner(input) int n = setsinput.nextInt(); n setsinput.nextInt() setsinput.nextInt setsinput int quantum_time = setsinput.nextInt(); quantum_time setsinput.nextInt() setsinput.nextInt setsinput Queue<Process> q = new ArrayDeque<Process>(); q new ArrayDeque<Process>() for(int i = 0; i < n; i++) {
			String setsStr = in.nextLine();
			//System.out.println(setsStr.charAt(0));
			Scanner setsLine = new Scanner(setsStr);
			q.add(new Process(setsLine.next(),setsLine.nextInt()));
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			String setsStr = in.nextLine();
			//System.out.println(setsStr.charAt(0));
			Scanner setsLine = new Scanner(setsStr);
			q.add(new Process(setsLine.next(),setsLine.nextInt()));
		} {
			String setsStr = in.nextLine();
			//System.out.println(setsStr.charAt(0));
			Scanner setsLine = new Scanner(setsStr);
			q.add(new Process(setsLine.next(),setsLine.nextInt()));
		} String setsStr = in.nextLine(); setsStr in.nextLine() in.nextLine in Scanner setsLine = new Scanner(setsStr); setsLine new Scanner(setsStr) q.add(new Process(setsLine.next(),setsLine.nextInt())) q.add q new Process(setsLine.next(),setsLine.nextInt()) Process tmp = new Process(); tmp new Process() StringBuilder ans = new StringBuilder(); ans new StringBuilder() int total_time = 0; total_time 0 while (!q.isEmpty()) {
			tmp = q.peek();
			q.poll();
			if(tmp.get_time() <= quantum_time) {
				total_time += tmp.get_time();
				ans.append(tmp.get_Name()).append(" ").append(Integer.toString(total_time)).append("\n");
			}else {
				total_time += quantum_time;
				q.add(new Process(tmp.get_Name(), tmp.get_time() - quantum_time));
			}
		} !q.isEmpty() q.isEmpty() q.isEmpty q {
			tmp = q.peek();
			q.poll();
			if(tmp.get_time() <= quantum_time) {
				total_time += tmp.get_time();
				ans.append(tmp.get_Name()).append(" ").append(Integer.toString(total_time)).append("\n");
			}else {
				total_time += quantum_time;
				q.add(new Process(tmp.get_Name(), tmp.get_time() - quantum_time));
			}
		} tmp = q.peek() tmp q.peek() q.peek q q.poll() q.poll q if(tmp.get_time() <= quantum_time) {
				total_time += tmp.get_time();
				ans.append(tmp.get_Name()).append(" ").append(Integer.toString(total_time)).append("\n");
			}else {
				total_time += quantum_time;
				q.add(new Process(tmp.get_Name(), tmp.get_time() - quantum_time));
			} tmp.get_time() <= quantum_time tmp.get_time() tmp.get_time tmp quantum_time {
				total_time += tmp.get_time();
				ans.append(tmp.get_Name()).append(" ").append(Integer.toString(total_time)).append("\n");
			} total_time += tmp.get_time() total_time tmp.get_time() tmp.get_time tmp ans.append(tmp.get_Name()).append(" ").append(Integer.toString(total_time)).append("\n") ans.append(tmp.get_Name()).append(" ").append(Integer.toString(total_time)).append ans.append(tmp.get_Name()).append(" ").append(Integer.toString(total_time)) ans.append(tmp.get_Name()).append(" ").append ans.append(tmp.get_Name()).append(" ") ans.append(tmp.get_Name()).append ans.append(tmp.get_Name()) ans.append ans tmp.get_Name() tmp.get_Name tmp " " Integer.toString(total_time) Integer.toString Integer total_time "\n" {
				total_time += quantum_time;
				q.add(new Process(tmp.get_Name(), tmp.get_time() - quantum_time));
			} total_time += quantum_time total_time quantum_time q.add(new Process(tmp.get_Name(), tmp.get_time() - quantum_time)) q.add q new Process(tmp.get_Name(), tmp.get_time() - quantum_time) System.out.print(ans.toString()) System.out.print System.out System System.out ans.toString() ans.toString ans String[] args args class Process {
	String name;
	int time;
	
	Process(){
		
	}
	
	Process(String init_name, int init_time){
		name = init_name;
		time = init_time;
	}
	
	public String get_Name() {
		return name;
	}
	
	public int get_time() {
		return time;
	}
	
} Process String name; name int time; time Process(){
		
	} Process {
		
	} Process(String init_name, int init_time){
		name = init_name;
		time = init_time;
	} Process {
		name = init_name;
		time = init_time;
	} name = init_name name init_name time = init_time time init_time String init_name init_name int init_time init_time public String get_Name() {
		return name;
	} get_Name {
		return name;
	} return name; name public int get_time() {
		return time;
	} get_time {
		return time;
	} return time; time public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String input = in.nextLine();
		Scanner setsinput = new Scanner(input);
		int n = setsinput.nextInt();
		int quantum_time = setsinput.nextInt();
		Queue<Process> q = new ArrayDeque<Process>();
		for(int i = 0; i < n; i++) {
			String setsStr = in.nextLine();
			//System.out.println(setsStr.charAt(0));
			Scanner setsLine = new Scanner(setsStr);
			q.add(new Process(setsLine.next(),setsLine.nextInt()));
		}
		
		Process tmp = new Process();
		StringBuilder ans = new StringBuilder();
		int total_time = 0;
		
		while (!q.isEmpty()) {
			tmp = q.peek();
			q.poll();
			if(tmp.get_time() <= quantum_time) {
				total_time += tmp.get_time();
				ans.append(tmp.get_Name()).append(" ").append(Integer.toString(total_time)).append("\n");
			}else {
				total_time += quantum_time;
				q.add(new Process(tmp.get_Name(), tmp.get_time() - quantum_time));
			}
		}
		System.out.print(ans.toString());
	}
} public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String input = in.nextLine();
		Scanner setsinput = new Scanner(input);
		int n = setsinput.nextInt();
		int quantum_time = setsinput.nextInt();
		Queue<Process> q = new ArrayDeque<Process>();
		for(int i = 0; i < n; i++) {
			String setsStr = in.nextLine();
			//System.out.println(setsStr.charAt(0));
			Scanner setsLine = new Scanner(setsStr);
			q.add(new Process(setsLine.next(),setsLine.nextInt()));
		}
		
		Process tmp = new Process();
		StringBuilder ans = new StringBuilder();
		int total_time = 0;
		
		while (!q.isEmpty()) {
			tmp = q.peek();
			q.poll();
			if(tmp.get_time() <= quantum_time) {
				total_time += tmp.get_time();
				ans.append(tmp.get_Name()).append(" ").append(Integer.toString(total_time)).append("\n");
			}else {
				total_time += quantum_time;
				q.add(new Process(tmp.get_Name(), tmp.get_time() - quantum_time));
			}
		}
		System.out.print(ans.toString());
	}
} Main
import java.util.Scanner;
import java.util.Queue;
import java.util.ArrayDeque;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String input = in.nextLine();
		Scanner setsinput = new Scanner(input);
		int n = setsinput.nextInt();
		int quantum_time = setsinput.nextInt();
		Queue<Process> q = new ArrayDeque<Process>();
		for(int i = 0; i < n; i++) {
			String setsStr = in.nextLine();
			//System.out.println(setsStr.charAt(0));
			Scanner setsLine = new Scanner(setsStr);
			q.add(new Process(setsLine.next(),setsLine.nextInt()));
		}
		
		Process tmp = new Process();
		StringBuilder ans = new StringBuilder();
		int total_time = 0;
		
		while (!q.isEmpty()) {
			tmp = q.peek();
			q.poll();
			if(tmp.get_time() <= quantum_time) {
				total_time += tmp.get_time();
				ans.append(tmp.get_Name()).append(" ").append(Integer.toString(total_time)).append("\n");
			}else {
				total_time += quantum_time;
				q.add(new Process(tmp.get_Name(), tmp.get_time() - quantum_time));
			}
		}
		System.out.print(ans.toString());
	}
}

class Process {
	String name;
	int time;
	
	Process(){
		
	}
	
	Process(String init_name, int init_time){
		name = init_name;
		time = init_time;
	}
	
	public String get_Name() {
		return name;
	}
	
	public int get_time() {
		return time;
	}
	
}

	

