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

class Process {
	String name;
	int time;

	public Process(String name, int time) {
		super();
		this.name = name;
		this.time = time;
	}

	public void proceed(int q) {
		this.time -= q;
	}

}

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int q = sc.nextInt();
		sc.nextLine();

		Queue<Process> queue = new LinkedList<>();

		for (int i = 0; i < n; i++) {
			String[] input = sc.nextLine().split(" ");
			Process p = new Process(input[0], Integer.parseInt(input[1]));
			queue.add(p);
		}

		int passedTime = 0;
		while(true) {

			if(queue.isEmpty()) break;

			Process now = queue.poll();
			if(now.time > q) {
				now.proceed(q);
				passedTime += q;
				queue.add(now);
			} else {
				passedTime += now.time;
				System.out.printf("%s %d\n", now.name, passedTime);
			}
		}
	}
} import java.util.LinkedList; LinkedList java.util import java.util.Queue; Queue java.util import java.util.Scanner; Scanner java.util class Process {
	String name;
	int time;

	public Process(String name, int time) {
		super();
		this.name = name;
		this.time = time;
	}

	public void proceed(int q) {
		this.time -= q;
	}

} Process String name; name int time; time public Process(String name, int time) {
		super();
		this.name = name;
		this.time = time;
	} Process {
		super();
		this.name = name;
		this.time = time;
	} super() super 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 void proceed(int q) {
		this.time -= q;
	} proceed {
		this.time -= q;
	} this.time -= q this.time this this.time q int q q public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int q = sc.nextInt();
		sc.nextLine();

		Queue<Process> queue = new LinkedList<>();

		for (int i = 0; i < n; i++) {
			String[] input = sc.nextLine().split(" ");
			Process p = new Process(input[0], Integer.parseInt(input[1]));
			queue.add(p);
		}

		int passedTime = 0;
		while(true) {

			if(queue.isEmpty()) break;

			Process now = queue.poll();
			if(now.time > q) {
				now.proceed(q);
				passedTime += q;
				queue.add(now);
			} else {
				passedTime += now.time;
				System.out.printf("%s %d\n", now.name, passedTime);
			}
		}
	}
} Main public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int q = sc.nextInt();
		sc.nextLine();

		Queue<Process> queue = new LinkedList<>();

		for (int i = 0; i < n; i++) {
			String[] input = sc.nextLine().split(" ");
			Process p = new Process(input[0], Integer.parseInt(input[1]));
			queue.add(p);
		}

		int passedTime = 0;
		while(true) {

			if(queue.isEmpty()) break;

			Process now = queue.poll();
			if(now.time > q) {
				now.proceed(q);
				passedTime += q;
				queue.add(now);
			} else {
				passedTime += now.time;
				System.out.printf("%s %d\n", now.name, passedTime);
			}
		}
	} main {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int q = sc.nextInt();
		sc.nextLine();

		Queue<Process> queue = new LinkedList<>();

		for (int i = 0; i < n; i++) {
			String[] input = sc.nextLine().split(" ");
			Process p = new Process(input[0], Integer.parseInt(input[1]));
			queue.add(p);
		}

		int passedTime = 0;
		while(true) {

			if(queue.isEmpty()) break;

			Process now = queue.poll();
			if(now.time > q) {
				now.proceed(q);
				passedTime += q;
				queue.add(now);
			} else {
				passedTime += now.time;
				System.out.printf("%s %d\n", now.name, passedTime);
			}
		}
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int q = sc.nextInt(); q sc.nextInt() sc.nextInt sc sc.nextLine() sc.nextLine sc Queue<Process> queue = new LinkedList<>(); queue new LinkedList<>() for (int i = 0; i < n; i++) {
			String[] input = sc.nextLine().split(" ");
			Process p = new Process(input[0], Integer.parseInt(input[1]));
			queue.add(p);
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			String[] input = sc.nextLine().split(" ");
			Process p = new Process(input[0], Integer.parseInt(input[1]));
			queue.add(p);
		} {
			String[] input = sc.nextLine().split(" ");
			Process p = new Process(input[0], Integer.parseInt(input[1]));
			queue.add(p);
		} String[] input = sc.nextLine().split(" "); input sc.nextLine().split(" ") sc.nextLine().split sc.nextLine() sc.nextLine sc " " Process p = new Process(input[0], Integer.parseInt(input[1])); p new Process(input[0], Integer.parseInt(input[1])) queue.add(p) queue.add queue p int passedTime = 0; passedTime 0 while(true) {

			if(queue.isEmpty()) break;

			Process now = queue.poll();
			if(now.time > q) {
				now.proceed(q);
				passedTime += q;
				queue.add(now);
			} else {
				passedTime += now.time;
				System.out.printf("%s %d\n", now.name, passedTime);
			}
		} true {

			if(queue.isEmpty()) break;

			Process now = queue.poll();
			if(now.time > q) {
				now.proceed(q);
				passedTime += q;
				queue.add(now);
			} else {
				passedTime += now.time;
				System.out.printf("%s %d\n", now.name, passedTime);
			}
		} if(queue.isEmpty()) break; queue.isEmpty() queue.isEmpty queue break; Process now = queue.poll(); now queue.poll() queue.poll queue if(now.time > q) {
				now.proceed(q);
				passedTime += q;
				queue.add(now);
			} else {
				passedTime += now.time;
				System.out.printf("%s %d\n", now.name, passedTime);
			} now.time > q now.time now now.time q {
				now.proceed(q);
				passedTime += q;
				queue.add(now);
			} now.proceed(q) now.proceed now q passedTime += q passedTime q queue.add(now) queue.add queue now {
				passedTime += now.time;
				System.out.printf("%s %d\n", now.name, passedTime);
			} passedTime += now.time passedTime now.time now now.time System.out.printf("%s %d\n", now.name, passedTime) System.out.printf System.out System System.out "%s %d\n" now.name now now.name passedTime String[] args args public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int q = sc.nextInt();
		sc.nextLine();

		Queue<Process> queue = new LinkedList<>();

		for (int i = 0; i < n; i++) {
			String[] input = sc.nextLine().split(" ");
			Process p = new Process(input[0], Integer.parseInt(input[1]));
			queue.add(p);
		}

		int passedTime = 0;
		while(true) {

			if(queue.isEmpty()) break;

			Process now = queue.poll();
			if(now.time > q) {
				now.proceed(q);
				passedTime += q;
				queue.add(now);
			} else {
				passedTime += now.time;
				System.out.printf("%s %d\n", now.name, passedTime);
			}
		}
	}
} public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int q = sc.nextInt();
		sc.nextLine();

		Queue<Process> queue = new LinkedList<>();

		for (int i = 0; i < n; i++) {
			String[] input = sc.nextLine().split(" ");
			Process p = new Process(input[0], Integer.parseInt(input[1]));
			queue.add(p);
		}

		int passedTime = 0;
		while(true) {

			if(queue.isEmpty()) break;

			Process now = queue.poll();
			if(now.time > q) {
				now.proceed(q);
				passedTime += q;
				queue.add(now);
			} else {
				passedTime += now.time;
				System.out.printf("%s %d\n", now.name, passedTime);
			}
		}
	}
} Main
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

class Process {
	String name;
	int time;

	public Process(String name, int time) {
		super();
		this.name = name;
		this.time = time;
	}

	public void proceed(int q) {
		this.time -= q;
	}

}

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int q = sc.nextInt();
		sc.nextLine();

		Queue<Process> queue = new LinkedList<>();

		for (int i = 0; i < n; i++) {
			String[] input = sc.nextLine().split(" ");
			Process p = new Process(input[0], Integer.parseInt(input[1]));
			queue.add(p);
		}

		int passedTime = 0;
		while(true) {

			if(queue.isEmpty()) break;

			Process now = queue.poll();
			if(now.time > q) {
				now.proceed(q);
				passedTime += q;
				queue.add(now);
			} else {
				passedTime += now.time;
				System.out.printf("%s %d\n", now.name, passedTime);
			}
		}
	}
}