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

class Main {public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		
		Queue<String> name = new ArrayDeque<>();
		Queue<Integer> time = new ArrayDeque<>();
		
		int n = sc.nextInt();
		int q = sc.nextInt();
		
		for(int i = 0; i < n; i++) {
			name.add(sc.next());
			time.add(sc.nextInt());
		}
		
		int t = 0;
		while(!name.isEmpty()) {
			String tmpname = name.poll();
			int tmptime = time.poll();
			
			if(tmptime - q <= 0) {
				t += tmptime;
				System.out.println(tmpname + " " + t);
			}else {
				t += q;
				name.add(tmpname);
				time.add(tmptime - q);
			}
		}
	}
} import java.util.ArrayDeque; ArrayDeque java.util import java.util.Queue; Queue java.util import java.util.Scanner; Scanner java.util class Main {public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		
		Queue<String> name = new ArrayDeque<>();
		Queue<Integer> time = new ArrayDeque<>();
		
		int n = sc.nextInt();
		int q = sc.nextInt();
		
		for(int i = 0; i < n; i++) {
			name.add(sc.next());
			time.add(sc.nextInt());
		}
		
		int t = 0;
		while(!name.isEmpty()) {
			String tmpname = name.poll();
			int tmptime = time.poll();
			
			if(tmptime - q <= 0) {
				t += tmptime;
				System.out.println(tmpname + " " + t);
			}else {
				t += q;
				name.add(tmpname);
				time.add(tmptime - q);
			}
		}
	}
} Main public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		
		Queue<String> name = new ArrayDeque<>();
		Queue<Integer> time = new ArrayDeque<>();
		
		int n = sc.nextInt();
		int q = sc.nextInt();
		
		for(int i = 0; i < n; i++) {
			name.add(sc.next());
			time.add(sc.nextInt());
		}
		
		int t = 0;
		while(!name.isEmpty()) {
			String tmpname = name.poll();
			int tmptime = time.poll();
			
			if(tmptime - q <= 0) {
				t += tmptime;
				System.out.println(tmpname + " " + t);
			}else {
				t += q;
				name.add(tmpname);
				time.add(tmptime - q);
			}
		}
	} main {
		Scanner sc = new Scanner(System.in);
		
		Queue<String> name = new ArrayDeque<>();
		Queue<Integer> time = new ArrayDeque<>();
		
		int n = sc.nextInt();
		int q = sc.nextInt();
		
		for(int i = 0; i < n; i++) {
			name.add(sc.next());
			time.add(sc.nextInt());
		}
		
		int t = 0;
		while(!name.isEmpty()) {
			String tmpname = name.poll();
			int tmptime = time.poll();
			
			if(tmptime - q <= 0) {
				t += tmptime;
				System.out.println(tmpname + " " + t);
			}else {
				t += q;
				name.add(tmpname);
				time.add(tmptime - q);
			}
		}
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) Queue<String> name = new ArrayDeque<>(); name new ArrayDeque<>() Queue<Integer> time = new ArrayDeque<>(); time new ArrayDeque<>() int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int q = sc.nextInt(); q sc.nextInt() sc.nextInt sc for(int i = 0; i < n; i++) {
			name.add(sc.next());
			time.add(sc.nextInt());
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			name.add(sc.next());
			time.add(sc.nextInt());
		} {
			name.add(sc.next());
			time.add(sc.nextInt());
		} name.add(sc.next()) name.add name sc.next() sc.next sc time.add(sc.nextInt()) time.add time sc.nextInt() sc.nextInt sc int t = 0; t 0 while(!name.isEmpty()) {
			String tmpname = name.poll();
			int tmptime = time.poll();
			
			if(tmptime - q <= 0) {
				t += tmptime;
				System.out.println(tmpname + " " + t);
			}else {
				t += q;
				name.add(tmpname);
				time.add(tmptime - q);
			}
		} !name.isEmpty() name.isEmpty() name.isEmpty name {
			String tmpname = name.poll();
			int tmptime = time.poll();
			
			if(tmptime - q <= 0) {
				t += tmptime;
				System.out.println(tmpname + " " + t);
			}else {
				t += q;
				name.add(tmpname);
				time.add(tmptime - q);
			}
		} String tmpname = name.poll(); tmpname name.poll() name.poll name int tmptime = time.poll(); tmptime time.poll() time.poll time if(tmptime - q <= 0) {
				t += tmptime;
				System.out.println(tmpname + " " + t);
			}else {
				t += q;
				name.add(tmpname);
				time.add(tmptime - q);
			} tmptime - q <= 0 tmptime - q tmptime q 0 {
				t += tmptime;
				System.out.println(tmpname + " " + t);
			} t += tmptime t tmptime System.out.println(tmpname + " " + t) System.out.println System.out System System.out tmpname + " " + t tmpname + " " + t tmpname " " t {
				t += q;
				name.add(tmpname);
				time.add(tmptime - q);
			} t += q t q name.add(tmpname) name.add name tmpname time.add(tmptime - q) time.add time tmptime - q tmptime q String args[] args
import java.util.ArrayDeque;
import java.util.Queue;
import java.util.Scanner;

class Main {public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		
		Queue<String> name = new ArrayDeque<>();
		Queue<Integer> time = new ArrayDeque<>();
		
		int n = sc.nextInt();
		int q = sc.nextInt();
		
		for(int i = 0; i < n; i++) {
			name.add(sc.next());
			time.add(sc.nextInt());
		}
		
		int t = 0;
		while(!name.isEmpty()) {
			String tmpname = name.poll();
			int tmptime = time.poll();
			
			if(tmptime - q <= 0) {
				t += tmptime;
				System.out.println(tmpname + " " + t);
			}else {
				t += q;
				name.add(tmpname);
				time.add(tmptime - q);
			}
		}
	}
}
