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

public class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int q = scan.nextInt();
		Queue<Data> queue = new ArrayDeque<Data>();
		for(int i = 0; i < n; i++) {
			Data d = new Data(scan.next(), scan.nextInt());
			queue.add(d);
		}
		scan.close();
		StringBuilder sb = new StringBuilder();
		int time = 0;
		while(queue.size() != 0) {
			Data d = queue.poll();
			if(q >= d.getTime()) {
				time += d.getTime();
				if(queue.size() == 0) {
					sb.append(d.getName() + " " + time);
				}else {
					sb.append(d.getName() + " " + time + "\n");
				}

			}else {
				time += q;
				int res = d.getTime() - q;
				d.setTime(res);
				queue.add(d);
			}
		}
		System.out.println(sb.toString());
	}
}

class Data{
	String name;
	int time;
	public Data(String name, int time) {
		this.name = name;
		this.time = time;
	}
	public String getName() {
		return name;
	}
	public int getTime() {
		return time;
	}
	public void setTime(int time) {
		this.time = time;
	}
}
 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) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int q = scan.nextInt();
		Queue<Data> queue = new ArrayDeque<Data>();
		for(int i = 0; i < n; i++) {
			Data d = new Data(scan.next(), scan.nextInt());
			queue.add(d);
		}
		scan.close();
		StringBuilder sb = new StringBuilder();
		int time = 0;
		while(queue.size() != 0) {
			Data d = queue.poll();
			if(q >= d.getTime()) {
				time += d.getTime();
				if(queue.size() == 0) {
					sb.append(d.getName() + " " + time);
				}else {
					sb.append(d.getName() + " " + time + "\n");
				}

			}else {
				time += q;
				int res = d.getTime() - q;
				d.setTime(res);
				queue.add(d);
			}
		}
		System.out.println(sb.toString());
	}
} Main public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int q = scan.nextInt();
		Queue<Data> queue = new ArrayDeque<Data>();
		for(int i = 0; i < n; i++) {
			Data d = new Data(scan.next(), scan.nextInt());
			queue.add(d);
		}
		scan.close();
		StringBuilder sb = new StringBuilder();
		int time = 0;
		while(queue.size() != 0) {
			Data d = queue.poll();
			if(q >= d.getTime()) {
				time += d.getTime();
				if(queue.size() == 0) {
					sb.append(d.getName() + " " + time);
				}else {
					sb.append(d.getName() + " " + time + "\n");
				}

			}else {
				time += q;
				int res = d.getTime() - q;
				d.setTime(res);
				queue.add(d);
			}
		}
		System.out.println(sb.toString());
	} main {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int q = scan.nextInt();
		Queue<Data> queue = new ArrayDeque<Data>();
		for(int i = 0; i < n; i++) {
			Data d = new Data(scan.next(), scan.nextInt());
			queue.add(d);
		}
		scan.close();
		StringBuilder sb = new StringBuilder();
		int time = 0;
		while(queue.size() != 0) {
			Data d = queue.poll();
			if(q >= d.getTime()) {
				time += d.getTime();
				if(queue.size() == 0) {
					sb.append(d.getName() + " " + time);
				}else {
					sb.append(d.getName() + " " + time + "\n");
				}

			}else {
				time += q;
				int res = d.getTime() - q;
				d.setTime(res);
				queue.add(d);
			}
		}
		System.out.println(sb.toString());
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int n = scan.nextInt(); n scan.nextInt() scan.nextInt scan int q = scan.nextInt(); q scan.nextInt() scan.nextInt scan Queue<Data> queue = new ArrayDeque<Data>(); queue new ArrayDeque<Data>() for(int i = 0; i < n; i++) {
			Data d = new Data(scan.next(), scan.nextInt());
			queue.add(d);
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			Data d = new Data(scan.next(), scan.nextInt());
			queue.add(d);
		} {
			Data d = new Data(scan.next(), scan.nextInt());
			queue.add(d);
		} Data d = new Data(scan.next(), scan.nextInt()); d new Data(scan.next(), scan.nextInt()) queue.add(d) queue.add queue d scan.close() scan.close scan StringBuilder sb = new StringBuilder(); sb new StringBuilder() int time = 0; time 0 while(queue.size() != 0) {
			Data d = queue.poll();
			if(q >= d.getTime()) {
				time += d.getTime();
				if(queue.size() == 0) {
					sb.append(d.getName() + " " + time);
				}else {
					sb.append(d.getName() + " " + time + "\n");
				}

			}else {
				time += q;
				int res = d.getTime() - q;
				d.setTime(res);
				queue.add(d);
			}
		} queue.size() != 0 queue.size() queue.size queue 0 {
			Data d = queue.poll();
			if(q >= d.getTime()) {
				time += d.getTime();
				if(queue.size() == 0) {
					sb.append(d.getName() + " " + time);
				}else {
					sb.append(d.getName() + " " + time + "\n");
				}

			}else {
				time += q;
				int res = d.getTime() - q;
				d.setTime(res);
				queue.add(d);
			}
		} Data d = queue.poll(); d queue.poll() queue.poll queue if(q >= d.getTime()) {
				time += d.getTime();
				if(queue.size() == 0) {
					sb.append(d.getName() + " " + time);
				}else {
					sb.append(d.getName() + " " + time + "\n");
				}

			}else {
				time += q;
				int res = d.getTime() - q;
				d.setTime(res);
				queue.add(d);
			} q >= d.getTime() q d.getTime() d.getTime d {
				time += d.getTime();
				if(queue.size() == 0) {
					sb.append(d.getName() + " " + time);
				}else {
					sb.append(d.getName() + " " + time + "\n");
				}

			} time += d.getTime() time d.getTime() d.getTime d if(queue.size() == 0) {
					sb.append(d.getName() + " " + time);
				}else {
					sb.append(d.getName() + " " + time + "\n");
				} queue.size() == 0 queue.size() queue.size queue 0 {
					sb.append(d.getName() + " " + time);
				} sb.append(d.getName() + " " + time) sb.append sb d.getName() + " " + time d.getName() + " " + time d.getName() d.getName d " " time {
					sb.append(d.getName() + " " + time + "\n");
				} sb.append(d.getName() + " " + time + "\n") sb.append sb d.getName() + " " + time + "\n" time d.getName() + " " + time + "\n" d.getName() d.getName d " " time "\n" {
				time += q;
				int res = d.getTime() - q;
				d.setTime(res);
				queue.add(d);
			} time += q time q int res = d.getTime() - q; res d.getTime() - q d.getTime() d.getTime d q d.setTime(res) d.setTime d res queue.add(d) queue.add queue d System.out.println(sb.toString()) System.out.println System.out System System.out sb.toString() sb.toString sb String[] args args class Data{
	String name;
	int time;
	public Data(String name, int time) {
		this.name = name;
		this.time = time;
	}
	public String getName() {
		return name;
	}
	public int getTime() {
		return time;
	}
	public void setTime(int time) {
		this.time = time;
	}
} Data String name; name int time; time public Data(String name, int time) {
		this.name = name;
		this.time = time;
	} Data {
		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 int getTime() {
		return time;
	} getTime {
		return time;
	} return time; time 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 class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int q = scan.nextInt();
		Queue<Data> queue = new ArrayDeque<Data>();
		for(int i = 0; i < n; i++) {
			Data d = new Data(scan.next(), scan.nextInt());
			queue.add(d);
		}
		scan.close();
		StringBuilder sb = new StringBuilder();
		int time = 0;
		while(queue.size() != 0) {
			Data d = queue.poll();
			if(q >= d.getTime()) {
				time += d.getTime();
				if(queue.size() == 0) {
					sb.append(d.getName() + " " + time);
				}else {
					sb.append(d.getName() + " " + time + "\n");
				}

			}else {
				time += q;
				int res = d.getTime() - q;
				d.setTime(res);
				queue.add(d);
			}
		}
		System.out.println(sb.toString());
	}
} public class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int q = scan.nextInt();
		Queue<Data> queue = new ArrayDeque<Data>();
		for(int i = 0; i < n; i++) {
			Data d = new Data(scan.next(), scan.nextInt());
			queue.add(d);
		}
		scan.close();
		StringBuilder sb = new StringBuilder();
		int time = 0;
		while(queue.size() != 0) {
			Data d = queue.poll();
			if(q >= d.getTime()) {
				time += d.getTime();
				if(queue.size() == 0) {
					sb.append(d.getName() + " " + time);
				}else {
					sb.append(d.getName() + " " + time + "\n");
				}

			}else {
				time += q;
				int res = d.getTime() - q;
				d.setTime(res);
				queue.add(d);
			}
		}
		System.out.println(sb.toString());
	}
} Main
import java.util.ArrayDeque;
import java.util.Queue;
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int q = scan.nextInt();
		Queue<Data> queue = new ArrayDeque<Data>();
		for(int i = 0; i < n; i++) {
			Data d = new Data(scan.next(), scan.nextInt());
			queue.add(d);
		}
		scan.close();
		StringBuilder sb = new StringBuilder();
		int time = 0;
		while(queue.size() != 0) {
			Data d = queue.poll();
			if(q >= d.getTime()) {
				time += d.getTime();
				if(queue.size() == 0) {
					sb.append(d.getName() + " " + time);
				}else {
					sb.append(d.getName() + " " + time + "\n");
				}

			}else {
				time += q;
				int res = d.getTime() - q;
				d.setTime(res);
				queue.add(d);
			}
		}
		System.out.println(sb.toString());
	}
}

class Data{
	String name;
	int time;
	public Data(String name, int time) {
		this.name = name;
		this.time = time;
	}
	public String getName() {
		return name;
	}
	public int getTime() {
		return time;
	}
	public void setTime(int time) {
		this.time = time;
	}
}

