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


public class Main {

	static class MyProcess {

		String qName;
		int needTime;
		int finTime = 0;

		public int getFinTime() {
			return finTime;
		}

		public String getqName() {
			return qName;
		}

		public int getNeedTime() {
			return needTime;
		}

		public void setNeedTime(int needTime) {
			this.needTime = needTime;
		}

		public void setFinTime(int finTime) {
			this.finTime = finTime;
		}

		MyProcess(String qName, int needTime, int finTime) {
			this.qName = qName;
			this.needTime = needTime;
			this.finTime = finTime;

		}

	}

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), qTime = sc.nextInt();
		int totalTime = 0;

		MyProcess[] mps = new MyProcess[n];

		for (int i = 0; i < n; i++) {
			mps[i] = new MyProcess(sc.next(), sc.nextInt(), 0);
		}

		java.util.Queue<MyProcess> q = new ArrayDeque<MyProcess>();
		for (int i = 0; i < n; i++) {
			q.add(mps[i]);
		}

		while (q.peek() != null) {
			MyProcess mp = q.poll();
			int needTime = mp.getNeedTime();
			String pName = mp.getqName();
			if (needTime <= qTime) {
				totalTime += needTime;
				mp.setFinTime(totalTime);
				System.out.println(mp.getqName() +" "+ mp.getFinTime());
			} else {
				q.add(new MyProcess(pName, needTime - qTime, 0));
				totalTime += qTime;
			}
		}
	}


}
 import java.util.ArrayDeque; ArrayDeque java.util import java.util.Scanner; Scanner java.util public class Main {

	static class MyProcess {

		String qName;
		int needTime;
		int finTime = 0;

		public int getFinTime() {
			return finTime;
		}

		public String getqName() {
			return qName;
		}

		public int getNeedTime() {
			return needTime;
		}

		public void setNeedTime(int needTime) {
			this.needTime = needTime;
		}

		public void setFinTime(int finTime) {
			this.finTime = finTime;
		}

		MyProcess(String qName, int needTime, int finTime) {
			this.qName = qName;
			this.needTime = needTime;
			this.finTime = finTime;

		}

	}

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), qTime = sc.nextInt();
		int totalTime = 0;

		MyProcess[] mps = new MyProcess[n];

		for (int i = 0; i < n; i++) {
			mps[i] = new MyProcess(sc.next(), sc.nextInt(), 0);
		}

		java.util.Queue<MyProcess> q = new ArrayDeque<MyProcess>();
		for (int i = 0; i < n; i++) {
			q.add(mps[i]);
		}

		while (q.peek() != null) {
			MyProcess mp = q.poll();
			int needTime = mp.getNeedTime();
			String pName = mp.getqName();
			if (needTime <= qTime) {
				totalTime += needTime;
				mp.setFinTime(totalTime);
				System.out.println(mp.getqName() +" "+ mp.getFinTime());
			} else {
				q.add(new MyProcess(pName, needTime - qTime, 0));
				totalTime += qTime;
			}
		}
	}


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

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), qTime = sc.nextInt();
		int totalTime = 0;

		MyProcess[] mps = new MyProcess[n];

		for (int i = 0; i < n; i++) {
			mps[i] = new MyProcess(sc.next(), sc.nextInt(), 0);
		}

		java.util.Queue<MyProcess> q = new ArrayDeque<MyProcess>();
		for (int i = 0; i < n; i++) {
			q.add(mps[i]);
		}

		while (q.peek() != null) {
			MyProcess mp = q.poll();
			int needTime = mp.getNeedTime();
			String pName = mp.getqName();
			if (needTime <= qTime) {
				totalTime += needTime;
				mp.setFinTime(totalTime);
				System.out.println(mp.getqName() +" "+ mp.getFinTime());
			} else {
				q.add(new MyProcess(pName, needTime - qTime, 0));
				totalTime += qTime;
			}
		}
	} main {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), qTime = sc.nextInt();
		int totalTime = 0;

		MyProcess[] mps = new MyProcess[n];

		for (int i = 0; i < n; i++) {
			mps[i] = new MyProcess(sc.next(), sc.nextInt(), 0);
		}

		java.util.Queue<MyProcess> q = new ArrayDeque<MyProcess>();
		for (int i = 0; i < n; i++) {
			q.add(mps[i]);
		}

		while (q.peek() != null) {
			MyProcess mp = q.poll();
			int needTime = mp.getNeedTime();
			String pName = mp.getqName();
			if (needTime <= qTime) {
				totalTime += needTime;
				mp.setFinTime(totalTime);
				System.out.println(mp.getqName() +" "+ mp.getFinTime());
			} else {
				q.add(new MyProcess(pName, needTime - qTime, 0));
				totalTime += qTime;
			}
		}
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt() n sc.nextInt() sc.nextInt sc qTime = sc.nextInt(); qTime sc.nextInt() sc.nextInt sc int totalTime = 0; totalTime 0 MyProcess[] mps = new MyProcess[n]; mps new MyProcess[n] n for (int i = 0; i < n; i++) {
			mps[i] = new MyProcess(sc.next(), sc.nextInt(), 0);
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			mps[i] = new MyProcess(sc.next(), sc.nextInt(), 0);
		} {
			mps[i] = new MyProcess(sc.next(), sc.nextInt(), 0);
		} mps[i] = new MyProcess(sc.next(), sc.nextInt(), 0) mps[i] mps i new MyProcess(sc.next(), sc.nextInt(), 0) java.util.Queue<MyProcess> q = new ArrayDeque<MyProcess>(); q new ArrayDeque<MyProcess>() for (int i = 0; i < n; i++) {
			q.add(mps[i]);
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			q.add(mps[i]);
		} {
			q.add(mps[i]);
		} q.add(mps[i]) q.add q mps[i] mps i while (q.peek() != null) {
			MyProcess mp = q.poll();
			int needTime = mp.getNeedTime();
			String pName = mp.getqName();
			if (needTime <= qTime) {
				totalTime += needTime;
				mp.setFinTime(totalTime);
				System.out.println(mp.getqName() +" "+ mp.getFinTime());
			} else {
				q.add(new MyProcess(pName, needTime - qTime, 0));
				totalTime += qTime;
			}
		} q.peek() != null q.peek() q.peek q null {
			MyProcess mp = q.poll();
			int needTime = mp.getNeedTime();
			String pName = mp.getqName();
			if (needTime <= qTime) {
				totalTime += needTime;
				mp.setFinTime(totalTime);
				System.out.println(mp.getqName() +" "+ mp.getFinTime());
			} else {
				q.add(new MyProcess(pName, needTime - qTime, 0));
				totalTime += qTime;
			}
		} MyProcess mp = q.poll(); mp q.poll() q.poll q int needTime = mp.getNeedTime(); needTime mp.getNeedTime() mp.getNeedTime mp String pName = mp.getqName(); pName mp.getqName() mp.getqName mp if (needTime <= qTime) {
				totalTime += needTime;
				mp.setFinTime(totalTime);
				System.out.println(mp.getqName() +" "+ mp.getFinTime());
			} else {
				q.add(new MyProcess(pName, needTime - qTime, 0));
				totalTime += qTime;
			} needTime <= qTime needTime qTime {
				totalTime += needTime;
				mp.setFinTime(totalTime);
				System.out.println(mp.getqName() +" "+ mp.getFinTime());
			} totalTime += needTime totalTime needTime mp.setFinTime(totalTime) mp.setFinTime mp totalTime System.out.println(mp.getqName() +" "+ mp.getFinTime()) System.out.println System.out System System.out mp.getqName() +" "+ mp.getFinTime() mp.getqName() +" "+ mp.getFinTime() mp.getqName() mp.getqName mp " " mp.getFinTime() mp.getFinTime mp {
				q.add(new MyProcess(pName, needTime - qTime, 0));
				totalTime += qTime;
			} q.add(new MyProcess(pName, needTime - qTime, 0)) q.add q new MyProcess(pName, needTime - qTime, 0) totalTime += qTime totalTime qTime String[] args args static class MyProcess {

		String qName;
		int needTime;
		int finTime = 0;

		public int getFinTime() {
			return finTime;
		}

		public String getqName() {
			return qName;
		}

		public int getNeedTime() {
			return needTime;
		}

		public void setNeedTime(int needTime) {
			this.needTime = needTime;
		}

		public void setFinTime(int finTime) {
			this.finTime = finTime;
		}

		MyProcess(String qName, int needTime, int finTime) {
			this.qName = qName;
			this.needTime = needTime;
			this.finTime = finTime;

		}

	} MyProcess String qName; qName int needTime; needTime int finTime = 0; finTime 0 public int getFinTime() {
			return finTime;
		} getFinTime {
			return finTime;
		} return finTime; finTime public String getqName() {
			return qName;
		} getqName {
			return qName;
		} return qName; qName public int getNeedTime() {
			return needTime;
		} getNeedTime {
			return needTime;
		} return needTime; needTime public void setNeedTime(int needTime) {
			this.needTime = needTime;
		} setNeedTime {
			this.needTime = needTime;
		} this.needTime = needTime this.needTime this this.needTime needTime int needTime needTime public void setFinTime(int finTime) {
			this.finTime = finTime;
		} setFinTime {
			this.finTime = finTime;
		} this.finTime = finTime this.finTime this this.finTime finTime int finTime finTime MyProcess(String qName, int needTime, int finTime) {
			this.qName = qName;
			this.needTime = needTime;
			this.finTime = finTime;

		} MyProcess {
			this.qName = qName;
			this.needTime = needTime;
			this.finTime = finTime;

		} this.qName = qName this.qName this this.qName qName this.needTime = needTime this.needTime this this.needTime needTime this.finTime = finTime this.finTime this this.finTime finTime String qName qName int needTime needTime int finTime finTime public class Main {

	static class MyProcess {

		String qName;
		int needTime;
		int finTime = 0;

		public int getFinTime() {
			return finTime;
		}

		public String getqName() {
			return qName;
		}

		public int getNeedTime() {
			return needTime;
		}

		public void setNeedTime(int needTime) {
			this.needTime = needTime;
		}

		public void setFinTime(int finTime) {
			this.finTime = finTime;
		}

		MyProcess(String qName, int needTime, int finTime) {
			this.qName = qName;
			this.needTime = needTime;
			this.finTime = finTime;

		}

	}

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), qTime = sc.nextInt();
		int totalTime = 0;

		MyProcess[] mps = new MyProcess[n];

		for (int i = 0; i < n; i++) {
			mps[i] = new MyProcess(sc.next(), sc.nextInt(), 0);
		}

		java.util.Queue<MyProcess> q = new ArrayDeque<MyProcess>();
		for (int i = 0; i < n; i++) {
			q.add(mps[i]);
		}

		while (q.peek() != null) {
			MyProcess mp = q.poll();
			int needTime = mp.getNeedTime();
			String pName = mp.getqName();
			if (needTime <= qTime) {
				totalTime += needTime;
				mp.setFinTime(totalTime);
				System.out.println(mp.getqName() +" "+ mp.getFinTime());
			} else {
				q.add(new MyProcess(pName, needTime - qTime, 0));
				totalTime += qTime;
			}
		}
	}


} public class Main {

	static class MyProcess {

		String qName;
		int needTime;
		int finTime = 0;

		public int getFinTime() {
			return finTime;
		}

		public String getqName() {
			return qName;
		}

		public int getNeedTime() {
			return needTime;
		}

		public void setNeedTime(int needTime) {
			this.needTime = needTime;
		}

		public void setFinTime(int finTime) {
			this.finTime = finTime;
		}

		MyProcess(String qName, int needTime, int finTime) {
			this.qName = qName;
			this.needTime = needTime;
			this.finTime = finTime;

		}

	}

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), qTime = sc.nextInt();
		int totalTime = 0;

		MyProcess[] mps = new MyProcess[n];

		for (int i = 0; i < n; i++) {
			mps[i] = new MyProcess(sc.next(), sc.nextInt(), 0);
		}

		java.util.Queue<MyProcess> q = new ArrayDeque<MyProcess>();
		for (int i = 0; i < n; i++) {
			q.add(mps[i]);
		}

		while (q.peek() != null) {
			MyProcess mp = q.poll();
			int needTime = mp.getNeedTime();
			String pName = mp.getqName();
			if (needTime <= qTime) {
				totalTime += needTime;
				mp.setFinTime(totalTime);
				System.out.println(mp.getqName() +" "+ mp.getFinTime());
			} else {
				q.add(new MyProcess(pName, needTime - qTime, 0));
				totalTime += qTime;
			}
		}
	}


} Main
import java.util.ArrayDeque;
import java.util.Scanner;


