import java.util.*;
class Processe{
	String processesName;
	int Times;
	int endtime;
}
public class Main{
	public static void main(String[] args){
		Queue<Processe> queue = new  LinkedList<Processe>();
		Queue<Processe> queue2 = new  LinkedList<Processe>();
		int n;
		int q;
		int endtime = 0;
		Scanner scanner = new Scanner(System.in);
		String string;
		string = scanner.nextLine();
		
		String [] strings = string.split(" ");
		n = Integer.parseInt(strings[0]);
		q= Integer.parseInt(strings[1]);
		
		Processe[] processes = new Processe [n];
		
		Processe processe  = new Processe();
		
		for(int i=0; i<n; i++){
			string = scanner.nextLine();
			strings = string.split(" ");
			processes[i] = new Processe();
			processes[i].processesName = strings[0];
			processes[i].Times = Integer.parseInt(strings[1]);
			queue.add(processes[i]);
		}
		while(!queue.isEmpty()){
			processe = queue.poll();
			if(processe.Times <= q){
				endtime += processe.Times;
				processe.endtime = endtime;
				queue2.add(processe);
			}else{
				endtime  += q;
				processe.Times -= q;
				queue.add(processe);
			}
		}
		while(!queue2.isEmpty()){
			processe = queue2.poll();
			System.out.println(processe.processesName + " " + processe.endtime);
		}
	}
} import java.util.*; util.* java class Processe{
	String processesName;
	int Times;
	int endtime;
} Processe String processesName; processesName int Times; Times int endtime; endtime public class Main{
	public static void main(String[] args){
		Queue<Processe> queue = new  LinkedList<Processe>();
		Queue<Processe> queue2 = new  LinkedList<Processe>();
		int n;
		int q;
		int endtime = 0;
		Scanner scanner = new Scanner(System.in);
		String string;
		string = scanner.nextLine();
		
		String [] strings = string.split(" ");
		n = Integer.parseInt(strings[0]);
		q= Integer.parseInt(strings[1]);
		
		Processe[] processes = new Processe [n];
		
		Processe processe  = new Processe();
		
		for(int i=0; i<n; i++){
			string = scanner.nextLine();
			strings = string.split(" ");
			processes[i] = new Processe();
			processes[i].processesName = strings[0];
			processes[i].Times = Integer.parseInt(strings[1]);
			queue.add(processes[i]);
		}
		while(!queue.isEmpty()){
			processe = queue.poll();
			if(processe.Times <= q){
				endtime += processe.Times;
				processe.endtime = endtime;
				queue2.add(processe);
			}else{
				endtime  += q;
				processe.Times -= q;
				queue.add(processe);
			}
		}
		while(!queue2.isEmpty()){
			processe = queue2.poll();
			System.out.println(processe.processesName + " " + processe.endtime);
		}
	}
} Main public static void main(String[] args){
		Queue<Processe> queue = new  LinkedList<Processe>();
		Queue<Processe> queue2 = new  LinkedList<Processe>();
		int n;
		int q;
		int endtime = 0;
		Scanner scanner = new Scanner(System.in);
		String string;
		string = scanner.nextLine();
		
		String [] strings = string.split(" ");
		n = Integer.parseInt(strings[0]);
		q= Integer.parseInt(strings[1]);
		
		Processe[] processes = new Processe [n];
		
		Processe processe  = new Processe();
		
		for(int i=0; i<n; i++){
			string = scanner.nextLine();
			strings = string.split(" ");
			processes[i] = new Processe();
			processes[i].processesName = strings[0];
			processes[i].Times = Integer.parseInt(strings[1]);
			queue.add(processes[i]);
		}
		while(!queue.isEmpty()){
			processe = queue.poll();
			if(processe.Times <= q){
				endtime += processe.Times;
				processe.endtime = endtime;
				queue2.add(processe);
			}else{
				endtime  += q;
				processe.Times -= q;
				queue.add(processe);
			}
		}
		while(!queue2.isEmpty()){
			processe = queue2.poll();
			System.out.println(processe.processesName + " " + processe.endtime);
		}
	} main {
		Queue<Processe> queue = new  LinkedList<Processe>();
		Queue<Processe> queue2 = new  LinkedList<Processe>();
		int n;
		int q;
		int endtime = 0;
		Scanner scanner = new Scanner(System.in);
		String string;
		string = scanner.nextLine();
		
		String [] strings = string.split(" ");
		n = Integer.parseInt(strings[0]);
		q= Integer.parseInt(strings[1]);
		
		Processe[] processes = new Processe [n];
		
		Processe processe  = new Processe();
		
		for(int i=0; i<n; i++){
			string = scanner.nextLine();
			strings = string.split(" ");
			processes[i] = new Processe();
			processes[i].processesName = strings[0];
			processes[i].Times = Integer.parseInt(strings[1]);
			queue.add(processes[i]);
		}
		while(!queue.isEmpty()){
			processe = queue.poll();
			if(processe.Times <= q){
				endtime += processe.Times;
				processe.endtime = endtime;
				queue2.add(processe);
			}else{
				endtime  += q;
				processe.Times -= q;
				queue.add(processe);
			}
		}
		while(!queue2.isEmpty()){
			processe = queue2.poll();
			System.out.println(processe.processesName + " " + processe.endtime);
		}
	} Queue<Processe> queue = new  LinkedList<Processe>(); queue new  LinkedList<Processe>() Queue<Processe> queue2 = new  LinkedList<Processe>(); queue2 new  LinkedList<Processe>() int n; n int q; q int endtime = 0; endtime 0 Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) String string; string string = scanner.nextLine() string scanner.nextLine() scanner.nextLine scanner String [] strings = string.split(" "); strings string.split(" ") string.split string " " n = Integer.parseInt(strings[0]) n Integer.parseInt(strings[0]) Integer.parseInt Integer strings[0] strings 0 q= Integer.parseInt(strings[1]) q Integer.parseInt(strings[1]) Integer.parseInt Integer strings[1] strings 1 Processe[] processes = new Processe [n]; processes new Processe [n] n Processe processe  = new Processe(); processe new Processe() for(int i=0; i<n; i++){
			string = scanner.nextLine();
			strings = string.split(" ");
			processes[i] = new Processe();
			processes[i].processesName = strings[0];
			processes[i].Times = Integer.parseInt(strings[1]);
			queue.add(processes[i]);
		} int i=0; int i=0; i 0 i<n i n i++ i++ i {
			string = scanner.nextLine();
			strings = string.split(" ");
			processes[i] = new Processe();
			processes[i].processesName = strings[0];
			processes[i].Times = Integer.parseInt(strings[1]);
			queue.add(processes[i]);
		} {
			string = scanner.nextLine();
			strings = string.split(" ");
			processes[i] = new Processe();
			processes[i].processesName = strings[0];
			processes[i].Times = Integer.parseInt(strings[1]);
			queue.add(processes[i]);
		} string = scanner.nextLine() string scanner.nextLine() scanner.nextLine scanner strings = string.split(" ") strings string.split(" ") string.split string " " processes[i] = new Processe() processes[i] processes i new Processe() processes[i].processesName = strings[0] processes[i].processesName processes[i] processes i processes[i].processesName strings[0] strings 0 processes[i].Times = Integer.parseInt(strings[1]) processes[i].Times processes[i] processes i processes[i].Times Integer.parseInt(strings[1]) Integer.parseInt Integer strings[1] strings 1 queue.add(processes[i]) queue.add queue processes[i] processes i while(!queue.isEmpty()){
			processe = queue.poll();
			if(processe.Times <= q){
				endtime += processe.Times;
				processe.endtime = endtime;
				queue2.add(processe);
			}else{
				endtime  += q;
				processe.Times -= q;
				queue.add(processe);
			}
		} !queue.isEmpty() queue.isEmpty() queue.isEmpty queue {
			processe = queue.poll();
			if(processe.Times <= q){
				endtime += processe.Times;
				processe.endtime = endtime;
				queue2.add(processe);
			}else{
				endtime  += q;
				processe.Times -= q;
				queue.add(processe);
			}
		} processe = queue.poll() processe queue.poll() queue.poll queue if(processe.Times <= q){
				endtime += processe.Times;
				processe.endtime = endtime;
				queue2.add(processe);
			}else{
				endtime  += q;
				processe.Times -= q;
				queue.add(processe);
			} processe.Times <= q processe.Times processe processe.Times q {
				endtime += processe.Times;
				processe.endtime = endtime;
				queue2.add(processe);
			} endtime += processe.Times endtime processe.Times processe processe.Times processe.endtime = endtime processe.endtime processe processe.endtime endtime queue2.add(processe) queue2.add queue2 processe {
				endtime  += q;
				processe.Times -= q;
				queue.add(processe);
			} endtime  += q endtime q processe.Times -= q processe.Times processe processe.Times q queue.add(processe) queue.add queue processe while(!queue2.isEmpty()){
			processe = queue2.poll();
			System.out.println(processe.processesName + " " + processe.endtime);
		} !queue2.isEmpty() queue2.isEmpty() queue2.isEmpty queue2 {
			processe = queue2.poll();
			System.out.println(processe.processesName + " " + processe.endtime);
		} processe = queue2.poll() processe queue2.poll() queue2.poll queue2 System.out.println(processe.processesName + " " + processe.endtime) System.out.println System.out System System.out processe.processesName + " " + processe.endtime processe.processesName + " " + processe.endtime processe.processesName processe processe.processesName " " processe.endtime processe processe.endtime String[] args args public class Main{
	public static void main(String[] args){
		Queue<Processe> queue = new  LinkedList<Processe>();
		Queue<Processe> queue2 = new  LinkedList<Processe>();
		int n;
		int q;
		int endtime = 0;
		Scanner scanner = new Scanner(System.in);
		String string;
		string = scanner.nextLine();
		
		String [] strings = string.split(" ");
		n = Integer.parseInt(strings[0]);
		q= Integer.parseInt(strings[1]);
		
		Processe[] processes = new Processe [n];
		
		Processe processe  = new Processe();
		
		for(int i=0; i<n; i++){
			string = scanner.nextLine();
			strings = string.split(" ");
			processes[i] = new Processe();
			processes[i].processesName = strings[0];
			processes[i].Times = Integer.parseInt(strings[1]);
			queue.add(processes[i]);
		}
		while(!queue.isEmpty()){
			processe = queue.poll();
			if(processe.Times <= q){
				endtime += processe.Times;
				processe.endtime = endtime;
				queue2.add(processe);
			}else{
				endtime  += q;
				processe.Times -= q;
				queue.add(processe);
			}
		}
		while(!queue2.isEmpty()){
			processe = queue2.poll();
			System.out.println(processe.processesName + " " + processe.endtime);
		}
	}
} public class Main{
	public static void main(String[] args){
		Queue<Processe> queue = new  LinkedList<Processe>();
		Queue<Processe> queue2 = new  LinkedList<Processe>();
		int n;
		int q;
		int endtime = 0;
		Scanner scanner = new Scanner(System.in);
		String string;
		string = scanner.nextLine();
		
		String [] strings = string.split(" ");
		n = Integer.parseInt(strings[0]);
		q= Integer.parseInt(strings[1]);
		
		Processe[] processes = new Processe [n];
		
		Processe processe  = new Processe();
		
		for(int i=0; i<n; i++){
			string = scanner.nextLine();
			strings = string.split(" ");
			processes[i] = new Processe();
			processes[i].processesName = strings[0];
			processes[i].Times = Integer.parseInt(strings[1]);
			queue.add(processes[i]);
		}
		while(!queue.isEmpty()){
			processe = queue.poll();
			if(processe.Times <= q){
				endtime += processe.Times;
				processe.endtime = endtime;
				queue2.add(processe);
			}else{
				endtime  += q;
				processe.Times -= q;
				queue.add(processe);
			}
		}
		while(!queue2.isEmpty()){
			processe = queue2.poll();
			System.out.println(processe.processesName + " " + processe.endtime);
		}
	}
} Main
import java.util.*;
class Processe{
	String processesName;
	int Times;
	int endtime;
}
public class Main{
	public static void main(String[] args){
		Queue<Processe> queue = new  LinkedList<Processe>();
		Queue<Processe> queue2 = new  LinkedList<Processe>();
		int n;
		int q;
		int endtime = 0;
		Scanner scanner = new Scanner(System.in);
		String string;
		string = scanner.nextLine();
		
		String [] strings = string.split(" ");
		n = Integer.parseInt(strings[0]);
		q= Integer.parseInt(strings[1]);
		
		Processe[] processes = new Processe [n];
		
		Processe processe  = new Processe();
		
		for(int i=0; i<n; i++){
			string = scanner.nextLine();
			strings = string.split(" ");
			processes[i] = new Processe();
			processes[i].processesName = strings[0];
			processes[i].Times = Integer.parseInt(strings[1]);
			queue.add(processes[i]);
		}
		while(!queue.isEmpty()){
			processe = queue.poll();
			if(processe.Times <= q){
				endtime += processe.Times;
				processe.endtime = endtime;
				queue2.add(processe);
			}else{
				endtime  += q;
				processe.Times -= q;
				queue.add(processe);
			}
		}
		while(!queue2.isEmpty()){
			processe = queue2.poll();
			System.out.println(processe.processesName + " " + processe.endtime);
		}
	}
}