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

public class Main {
	public static void main(String[] args) throws IOException {

		Scanner scan = new Scanner(System.in);

		Queue<DataS> queue = new ArrayDeque<>();
		int n = scan.nextInt();
		int q = scan.nextInt();
		for (int i = 0; i < n ; i++) {
			String name = scan.next();
			int time = scan.nextInt();
			DataS dataS = new DataS( name, time );
			queue.add(dataS);
		}

		int time = 0;
		while(queue.size() != 0) {
			DataS dataS = queue.poll();
			int dataTime = dataS.getTime();
			if(dataTime > q) {
				time += q;
				dataS.setTime(dataTime - q);
				queue.add(dataS);
			}else {
				time += dataS.getTime();
				System.out.println(dataS.getName() + " " + time);
			}
		}

	}

	static class DataS{
		private String name;
		private int time;
		public DataS(String name , int time) {
			this.name = name;
			this.time = time;
		}
		public String getName() {
			return name;
		}

		public void setTime(int time) {
			this.time = time;
		}

		public int getTime() {
			return time;
		}
	}

}
 import java.io.IOException; IOException java.io import java.util.ArrayDeque; ArrayDeque 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) throws IOException {

		Scanner scan = new Scanner(System.in);

		Queue<DataS> queue = new ArrayDeque<>();
		int n = scan.nextInt();
		int q = scan.nextInt();
		for (int i = 0; i < n ; i++) {
			String name = scan.next();
			int time = scan.nextInt();
			DataS dataS = new DataS( name, time );
			queue.add(dataS);
		}

		int time = 0;
		while(queue.size() != 0) {
			DataS dataS = queue.poll();
			int dataTime = dataS.getTime();
			if(dataTime > q) {
				time += q;
				dataS.setTime(dataTime - q);
				queue.add(dataS);
			}else {
				time += dataS.getTime();
				System.out.println(dataS.getName() + " " + time);
			}
		}

	}

	static class DataS{
		private String name;
		private int time;
		public DataS(String name , int time) {
			this.name = name;
			this.time = time;
		}
		public String getName() {
			return name;
		}

		public void setTime(int time) {
			this.time = time;
		}

		public int getTime() {
			return time;
		}
	}

} Main public static void main(String[] args) throws IOException {

		Scanner scan = new Scanner(System.in);

		Queue<DataS> queue = new ArrayDeque<>();
		int n = scan.nextInt();
		int q = scan.nextInt();
		for (int i = 0; i < n ; i++) {
			String name = scan.next();
			int time = scan.nextInt();
			DataS dataS = new DataS( name, time );
			queue.add(dataS);
		}

		int time = 0;
		while(queue.size() != 0) {
			DataS dataS = queue.poll();
			int dataTime = dataS.getTime();
			if(dataTime > q) {
				time += q;
				dataS.setTime(dataTime - q);
				queue.add(dataS);
			}else {
				time += dataS.getTime();
				System.out.println(dataS.getName() + " " + time);
			}
		}

	} main {

		Scanner scan = new Scanner(System.in);

		Queue<DataS> queue = new ArrayDeque<>();
		int n = scan.nextInt();
		int q = scan.nextInt();
		for (int i = 0; i < n ; i++) {
			String name = scan.next();
			int time = scan.nextInt();
			DataS dataS = new DataS( name, time );
			queue.add(dataS);
		}

		int time = 0;
		while(queue.size() != 0) {
			DataS dataS = queue.poll();
			int dataTime = dataS.getTime();
			if(dataTime > q) {
				time += q;
				dataS.setTime(dataTime - q);
				queue.add(dataS);
			}else {
				time += dataS.getTime();
				System.out.println(dataS.getName() + " " + time);
			}
		}

	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) Queue<DataS> queue = new ArrayDeque<>(); queue new ArrayDeque<>() int n = scan.nextInt(); n scan.nextInt() scan.nextInt scan int q = scan.nextInt(); q scan.nextInt() scan.nextInt scan for (int i = 0; i < n ; i++) {
			String name = scan.next();
			int time = scan.nextInt();
			DataS dataS = new DataS( name, time );
			queue.add(dataS);
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			String name = scan.next();
			int time = scan.nextInt();
			DataS dataS = new DataS( name, time );
			queue.add(dataS);
		} {
			String name = scan.next();
			int time = scan.nextInt();
			DataS dataS = new DataS( name, time );
			queue.add(dataS);
		} String name = scan.next(); name scan.next() scan.next scan int time = scan.nextInt(); time scan.nextInt() scan.nextInt scan DataS dataS = new DataS( name, time ); dataS new DataS( name, time ) queue.add(dataS) queue.add queue dataS int time = 0; time 0 while(queue.size() != 0) {
			DataS dataS = queue.poll();
			int dataTime = dataS.getTime();
			if(dataTime > q) {
				time += q;
				dataS.setTime(dataTime - q);
				queue.add(dataS);
			}else {
				time += dataS.getTime();
				System.out.println(dataS.getName() + " " + time);
			}
		} queue.size() != 0 queue.size() queue.size queue 0 {
			DataS dataS = queue.poll();
			int dataTime = dataS.getTime();
			if(dataTime > q) {
				time += q;
				dataS.setTime(dataTime - q);
				queue.add(dataS);
			}else {
				time += dataS.getTime();
				System.out.println(dataS.getName() + " " + time);
			}
		} DataS dataS = queue.poll(); dataS queue.poll() queue.poll queue int dataTime = dataS.getTime(); dataTime dataS.getTime() dataS.getTime dataS if(dataTime > q) {
				time += q;
				dataS.setTime(dataTime - q);
				queue.add(dataS);
			}else {
				time += dataS.getTime();
				System.out.println(dataS.getName() + " " + time);
			} dataTime > q dataTime q {
				time += q;
				dataS.setTime(dataTime - q);
				queue.add(dataS);
			} time += q time q dataS.setTime(dataTime - q) dataS.setTime dataS dataTime - q dataTime q queue.add(dataS) queue.add queue dataS {
				time += dataS.getTime();
				System.out.println(dataS.getName() + " " + time);
			} time += dataS.getTime() time dataS.getTime() dataS.getTime dataS System.out.println(dataS.getName() + " " + time) System.out.println System.out System System.out dataS.getName() + " " + time dataS.getName() + " " + time dataS.getName() dataS.getName dataS " " time String[] args args static class DataS{
		private String name;
		private int time;
		public DataS(String name , int time) {
			this.name = name;
			this.time = time;
		}
		public String getName() {
			return name;
		}

		public void setTime(int time) {
			this.time = time;
		}

		public int getTime() {
			return time;
		}
	} DataS private String name; name private int time; time public DataS(String name , int time) {
			this.name = name;
			this.time = time;
		} DataS {
			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 setTime(int time) {
			this.time = time;
		} setTime {
			this.time = time;
		} this.time = time this.time this this.time time int time time public int getTime() {
			return time;
		} getTime {
			return time;
		} return time; time public class Main {
	public static void main(String[] args) throws IOException {

		Scanner scan = new Scanner(System.in);

		Queue<DataS> queue = new ArrayDeque<>();
		int n = scan.nextInt();
		int q = scan.nextInt();
		for (int i = 0; i < n ; i++) {
			String name = scan.next();
			int time = scan.nextInt();
			DataS dataS = new DataS( name, time );
			queue.add(dataS);
		}

		int time = 0;
		while(queue.size() != 0) {
			DataS dataS = queue.poll();
			int dataTime = dataS.getTime();
			if(dataTime > q) {
				time += q;
				dataS.setTime(dataTime - q);
				queue.add(dataS);
			}else {
				time += dataS.getTime();
				System.out.println(dataS.getName() + " " + time);
			}
		}

	}

	static class DataS{
		private String name;
		private int time;
		public DataS(String name , int time) {
			this.name = name;
			this.time = time;
		}
		public String getName() {
			return name;
		}

		public void setTime(int time) {
			this.time = time;
		}

		public int getTime() {
			return time;
		}
	}

} public class Main {
	public static void main(String[] args) throws IOException {

		Scanner scan = new Scanner(System.in);

		Queue<DataS> queue = new ArrayDeque<>();
		int n = scan.nextInt();
		int q = scan.nextInt();
		for (int i = 0; i < n ; i++) {
			String name = scan.next();
			int time = scan.nextInt();
			DataS dataS = new DataS( name, time );
			queue.add(dataS);
		}

		int time = 0;
		while(queue.size() != 0) {
			DataS dataS = queue.poll();
			int dataTime = dataS.getTime();
			if(dataTime > q) {
				time += q;
				dataS.setTime(dataTime - q);
				queue.add(dataS);
			}else {
				time += dataS.getTime();
				System.out.println(dataS.getName() + " " + time);
			}
		}

	}

	static class DataS{
		private String name;
		private int time;
		public DataS(String name , int time) {
			this.name = name;
			this.time = time;
		}
		public String getName() {
			return name;
		}

		public void setTime(int time) {
			this.time = time;
		}

		public int getTime() {
			return time;
		}
	}

} Main
import java.io.IOException;
import java.util.ArrayDeque;
import java.util.Queue;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws IOException {

		Scanner scan = new Scanner(System.in);

		Queue<DataS> queue = new ArrayDeque<>();
		int n = scan.nextInt();
		int q = scan.nextInt();
		for (int i = 0; i < n ; i++) {
			String name = scan.next();
			int time = scan.nextInt();
			DataS dataS = new DataS( name, time );
			queue.add(dataS);
		}

		int time = 0;
		while(queue.size() != 0) {
			DataS dataS = queue.poll();
			int dataTime = dataS.getTime();
			if(dataTime > q) {
				time += q;
				dataS.setTime(dataTime - q);
				queue.add(dataS);
			}else {
				time += dataS.getTime();
				System.out.println(dataS.getName() + " " + time);
			}
		}

	}

	static class DataS{
		private String name;
		private int time;
		public DataS(String name , int time) {
			this.name = name;
			this.time = time;
		}
		public String getName() {
			return name;
		}

		public void setTime(int time) {
			this.time = time;
		}

		public int getTime() {
			return time;
		}
	}

}