public class Main {

	static class MyProcess {

		String qName;
		int needTime;
		int finTime = 0;

		public int getFinTime() {
			return finTime;
		}

		public String getqName() {
			return qName;
		}

		public int getNeedTime() {
			return needTime;
		}

		public void setNeedTime(int needTime) {
			this.needTime = needTime;
		}

		public void setFinTime(int finTime) {
			this.finTime = finTime;
		}

		MyProcess(String qName, int needTime, int finTime) {
			this.qName = qName;
			this.needTime = needTime;
			this.finTime = finTime;

		}

	}

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), qTime = sc.nextInt();
		int totalTime = 0;

		MyProcess[] mps = new MyProcess[n];

		for (int i = 0; i < n; i++) {
			mps[i] = new MyProcess(sc.next(), sc.nextInt(), 0);
		}

		java.util.Queue<MyProcess> q = new ArrayDeque<MyProcess>();
		for (int i = 0; i < n; i++) {
			q.add(mps[i]);
		}

		while (q.peek() != null) {
			MyProcess mp = q.poll();
			int needTime = mp.getNeedTime();
			String pName = mp.getqName();
			if (needTime <= qTime) {
				totalTime += needTime;
				mp.setFinTime(totalTime);
				System.out.println(mp.getqName() +" "+ mp.getFinTime());
			} else {
				q.add(new MyProcess(pName, needTime - qTime, 0));
				totalTime += qTime;
			}
		}
	}


}

