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

public class Main{	

public static void main(String[] args) {
		Queue<Integer> time = new LinkedList<Integer>();
		Queue<String> name = new LinkedList<String>();
		
		Scanner sc = new Scanner(System.in);
		int input = sc.nextInt();
		int quantum = sc.nextInt();
		int timestamp = 0;
		sc.nextLine();
		String p = "";
		int t = 0;
		for (int i =0; i< input; i++) { //////  p1 = p,    500 = t
		  p = sc.next();
		  name.add(p);
		  t = sc.nextInt();
		  time.add(t);

		}
		
		while(!name.isEmpty()) {
			String a = name.poll();
			int ti = time.poll();
			if( ti <= quantum) {
				timestamp += ti;
				System.out.println(a + " " + timestamp);
			
				
			}
			else {
				ti = ti - quantum;
				name.add(a);
				time.add(ti);
				timestamp += quantum;
			}
			
		}
	}
} import java.util.LinkedList; LinkedList java.util import java.util.Queue; Queue java.util import java.util.Scanner; Scanner java.util public class Main{	

public static void main(String[] args) {
		Queue<Integer> time = new LinkedList<Integer>();
		Queue<String> name = new LinkedList<String>();
		
		Scanner sc = new Scanner(System.in);
		int input = sc.nextInt();
		int quantum = sc.nextInt();
		int timestamp = 0;
		sc.nextLine();
		String p = "";
		int t = 0;
		for (int i =0; i< input; i++) { //////  p1 = p,    500 = t
		  p = sc.next();
		  name.add(p);
		  t = sc.nextInt();
		  time.add(t);

		}
		
		while(!name.isEmpty()) {
			String a = name.poll();
			int ti = time.poll();
			if( ti <= quantum) {
				timestamp += ti;
				System.out.println(a + " " + timestamp);
			
				
			}
			else {
				ti = ti - quantum;
				name.add(a);
				time.add(ti);
				timestamp += quantum;
			}
			
		}
	}
} Main public static void main(String[] args) {
		Queue<Integer> time = new LinkedList<Integer>();
		Queue<String> name = new LinkedList<String>();
		
		Scanner sc = new Scanner(System.in);
		int input = sc.nextInt();
		int quantum = sc.nextInt();
		int timestamp = 0;
		sc.nextLine();
		String p = "";
		int t = 0;
		for (int i =0; i< input; i++) { //////  p1 = p,    500 = t
		  p = sc.next();
		  name.add(p);
		  t = sc.nextInt();
		  time.add(t);

		}
		
		while(!name.isEmpty()) {
			String a = name.poll();
			int ti = time.poll();
			if( ti <= quantum) {
				timestamp += ti;
				System.out.println(a + " " + timestamp);
			
				
			}
			else {
				ti = ti - quantum;
				name.add(a);
				time.add(ti);
				timestamp += quantum;
			}
			
		}
	} main {
		Queue<Integer> time = new LinkedList<Integer>();
		Queue<String> name = new LinkedList<String>();
		
		Scanner sc = new Scanner(System.in);
		int input = sc.nextInt();
		int quantum = sc.nextInt();
		int timestamp = 0;
		sc.nextLine();
		String p = "";
		int t = 0;
		for (int i =0; i< input; i++) { //////  p1 = p,    500 = t
		  p = sc.next();
		  name.add(p);
		  t = sc.nextInt();
		  time.add(t);

		}
		
		while(!name.isEmpty()) {
			String a = name.poll();
			int ti = time.poll();
			if( ti <= quantum) {
				timestamp += ti;
				System.out.println(a + " " + timestamp);
			
				
			}
			else {
				ti = ti - quantum;
				name.add(a);
				time.add(ti);
				timestamp += quantum;
			}
			
		}
	} Queue<Integer> time = new LinkedList<Integer>(); time new LinkedList<Integer>() Queue<String> name = new LinkedList<String>(); name new LinkedList<String>() Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int input = sc.nextInt(); input sc.nextInt() sc.nextInt sc int quantum = sc.nextInt(); quantum sc.nextInt() sc.nextInt sc int timestamp = 0; timestamp 0 sc.nextLine() sc.nextLine sc String p = ""; p "" int t = 0; t 0 for (int i =0; i< input; i++) { //////  p1 = p,    500 = t
		  p = sc.next();
		  name.add(p);
		  t = sc.nextInt();
		  time.add(t);

		} int i =0; int i =0; i 0 i< input i input i++ i++ i { //////  p1 = p,    500 = t
		  p = sc.next();
		  name.add(p);
		  t = sc.nextInt();
		  time.add(t);

		} { //////  p1 = p,    500 = t
		  p = sc.next();
		  name.add(p);
		  t = sc.nextInt();
		  time.add(t);

		} p = sc.next() p sc.next() sc.next sc name.add(p) name.add name p t = sc.nextInt() t sc.nextInt() sc.nextInt sc time.add(t) time.add time t while(!name.isEmpty()) {
			String a = name.poll();
			int ti = time.poll();
			if( ti <= quantum) {
				timestamp += ti;
				System.out.println(a + " " + timestamp);
			
				
			}
			else {
				ti = ti - quantum;
				name.add(a);
				time.add(ti);
				timestamp += quantum;
			}
			
		} !name.isEmpty() name.isEmpty() name.isEmpty name {
			String a = name.poll();
			int ti = time.poll();
			if( ti <= quantum) {
				timestamp += ti;
				System.out.println(a + " " + timestamp);
			
				
			}
			else {
				ti = ti - quantum;
				name.add(a);
				time.add(ti);
				timestamp += quantum;
			}
			
		} String a = name.poll(); a name.poll() name.poll name int ti = time.poll(); ti time.poll() time.poll time if( ti <= quantum) {
				timestamp += ti;
				System.out.println(a + " " + timestamp);
			
				
			}
			else {
				ti = ti - quantum;
				name.add(a);
				time.add(ti);
				timestamp += quantum;
			} ti <= quantum ti quantum {
				timestamp += ti;
				System.out.println(a + " " + timestamp);
			
				
			} timestamp += ti timestamp ti System.out.println(a + " " + timestamp) System.out.println System.out System System.out a + " " + timestamp a + " " + timestamp a " " timestamp {
				ti = ti - quantum;
				name.add(a);
				time.add(ti);
				timestamp += quantum;
			} ti = ti - quantum ti ti - quantum ti quantum name.add(a) name.add name a time.add(ti) time.add time ti timestamp += quantum timestamp quantum String[] args args public class Main{	

public static void main(String[] args) {
		Queue<Integer> time = new LinkedList<Integer>();
		Queue<String> name = new LinkedList<String>();
		
		Scanner sc = new Scanner(System.in);
		int input = sc.nextInt();
		int quantum = sc.nextInt();
		int timestamp = 0;
		sc.nextLine();
		String p = "";
		int t = 0;
		for (int i =0; i< input; i++) { //////  p1 = p,    500 = t
		  p = sc.next();
		  name.add(p);
		  t = sc.nextInt();
		  time.add(t);

		}
		
		while(!name.isEmpty()) {
			String a = name.poll();
			int ti = time.poll();
			if( ti <= quantum) {
				timestamp += ti;
				System.out.println(a + " " + timestamp);
			
				
			}
			else {
				ti = ti - quantum;
				name.add(a);
				time.add(ti);
				timestamp += quantum;
			}
			
		}
	}
} public class Main{	

public static void main(String[] args) {
		Queue<Integer> time = new LinkedList<Integer>();
		Queue<String> name = new LinkedList<String>();
		
		Scanner sc = new Scanner(System.in);
		int input = sc.nextInt();
		int quantum = sc.nextInt();
		int timestamp = 0;
		sc.nextLine();
		String p = "";
		int t = 0;
		for (int i =0; i< input; i++) { //////  p1 = p,    500 = t
		  p = sc.next();
		  name.add(p);
		  t = sc.nextInt();
		  time.add(t);

		}
		
		while(!name.isEmpty()) {
			String a = name.poll();
			int ti = time.poll();
			if( ti <= quantum) {
				timestamp += ti;
				System.out.println(a + " " + timestamp);
			
				
			}
			else {
				ti = ti - quantum;
				name.add(a);
				time.add(ti);
				timestamp += quantum;
			}
			
		}
	}
} Main
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main{	

public static void main(String[] args) {
		Queue<Integer> time = new LinkedList<Integer>();
		Queue<String> name = new LinkedList<String>();
		
		Scanner sc = new Scanner(System.in);
		int input = sc.nextInt();
		int quantum = sc.nextInt();
		int timestamp = 0;
		sc.nextLine();
		String p = "";
		int t = 0;
		for (int i =0; i< input; i++) { //////  p1 = p,    500 = t
		  p = sc.next();
		  name.add(p);
		  t = sc.nextInt();
		  time.add(t);

		}
		
		while(!name.isEmpty()) {
			String a = name.poll();
			int ti = time.poll();
			if( ti <= quantum) {
				timestamp += ti;
				System.out.println(a + " " + timestamp);
			
				
			}
			else {
				ti = ti - quantum;
				name.add(a);
				time.add(ti);
				timestamp += quantum;
			}
			
		}
	}
}
