import java.util.ArrayList;
import java.util.Scanner;


class Process{
	
	private String name;
	private int time;
	public Process(String name,int time){
		this.name = name;
		this.time = time;
	}
	
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public int getTime() {
		return time;
	}
	public void setTime(int time) {
		this.time = time;
	}
	
	
}

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int p = sc.nextInt();
		
		ArrayList<Process> ar = new ArrayList<Process>();
		ArrayList<Process> result = new ArrayList<Process>();
		
		for (int i = 0; i < n; i++) {
			ar.add(new Process(sc.next(),sc.nextInt()));
		}
		
		int totalTime=0,i=0;
		Process process;
		while(true){
			if(i<n){
				if((process=ar.get(i)).getTime()<=p){
					totalTime += process.getTime();
					result.add(new Process(process.getName(), totalTime));
					ar.remove(i);
					n--;
				}
				else{
					totalTime += p;
					int temp =ar.get(i).getTime()-p;
					ar.get(i).setTime(temp);
					i++;
				}
			}
			else{
				i=0;
			}
			if(ar.size()==0){
				break;
			}
		}
		
		for(Process rProcess:result){
			System.out.println(rProcess.getName()+ " "+rProcess.getTime());
		}
		
	}
	
} import java.util.ArrayList; ArrayList java.util import java.util.Scanner; Scanner java.util class Process{
	
	private String name;
	private int time;
	public Process(String name,int time){
		this.name = name;
		this.time = time;
	}
	
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public int getTime() {
		return time;
	}
	public void setTime(int time) {
		this.time = time;
	}
	
	
} Process private String name; name private int time; time public Process(String name,int time){
		this.name = name;
		this.time = time;
	} Process {
		this.name = name;
		this.time = time;
	} this.name = name this.name this this.name name this.time = time this.time this this.time time String name name int time time public String getName() {
		return name;
	} getName {
		return name;
	} return name; name public void setName(String name) {
		this.name = name;
	} setName {
		this.name = name;
	} this.name = name this.name this this.name name String name name public int getTime() {
		return time;
	} getTime {
		return time;
	} return time; time public void setTime(int time) {
		this.time = time;
	} setTime {
		this.time = time;
	} this.time = time this.time this this.time time int time time public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int p = sc.nextInt();
		
		ArrayList<Process> ar = new ArrayList<Process>();
		ArrayList<Process> result = new ArrayList<Process>();
		
		for (int i = 0; i < n; i++) {
			ar.add(new Process(sc.next(),sc.nextInt()));
		}
		
		int totalTime=0,i=0;
		Process process;
		while(true){
			if(i<n){
				if((process=ar.get(i)).getTime()<=p){
					totalTime += process.getTime();
					result.add(new Process(process.getName(), totalTime));
					ar.remove(i);
					n--;
				}
				else{
					totalTime += p;
					int temp =ar.get(i).getTime()-p;
					ar.get(i).setTime(temp);
					i++;
				}
			}
			else{
				i=0;
			}
			if(ar.size()==0){
				break;
			}
		}
		
		for(Process rProcess:result){
			System.out.println(rProcess.getName()+ " "+rProcess.getTime());
		}
		
	}
	
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int p = sc.nextInt();
		
		ArrayList<Process> ar = new ArrayList<Process>();
		ArrayList<Process> result = new ArrayList<Process>();
		
		for (int i = 0; i < n; i++) {
			ar.add(new Process(sc.next(),sc.nextInt()));
		}
		
		int totalTime=0,i=0;
		Process process;
		while(true){
			if(i<n){
				if((process=ar.get(i)).getTime()<=p){
					totalTime += process.getTime();
					result.add(new Process(process.getName(), totalTime));
					ar.remove(i);
					n--;
				}
				else{
					totalTime += p;
					int temp =ar.get(i).getTime()-p;
					ar.get(i).setTime(temp);
					i++;
				}
			}
			else{
				i=0;
			}
			if(ar.size()==0){
				break;
			}
		}
		
		for(Process rProcess:result){
			System.out.println(rProcess.getName()+ " "+rProcess.getTime());
		}
		
	} main {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int p = sc.nextInt();
		
		ArrayList<Process> ar = new ArrayList<Process>();
		ArrayList<Process> result = new ArrayList<Process>();
		
		for (int i = 0; i < n; i++) {
			ar.add(new Process(sc.next(),sc.nextInt()));
		}
		
		int totalTime=0,i=0;
		Process process;
		while(true){
			if(i<n){
				if((process=ar.get(i)).getTime()<=p){
					totalTime += process.getTime();
					result.add(new Process(process.getName(), totalTime));
					ar.remove(i);
					n--;
				}
				else{
					totalTime += p;
					int temp =ar.get(i).getTime()-p;
					ar.get(i).setTime(temp);
					i++;
				}
			}
			else{
				i=0;
			}
			if(ar.size()==0){
				break;
			}
		}
		
		for(Process rProcess:result){
			System.out.println(rProcess.getName()+ " "+rProcess.getTime());
		}
		
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int p = sc.nextInt(); p sc.nextInt() sc.nextInt sc ArrayList<Process> ar = new ArrayList<Process>(); ar new ArrayList<Process>() ArrayList<Process> result = new ArrayList<Process>(); result new ArrayList<Process>() for (int i = 0; i < n; i++) {
			ar.add(new Process(sc.next(),sc.nextInt()));
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			ar.add(new Process(sc.next(),sc.nextInt()));
		} {
			ar.add(new Process(sc.next(),sc.nextInt()));
		} ar.add(new Process(sc.next(),sc.nextInt())) ar.add ar new Process(sc.next(),sc.nextInt()) int totalTime=0 totalTime 0 i=0; i 0 Process process; process while(true){
			if(i<n){
				if((process=ar.get(i)).getTime()<=p){
					totalTime += process.getTime();
					result.add(new Process(process.getName(), totalTime));
					ar.remove(i);
					n--;
				}
				else{
					totalTime += p;
					int temp =ar.get(i).getTime()-p;
					ar.get(i).setTime(temp);
					i++;
				}
			}
			else{
				i=0;
			}
			if(ar.size()==0){
				break;
			}
		} true {
			if(i<n){
				if((process=ar.get(i)).getTime()<=p){
					totalTime += process.getTime();
					result.add(new Process(process.getName(), totalTime));
					ar.remove(i);
					n--;
				}
				else{
					totalTime += p;
					int temp =ar.get(i).getTime()-p;
					ar.get(i).setTime(temp);
					i++;
				}
			}
			else{
				i=0;
			}
			if(ar.size()==0){
				break;
			}
		} if(i<n){
				if((process=ar.get(i)).getTime()<=p){
					totalTime += process.getTime();
					result.add(new Process(process.getName(), totalTime));
					ar.remove(i);
					n--;
				}
				else{
					totalTime += p;
					int temp =ar.get(i).getTime()-p;
					ar.get(i).setTime(temp);
					i++;
				}
			}
			else{
				i=0;
			} i<n i n {
				if((process=ar.get(i)).getTime()<=p){
					totalTime += process.getTime();
					result.add(new Process(process.getName(), totalTime));
					ar.remove(i);
					n--;
				}
				else{
					totalTime += p;
					int temp =ar.get(i).getTime()-p;
					ar.get(i).setTime(temp);
					i++;
				}
			} if((process=ar.get(i)).getTime()<=p){
					totalTime += process.getTime();
					result.add(new Process(process.getName(), totalTime));
					ar.remove(i);
					n--;
				}
				else{
					totalTime += p;
					int temp =ar.get(i).getTime()-p;
					ar.get(i).setTime(temp);
					i++;
				} (process=ar.get(i)).getTime()<=p (process=ar.get(i)).getTime() (process=ar.get(i)).getTime (process=ar.get(i)) process ar.get(i) ar.get ar i p {
					totalTime += process.getTime();
					result.add(new Process(process.getName(), totalTime));
					ar.remove(i);
					n--;
				} totalTime += process.getTime() totalTime process.getTime() process.getTime process result.add(new Process(process.getName(), totalTime)) result.add result new Process(process.getName(), totalTime) ar.remove(i) ar.remove ar i n-- n {
					totalTime += p;
					int temp =ar.get(i).getTime()-p;
					ar.get(i).setTime(temp);
					i++;
				} totalTime += p totalTime p int temp =ar.get(i).getTime()-p; temp ar.get(i).getTime()-p ar.get(i).getTime() ar.get(i).getTime ar.get(i) ar.get ar i p ar.get(i).setTime(temp) ar.get(i).setTime ar.get(i) ar.get ar i temp i++ i {
				i=0;
			} i=0 i 0 if(ar.size()==0){
				break;
			} ar.size()==0 ar.size() ar.size ar 0 {
				break;
			} break; for(Process rProcess:result){
			System.out.println(rProcess.getName()+ " "+rProcess.getTime());
		} Process rProcess result {
			System.out.println(rProcess.getName()+ " "+rProcess.getTime());
		} {
			System.out.println(rProcess.getName()+ " "+rProcess.getTime());
		} System.out.println(rProcess.getName()+ " "+rProcess.getTime()) System.out.println System.out System System.out rProcess.getName()+ " "+rProcess.getTime() rProcess.getName()+ " "+rProcess.getTime() rProcess.getName() rProcess.getName rProcess " " rProcess.getTime() rProcess.getTime rProcess String[] args args public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int p = sc.nextInt();
		
		ArrayList<Process> ar = new ArrayList<Process>();
		ArrayList<Process> result = new ArrayList<Process>();
		
		for (int i = 0; i < n; i++) {
			ar.add(new Process(sc.next(),sc.nextInt()));
		}
		
		int totalTime=0,i=0;
		Process process;
		while(true){
			if(i<n){
				if((process=ar.get(i)).getTime()<=p){
					totalTime += process.getTime();
					result.add(new Process(process.getName(), totalTime));
					ar.remove(i);
					n--;
				}
				else{
					totalTime += p;
					int temp =ar.get(i).getTime()-p;
					ar.get(i).setTime(temp);
					i++;
				}
			}
			else{
				i=0;
			}
			if(ar.size()==0){
				break;
			}
		}
		
		for(Process rProcess:result){
			System.out.println(rProcess.getName()+ " "+rProcess.getTime());
		}
		
	}
	
} public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int p = sc.nextInt();
		
		ArrayList<Process> ar = new ArrayList<Process>();
		ArrayList<Process> result = new ArrayList<Process>();
		
		for (int i = 0; i < n; i++) {
			ar.add(new Process(sc.next(),sc.nextInt()));
		}
		
		int totalTime=0,i=0;
		Process process;
		while(true){
			if(i<n){
				if((process=ar.get(i)).getTime()<=p){
					totalTime += process.getTime();
					result.add(new Process(process.getName(), totalTime));
					ar.remove(i);
					n--;
				}
				else{
					totalTime += p;
					int temp =ar.get(i).getTime()-p;
					ar.get(i).setTime(temp);
					i++;
				}
			}
			else{
				i=0;
			}
			if(ar.size()==0){
				break;
			}
		}
		
		for(Process rProcess:result){
			System.out.println(rProcess.getName()+ " "+rProcess.getTime());
		}
		
	}
	
} Main
import java.util.ArrayList;
import java.util.Scanner;


class Process{
	
	private String name;
	private int time;
	public Process(String name,int time){
		this.name = name;
		this.time = time;
	}
	
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public int getTime() {
		return time;
	}
	public void setTime(int time) {
		this.time = time;
	}
	
	
}

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int p = sc.nextInt();
		
		ArrayList<Process> ar = new ArrayList<Process>();
		ArrayList<Process> result = new ArrayList<Process>();
		
		for (int i = 0; i < n; i++) {
			ar.add(new Process(sc.next(),sc.nextInt()));
		}
		
		int totalTime=0,i=0;
		Process process;
		while(true){
			if(i<n){
				if((process=ar.get(i)).getTime()<=p){
					totalTime += process.getTime();
					result.add(new Process(process.getName(), totalTime));
					ar.remove(i);
					n--;
				}
				else{
					totalTime += p;
					int temp =ar.get(i).getTime()-p;
					ar.get(i).setTime(temp);
					i++;
				}
			}
			else{
				i=0;
			}
			if(ar.size()==0){
				break;
			}
		}
		
		for(Process rProcess:result){
			System.out.println(rProcess.getName()+ " "+rProcess.getTime());
		}
		
	}
	
}