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

public class Main {
	static class NameTime {
		String name;
		int time;
		
	}
	
	public static void queue1(Queue<NameTime> q, int t) {
		int time = 0;
		while (!q.isEmpty()) {
			NameTime nt = q.remove();
			if (nt.time > t) {
				time += t;
				nt.time -= t;
				q.add(nt);
			}
			else {
				time += nt.time;
				System.out.println(nt.name + " " + time);
			}
		}
	}
	public static void main(String[] args) {
		
		Scanner scan = new Scanner(System.in);
		Queue<NameTime> q = new LinkedList<>();
		int n = scan.nextInt();
		int t = scan.nextInt();
		
		for (int i = 0; i < n; ++i) {
			NameTime nt = new NameTime();
			nt.name = scan.next();
			nt.time = scan.nextInt();
			q.add(nt);
		}
		queue1(q, t);
		
	}
}
 import java.util.LinkedList; LinkedList java.util import java.util.Queue; Queue java.util import java.util.Scanner; Scanner java.util public class Main {
	static class NameTime {
		String name;
		int time;
		
	}
	
	public static void queue1(Queue<NameTime> q, int t) {
		int time = 0;
		while (!q.isEmpty()) {
			NameTime nt = q.remove();
			if (nt.time > t) {
				time += t;
				nt.time -= t;
				q.add(nt);
			}
			else {
				time += nt.time;
				System.out.println(nt.name + " " + time);
			}
		}
	}
	public static void main(String[] args) {
		
		Scanner scan = new Scanner(System.in);
		Queue<NameTime> q = new LinkedList<>();
		int n = scan.nextInt();
		int t = scan.nextInt();
		
		for (int i = 0; i < n; ++i) {
			NameTime nt = new NameTime();
			nt.name = scan.next();
			nt.time = scan.nextInt();
			q.add(nt);
		}
		queue1(q, t);
		
	}
} Main public static void queue1(Queue<NameTime> q, int t) {
		int time = 0;
		while (!q.isEmpty()) {
			NameTime nt = q.remove();
			if (nt.time > t) {
				time += t;
				nt.time -= t;
				q.add(nt);
			}
			else {
				time += nt.time;
				System.out.println(nt.name + " " + time);
			}
		}
	} queue1 {
		int time = 0;
		while (!q.isEmpty()) {
			NameTime nt = q.remove();
			if (nt.time > t) {
				time += t;
				nt.time -= t;
				q.add(nt);
			}
			else {
				time += nt.time;
				System.out.println(nt.name + " " + time);
			}
		}
	} int time = 0; time 0 while (!q.isEmpty()) {
			NameTime nt = q.remove();
			if (nt.time > t) {
				time += t;
				nt.time -= t;
				q.add(nt);
			}
			else {
				time += nt.time;
				System.out.println(nt.name + " " + time);
			}
		} !q.isEmpty() q.isEmpty() q.isEmpty q {
			NameTime nt = q.remove();
			if (nt.time > t) {
				time += t;
				nt.time -= t;
				q.add(nt);
			}
			else {
				time += nt.time;
				System.out.println(nt.name + " " + time);
			}
		} NameTime nt = q.remove(); nt q.remove() q.remove q if (nt.time > t) {
				time += t;
				nt.time -= t;
				q.add(nt);
			}
			else {
				time += nt.time;
				System.out.println(nt.name + " " + time);
			} nt.time > t nt.time nt nt.time t {
				time += t;
				nt.time -= t;
				q.add(nt);
			} time += t time t nt.time -= t nt.time nt nt.time t q.add(nt) q.add q nt {
				time += nt.time;
				System.out.println(nt.name + " " + time);
			} time += nt.time time nt.time nt nt.time System.out.println(nt.name + " " + time) System.out.println System.out System System.out nt.name + " " + time nt.name + " " + time nt.name nt nt.name " " time Queue<NameTime> q q int t t public static void main(String[] args) {
		
		Scanner scan = new Scanner(System.in);
		Queue<NameTime> q = new LinkedList<>();
		int n = scan.nextInt();
		int t = scan.nextInt();
		
		for (int i = 0; i < n; ++i) {
			NameTime nt = new NameTime();
			nt.name = scan.next();
			nt.time = scan.nextInt();
			q.add(nt);
		}
		queue1(q, t);
		
	} main {
		
		Scanner scan = new Scanner(System.in);
		Queue<NameTime> q = new LinkedList<>();
		int n = scan.nextInt();
		int t = scan.nextInt();
		
		for (int i = 0; i < n; ++i) {
			NameTime nt = new NameTime();
			nt.name = scan.next();
			nt.time = scan.nextInt();
			q.add(nt);
		}
		queue1(q, t);
		
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) Queue<NameTime> q = new LinkedList<>(); q new LinkedList<>() int n = scan.nextInt(); n scan.nextInt() scan.nextInt scan int t = scan.nextInt(); t scan.nextInt() scan.nextInt scan for (int i = 0; i < n; ++i) {
			NameTime nt = new NameTime();
			nt.name = scan.next();
			nt.time = scan.nextInt();
			q.add(nt);
		} int i = 0; int i = 0; i 0 i < n i n ++i ++i i {
			NameTime nt = new NameTime();
			nt.name = scan.next();
			nt.time = scan.nextInt();
			q.add(nt);
		} {
			NameTime nt = new NameTime();
			nt.name = scan.next();
			nt.time = scan.nextInt();
			q.add(nt);
		} NameTime nt = new NameTime(); nt new NameTime() nt.name = scan.next() nt.name nt nt.name scan.next() scan.next scan nt.time = scan.nextInt() nt.time nt nt.time scan.nextInt() scan.nextInt scan q.add(nt) q.add q nt queue1(q, t) queue1 q t String[] args args static class NameTime {
		String name;
		int time;
		
	} NameTime String name; name int time; time public class Main {
	static class NameTime {
		String name;
		int time;
		
	}
	
	public static void queue1(Queue<NameTime> q, int t) {
		int time = 0;
		while (!q.isEmpty()) {
			NameTime nt = q.remove();
			if (nt.time > t) {
				time += t;
				nt.time -= t;
				q.add(nt);
			}
			else {
				time += nt.time;
				System.out.println(nt.name + " " + time);
			}
		}
	}
	public static void main(String[] args) {
		
		Scanner scan = new Scanner(System.in);
		Queue<NameTime> q = new LinkedList<>();
		int n = scan.nextInt();
		int t = scan.nextInt();
		
		for (int i = 0; i < n; ++i) {
			NameTime nt = new NameTime();
			nt.name = scan.next();
			nt.time = scan.nextInt();
			q.add(nt);
		}
		queue1(q, t);
		
	}
} public class Main {
	static class NameTime {
		String name;
		int time;
		
	}
	
	public static void queue1(Queue<NameTime> q, int t) {
		int time = 0;
		while (!q.isEmpty()) {
			NameTime nt = q.remove();
			if (nt.time > t) {
				time += t;
				nt.time -= t;
				q.add(nt);
			}
			else {
				time += nt.time;
				System.out.println(nt.name + " " + time);
			}
		}
	}
	public static void main(String[] args) {
		
		Scanner scan = new Scanner(System.in);
		Queue<NameTime> q = new LinkedList<>();
		int n = scan.nextInt();
		int t = scan.nextInt();
		
		for (int i = 0; i < n; ++i) {
			NameTime nt = new NameTime();
			nt.name = scan.next();
			nt.time = scan.nextInt();
			q.add(nt);
		}
		queue1(q, t);
		
	}
} Main

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

public class Main {
	static class NameTime {
		String name;
		int time;
		
	}
	
	public static void queue1(Queue<NameTime> q, int t) {
		int time = 0;
		while (!q.isEmpty()) {
			NameTime nt = q.remove();
			if (nt.time > t) {
				time += t;
				nt.time -= t;
				q.add(nt);
			}
			else {
				time += nt.time;
				System.out.println(nt.name + " " + time);
			}
		}
	}
	public static void main(String[] args) {
		
		Scanner scan = new Scanner(System.in);
		Queue<NameTime> q = new LinkedList<>();
		int n = scan.nextInt();
		int t = scan.nextInt();
		
		for (int i = 0; i < n; ++i) {
			NameTime nt = new NameTime();
			nt.name = scan.next();
			nt.time = scan.nextInt();
			q.add(nt);
		}
		queue1(q, t);
		
	}
}

