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

public class Main{
	private static int timer = 0;

	public static void processor(Queue<Process> p, int q){
		Process x;
		timer = 0;
		while(!p.isEmpty()){
			x = p.remove();
			if(!x.handle(q)) p.add(x);
		}
	}	

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int quantum = sc.nextInt();

		Queue<Process> p = new LinkedList<Process>();
		String name;
		int time;
		for(int i=0; i<n; i++){
			name = sc.next();
			time = sc.nextInt();
			Process x = new Process(name, time);
			p.add(x);
		}

		sc.close();

		processor(p,quantum);
	}

	private static class Process{
		String name;
		int time; //remaining time

		public Process(String n, int t){
			name = n;
			time = t;
		}

		//return if it ends
		public boolean handle(int q){
			if(q<time){
				time -= q;
				timer +=q;
				return false;
			} 
			else{
				timer += time;
				System.out.println(name+" "+timer);
				return true;
			}
		}
	}
} import java.util.Scanner; Scanner java.util import java.util.Queue; Queue java.util import java.util.LinkedList; LinkedList java.util public class Main{
	private static int timer = 0;

	public static void processor(Queue<Process> p, int q){
		Process x;
		timer = 0;
		while(!p.isEmpty()){
			x = p.remove();
			if(!x.handle(q)) p.add(x);
		}
	}	

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int quantum = sc.nextInt();

		Queue<Process> p = new LinkedList<Process>();
		String name;
		int time;
		for(int i=0; i<n; i++){
			name = sc.next();
			time = sc.nextInt();
			Process x = new Process(name, time);
			p.add(x);
		}

		sc.close();

		processor(p,quantum);
	}

	private static class Process{
		String name;
		int time; //remaining time

		public Process(String n, int t){
			name = n;
			time = t;
		}

		//return if it ends
		public boolean handle(int q){
			if(q<time){
				time -= q;
				timer +=q;
				return false;
			} 
			else{
				timer += time;
				System.out.println(name+" "+timer);
				return true;
			}
		}
	}
} Main private static int timer = 0; timer 0 public static void processor(Queue<Process> p, int q){
		Process x;
		timer = 0;
		while(!p.isEmpty()){
			x = p.remove();
			if(!x.handle(q)) p.add(x);
		}
	} processor {
		Process x;
		timer = 0;
		while(!p.isEmpty()){
			x = p.remove();
			if(!x.handle(q)) p.add(x);
		}
	} Process x; x timer = 0 timer 0 while(!p.isEmpty()){
			x = p.remove();
			if(!x.handle(q)) p.add(x);
		} !p.isEmpty() p.isEmpty() p.isEmpty p {
			x = p.remove();
			if(!x.handle(q)) p.add(x);
		} x = p.remove() x p.remove() p.remove p if(!x.handle(q)) p.add(x); !x.handle(q) x.handle(q) x.handle x q p.add(x) p.add p x Queue<Process> p p int q q public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int quantum = sc.nextInt();

		Queue<Process> p = new LinkedList<Process>();
		String name;
		int time;
		for(int i=0; i<n; i++){
			name = sc.next();
			time = sc.nextInt();
			Process x = new Process(name, time);
			p.add(x);
		}

		sc.close();

		processor(p,quantum);
	} main {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int quantum = sc.nextInt();

		Queue<Process> p = new LinkedList<Process>();
		String name;
		int time;
		for(int i=0; i<n; i++){
			name = sc.next();
			time = sc.nextInt();
			Process x = new Process(name, time);
			p.add(x);
		}

		sc.close();

		processor(p,quantum);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int quantum = sc.nextInt(); quantum sc.nextInt() sc.nextInt sc Queue<Process> p = new LinkedList<Process>(); p new LinkedList<Process>() String name; name int time; time for(int i=0; i<n; i++){
			name = sc.next();
			time = sc.nextInt();
			Process x = new Process(name, time);
			p.add(x);
		} int i=0; int i=0; i 0 i<n i n i++ i++ i {
			name = sc.next();
			time = sc.nextInt();
			Process x = new Process(name, time);
			p.add(x);
		} {
			name = sc.next();
			time = sc.nextInt();
			Process x = new Process(name, time);
			p.add(x);
		} name = sc.next() name sc.next() sc.next sc time = sc.nextInt() time sc.nextInt() sc.nextInt sc Process x = new Process(name, time); x new Process(name, time) p.add(x) p.add p x sc.close() sc.close sc processor(p,quantum) processor p quantum String[] args args private static class Process{
		String name;
		int time; //remaining time

		public Process(String n, int t){
			name = n;
			time = t;
		}

		//return if it ends
		public boolean handle(int q){
			if(q<time){
				time -= q;
				timer +=q;
				return false;
			} 
			else{
				timer += time;
				System.out.println(name+" "+timer);
				return true;
			}
		}
	} Process String name; name int time; //remaining time time public Process(String n, int t){
			name = n;
			time = t;
		} Process {
			name = n;
			time = t;
		} name = n name n time = t time t String n n int t t //return if it ends
		public boolean handle(int q){
			if(q<time){
				time -= q;
				timer +=q;
				return false;
			} 
			else{
				timer += time;
				System.out.println(name+" "+timer);
				return true;
			}
		} handle {
			if(q<time){
				time -= q;
				timer +=q;
				return false;
			} 
			else{
				timer += time;
				System.out.println(name+" "+timer);
				return true;
			}
		} if(q<time){
				time -= q;
				timer +=q;
				return false;
			} 
			else{
				timer += time;
				System.out.println(name+" "+timer);
				return true;
			} q<time q time {
				time -= q;
				timer +=q;
				return false;
			} time -= q time q timer +=q timer q return false; false {
				timer += time;
				System.out.println(name+" "+timer);
				return true;
			} timer += time timer time System.out.println(name+" "+timer) System.out.println System.out System System.out name+" "+timer name+" "+timer name " " timer return true; true int q q public class Main{
	private static int timer = 0;

	public static void processor(Queue<Process> p, int q){
		Process x;
		timer = 0;
		while(!p.isEmpty()){
			x = p.remove();
			if(!x.handle(q)) p.add(x);
		}
	}	

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int quantum = sc.nextInt();

		Queue<Process> p = new LinkedList<Process>();
		String name;
		int time;
		for(int i=0; i<n; i++){
			name = sc.next();
			time = sc.nextInt();
			Process x = new Process(name, time);
			p.add(x);
		}

		sc.close();

		processor(p,quantum);
	}

	private static class Process{
		String name;
		int time; //remaining time

		public Process(String n, int t){
			name = n;
			time = t;
		}

		//return if it ends
		public boolean handle(int q){
			if(q<time){
				time -= q;
				timer +=q;
				return false;
			} 
			else{
				timer += time;
				System.out.println(name+" "+timer);
				return true;
			}
		}
	}
} public class Main{
	private static int timer = 0;

	public static void processor(Queue<Process> p, int q){
		Process x;
		timer = 0;
		while(!p.isEmpty()){
			x = p.remove();
			if(!x.handle(q)) p.add(x);
		}
	}	

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int quantum = sc.nextInt();

		Queue<Process> p = new LinkedList<Process>();
		String name;
		int time;
		for(int i=0; i<n; i++){
			name = sc.next();
			time = sc.nextInt();
			Process x = new Process(name, time);
			p.add(x);
		}

		sc.close();

		processor(p,quantum);
	}

	private static class Process{
		String name;
		int time; //remaining time

		public Process(String n, int t){
			name = n;
			time = t;
		}

		//return if it ends
		public boolean handle(int q){
			if(q<time){
				time -= q;
				timer +=q;
				return false;
			} 
			else{
				timer += time;
				System.out.println(name+" "+timer);
				return true;
			}
		}
	}
} Main
import java.util.Scanner;
import java.util.Queue;
import java.util.LinkedList;

public class Main{
	private static int timer = 0;

	public static void processor(Queue<Process> p, int q){
		Process x;
		timer = 0;
		while(!p.isEmpty()){
			x = p.remove();
			if(!x.handle(q)) p.add(x);
		}
	}	

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int quantum = sc.nextInt();

		Queue<Process> p = new LinkedList<Process>();
		String name;
		int time;
		for(int i=0; i<n; i++){
			name = sc.next();
			time = sc.nextInt();
			Process x = new Process(name, time);
			p.add(x);
		}

		sc.close();

		processor(p,quantum);
	}

	private static class Process{
		String name;
		int time; //remaining time

		public Process(String n, int t){
			name = n;
			time = t;
		}

		//return if it ends
		public boolean handle(int q){
			if(q<time){
				time -= q;
				timer +=q;
				return false;
			} 
			else{
				timer += time;
				System.out.println(name+" "+timer);
				return true;
			}
		}
	}
}
