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

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

		Scanner cin = new Scanner(System.in);
		while (cin.hasNext()) {
			String[] str = cin.nextLine().split(" ");
			int rundex = Integer.parseInt(str[0]);
			int step = Integer.parseInt(str[1]);
			Queue<node> qu = new LinkedList<node>();
			int time =0;
			for (int i = 1; i <= rundex; i++) {
				str = cin.nextLine().split(" ");
				qu.add(new node(str[0], Integer.parseInt(str[1]),0));
			}
			while (!qu.isEmpty()) {
				node temp = qu.poll();
				if (temp.value <= step) {
					time+=temp.value;
					System.out.println(temp.point +" "+time);
				}
				else{
					time+=step;
					temp.value-=step;
					qu.add(temp);
				}
			}
		}
	}

	static class node {
		String point;
		int value;
		int usetime;
		public node(String point, int value,int usetime) {
			this.point = point;
			this.value = value;
			this.usetime=usetime;
		}
	}
}
 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) {

		Scanner cin = new Scanner(System.in);
		while (cin.hasNext()) {
			String[] str = cin.nextLine().split(" ");
			int rundex = Integer.parseInt(str[0]);
			int step = Integer.parseInt(str[1]);
			Queue<node> qu = new LinkedList<node>();
			int time =0;
			for (int i = 1; i <= rundex; i++) {
				str = cin.nextLine().split(" ");
				qu.add(new node(str[0], Integer.parseInt(str[1]),0));
			}
			while (!qu.isEmpty()) {
				node temp = qu.poll();
				if (temp.value <= step) {
					time+=temp.value;
					System.out.println(temp.point +" "+time);
				}
				else{
					time+=step;
					temp.value-=step;
					qu.add(temp);
				}
			}
		}
	}

	static class node {
		String point;
		int value;
		int usetime;
		public node(String point, int value,int usetime) {
			this.point = point;
			this.value = value;
			this.usetime=usetime;
		}
	}
} Main public static void main(String[] args) {

		Scanner cin = new Scanner(System.in);
		while (cin.hasNext()) {
			String[] str = cin.nextLine().split(" ");
			int rundex = Integer.parseInt(str[0]);
			int step = Integer.parseInt(str[1]);
			Queue<node> qu = new LinkedList<node>();
			int time =0;
			for (int i = 1; i <= rundex; i++) {
				str = cin.nextLine().split(" ");
				qu.add(new node(str[0], Integer.parseInt(str[1]),0));
			}
			while (!qu.isEmpty()) {
				node temp = qu.poll();
				if (temp.value <= step) {
					time+=temp.value;
					System.out.println(temp.point +" "+time);
				}
				else{
					time+=step;
					temp.value-=step;
					qu.add(temp);
				}
			}
		}
	} main {

		Scanner cin = new Scanner(System.in);
		while (cin.hasNext()) {
			String[] str = cin.nextLine().split(" ");
			int rundex = Integer.parseInt(str[0]);
			int step = Integer.parseInt(str[1]);
			Queue<node> qu = new LinkedList<node>();
			int time =0;
			for (int i = 1; i <= rundex; i++) {
				str = cin.nextLine().split(" ");
				qu.add(new node(str[0], Integer.parseInt(str[1]),0));
			}
			while (!qu.isEmpty()) {
				node temp = qu.poll();
				if (temp.value <= step) {
					time+=temp.value;
					System.out.println(temp.point +" "+time);
				}
				else{
					time+=step;
					temp.value-=step;
					qu.add(temp);
				}
			}
		}
	} Scanner cin = new Scanner(System.in); cin new Scanner(System.in) while (cin.hasNext()) {
			String[] str = cin.nextLine().split(" ");
			int rundex = Integer.parseInt(str[0]);
			int step = Integer.parseInt(str[1]);
			Queue<node> qu = new LinkedList<node>();
			int time =0;
			for (int i = 1; i <= rundex; i++) {
				str = cin.nextLine().split(" ");
				qu.add(new node(str[0], Integer.parseInt(str[1]),0));
			}
			while (!qu.isEmpty()) {
				node temp = qu.poll();
				if (temp.value <= step) {
					time+=temp.value;
					System.out.println(temp.point +" "+time);
				}
				else{
					time+=step;
					temp.value-=step;
					qu.add(temp);
				}
			}
		} cin.hasNext() cin.hasNext cin {
			String[] str = cin.nextLine().split(" ");
			int rundex = Integer.parseInt(str[0]);
			int step = Integer.parseInt(str[1]);
			Queue<node> qu = new LinkedList<node>();
			int time =0;
			for (int i = 1; i <= rundex; i++) {
				str = cin.nextLine().split(" ");
				qu.add(new node(str[0], Integer.parseInt(str[1]),0));
			}
			while (!qu.isEmpty()) {
				node temp = qu.poll();
				if (temp.value <= step) {
					time+=temp.value;
					System.out.println(temp.point +" "+time);
				}
				else{
					time+=step;
					temp.value-=step;
					qu.add(temp);
				}
			}
		} String[] str = cin.nextLine().split(" "); str cin.nextLine().split(" ") cin.nextLine().split cin.nextLine() cin.nextLine cin " " int rundex = Integer.parseInt(str[0]); rundex Integer.parseInt(str[0]) Integer.parseInt Integer str[0] str 0 int step = Integer.parseInt(str[1]); step Integer.parseInt(str[1]) Integer.parseInt Integer str[1] str 1 Queue<node> qu = new LinkedList<node>(); qu new LinkedList<node>() int time =0; time 0 for (int i = 1; i <= rundex; i++) {
				str = cin.nextLine().split(" ");
				qu.add(new node(str[0], Integer.parseInt(str[1]),0));
			} int i = 1; int i = 1; i 1 i <= rundex i rundex i++ i++ i {
				str = cin.nextLine().split(" ");
				qu.add(new node(str[0], Integer.parseInt(str[1]),0));
			} {
				str = cin.nextLine().split(" ");
				qu.add(new node(str[0], Integer.parseInt(str[1]),0));
			} str = cin.nextLine().split(" ") str cin.nextLine().split(" ") cin.nextLine().split cin.nextLine() cin.nextLine cin " " qu.add(new node(str[0], Integer.parseInt(str[1]),0)) qu.add qu new node(str[0], Integer.parseInt(str[1]),0) while (!qu.isEmpty()) {
				node temp = qu.poll();
				if (temp.value <= step) {
					time+=temp.value;
					System.out.println(temp.point +" "+time);
				}
				else{
					time+=step;
					temp.value-=step;
					qu.add(temp);
				}
			} !qu.isEmpty() qu.isEmpty() qu.isEmpty qu {
				node temp = qu.poll();
				if (temp.value <= step) {
					time+=temp.value;
					System.out.println(temp.point +" "+time);
				}
				else{
					time+=step;
					temp.value-=step;
					qu.add(temp);
				}
			} node temp = qu.poll(); temp qu.poll() qu.poll qu if (temp.value <= step) {
					time+=temp.value;
					System.out.println(temp.point +" "+time);
				}
				else{
					time+=step;
					temp.value-=step;
					qu.add(temp);
				} temp.value <= step temp.value temp temp.value step {
					time+=temp.value;
					System.out.println(temp.point +" "+time);
				} time+=temp.value time temp.value temp temp.value System.out.println(temp.point +" "+time) System.out.println System.out System System.out temp.point +" "+time temp.point +" "+time temp.point temp temp.point " " time {
					time+=step;
					temp.value-=step;
					qu.add(temp);
				} time+=step time step temp.value-=step temp.value temp temp.value step qu.add(temp) qu.add qu temp String[] args args static class node {
		String point;
		int value;
		int usetime;
		public node(String point, int value,int usetime) {
			this.point = point;
			this.value = value;
			this.usetime=usetime;
		}
	} node String point; point int value; value int usetime; usetime public node(String point, int value,int usetime) {
			this.point = point;
			this.value = value;
			this.usetime=usetime;
		} node {
			this.point = point;
			this.value = value;
			this.usetime=usetime;
		} this.point = point this.point this this.point point this.value = value this.value this this.value value this.usetime=usetime this.usetime this this.usetime usetime String point point int value value int usetime usetime public class Main {
	public static void main(String[] args) {

		Scanner cin = new Scanner(System.in);
		while (cin.hasNext()) {
			String[] str = cin.nextLine().split(" ");
			int rundex = Integer.parseInt(str[0]);
			int step = Integer.parseInt(str[1]);
			Queue<node> qu = new LinkedList<node>();
			int time =0;
			for (int i = 1; i <= rundex; i++) {
				str = cin.nextLine().split(" ");
				qu.add(new node(str[0], Integer.parseInt(str[1]),0));
			}
			while (!qu.isEmpty()) {
				node temp = qu.poll();
				if (temp.value <= step) {
					time+=temp.value;
					System.out.println(temp.point +" "+time);
				}
				else{
					time+=step;
					temp.value-=step;
					qu.add(temp);
				}
			}
		}
	}

	static class node {
		String point;
		int value;
		int usetime;
		public node(String point, int value,int usetime) {
			this.point = point;
			this.value = value;
			this.usetime=usetime;
		}
	}
} public class Main {
	public static void main(String[] args) {

		Scanner cin = new Scanner(System.in);
		while (cin.hasNext()) {
			String[] str = cin.nextLine().split(" ");
			int rundex = Integer.parseInt(str[0]);
			int step = Integer.parseInt(str[1]);
			Queue<node> qu = new LinkedList<node>();
			int time =0;
			for (int i = 1; i <= rundex; i++) {
				str = cin.nextLine().split(" ");
				qu.add(new node(str[0], Integer.parseInt(str[1]),0));
			}
			while (!qu.isEmpty()) {
				node temp = qu.poll();
				if (temp.value <= step) {
					time+=temp.value;
					System.out.println(temp.point +" "+time);
				}
				else{
					time+=step;
					temp.value-=step;
					qu.add(temp);
				}
			}
		}
	}

	static class node {
		String point;
		int value;
		int usetime;
		public node(String point, int value,int usetime) {
			this.point = point;
			this.value = value;
			this.usetime=usetime;
		}
	}
} Main
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

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

		Scanner cin = new Scanner(System.in);
		while (cin.hasNext()) {
			String[] str = cin.nextLine().split(" ");
			int rundex = Integer.parseInt(str[0]);
			int step = Integer.parseInt(str[1]);
			Queue<node> qu = new LinkedList<node>();
			int time =0;
			for (int i = 1; i <= rundex; i++) {
				str = cin.nextLine().split(" ");
				qu.add(new node(str[0], Integer.parseInt(str[1]),0));
			}
			while (!qu.isEmpty()) {
				node temp = qu.poll();
				if (temp.value <= step) {
					time+=temp.value;
					System.out.println(temp.point +" "+time);
				}
				else{
					time+=step;
					temp.value-=step;
					qu.add(temp);
				}
			}
		}
	}

	static class node {
		String point;
		int value;
		int usetime;
		public node(String point, int value,int usetime) {
			this.point = point;
			this.value = value;
			this.usetime=usetime;
		}
	}
}

