import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;

public class Main {
	public static void main(String[] args) {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		ArrayDeque<Task> q = new ArrayDeque<Task>();
		ArrayDeque<Task> ans = new ArrayDeque<Task>();
		
		try {
			String[] param = in.readLine().split(" ");
			int lim = Integer.parseInt(param[0]);
			int time = Integer.parseInt(param[1]);
			
			for (int i = 0; i < lim; i++) {
				param = in.readLine().split(" ");
				
				Task t = new Task(Integer.parseInt(param[1]), param[0]);
				q.add(t);
			}
			
			int past = 0;
			while (q.isEmpty() == false) {
				Task tmp = q.remove();
				boolean flag = tmp.minusTime(time);
				
				if (flag == true) {
					past = past + tmp.getTIme() + time;
					ans.add(new Task(past, tmp.getName()));
				} else {
					past = past + time;
					q.add(tmp);
				}
			}
			
			while (ans.isEmpty() == false) {
				Task tmp = ans.remove();
				System.out.println(tmp.getName() + " " + tmp.getTIme());
			}
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}

class Task {
	private int time;
	private String name;
	
	public Task(int t, String n) {
		time = t;
		name = n;
	}
	
	public int getTIme() {
		return time;
	}
	
	public String getName() {
		return name;
	}
	
	public boolean minusTime(int t) {
		time = time - t;
		if (time <= 0) return true;
		return false;
	}
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io import java.util.ArrayDeque; ArrayDeque java.util public class Main {
	public static void main(String[] args) {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		ArrayDeque<Task> q = new ArrayDeque<Task>();
		ArrayDeque<Task> ans = new ArrayDeque<Task>();
		
		try {
			String[] param = in.readLine().split(" ");
			int lim = Integer.parseInt(param[0]);
			int time = Integer.parseInt(param[1]);
			
			for (int i = 0; i < lim; i++) {
				param = in.readLine().split(" ");
				
				Task t = new Task(Integer.parseInt(param[1]), param[0]);
				q.add(t);
			}
			
			int past = 0;
			while (q.isEmpty() == false) {
				Task tmp = q.remove();
				boolean flag = tmp.minusTime(time);
				
				if (flag == true) {
					past = past + tmp.getTIme() + time;
					ans.add(new Task(past, tmp.getName()));
				} else {
					past = past + time;
					q.add(tmp);
				}
			}
			
			while (ans.isEmpty() == false) {
				Task tmp = ans.remove();
				System.out.println(tmp.getName() + " " + tmp.getTIme());
			}
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
} Main public static void main(String[] args) {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		ArrayDeque<Task> q = new ArrayDeque<Task>();
		ArrayDeque<Task> ans = new ArrayDeque<Task>();
		
		try {
			String[] param = in.readLine().split(" ");
			int lim = Integer.parseInt(param[0]);
			int time = Integer.parseInt(param[1]);
			
			for (int i = 0; i < lim; i++) {
				param = in.readLine().split(" ");
				
				Task t = new Task(Integer.parseInt(param[1]), param[0]);
				q.add(t);
			}
			
			int past = 0;
			while (q.isEmpty() == false) {
				Task tmp = q.remove();
				boolean flag = tmp.minusTime(time);
				
				if (flag == true) {
					past = past + tmp.getTIme() + time;
					ans.add(new Task(past, tmp.getName()));
				} else {
					past = past + time;
					q.add(tmp);
				}
			}
			
			while (ans.isEmpty() == false) {
				Task tmp = ans.remove();
				System.out.println(tmp.getName() + " " + tmp.getTIme());
			}
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	} main {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		ArrayDeque<Task> q = new ArrayDeque<Task>();
		ArrayDeque<Task> ans = new ArrayDeque<Task>();
		
		try {
			String[] param = in.readLine().split(" ");
			int lim = Integer.parseInt(param[0]);
			int time = Integer.parseInt(param[1]);
			
			for (int i = 0; i < lim; i++) {
				param = in.readLine().split(" ");
				
				Task t = new Task(Integer.parseInt(param[1]), param[0]);
				q.add(t);
			}
			
			int past = 0;
			while (q.isEmpty() == false) {
				Task tmp = q.remove();
				boolean flag = tmp.minusTime(time);
				
				if (flag == true) {
					past = past + tmp.getTIme() + time;
					ans.add(new Task(past, tmp.getName()));
				} else {
					past = past + time;
					q.add(tmp);
				}
			}
			
			while (ans.isEmpty() == false) {
				Task tmp = ans.remove();
				System.out.println(tmp.getName() + " " + tmp.getTIme());
			}
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	} BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); in new BufferedReader(new InputStreamReader(System.in)) ArrayDeque<Task> q = new ArrayDeque<Task>(); q new ArrayDeque<Task>() ArrayDeque<Task> ans = new ArrayDeque<Task>(); ans new ArrayDeque<Task>() try {
			String[] param = in.readLine().split(" ");
			int lim = Integer.parseInt(param[0]);
			int time = Integer.parseInt(param[1]);
			
			for (int i = 0; i < lim; i++) {
				param = in.readLine().split(" ");
				
				Task t = new Task(Integer.parseInt(param[1]), param[0]);
				q.add(t);
			}
			
			int past = 0;
			while (q.isEmpty() == false) {
				Task tmp = q.remove();
				boolean flag = tmp.minusTime(time);
				
				if (flag == true) {
					past = past + tmp.getTIme() + time;
					ans.add(new Task(past, tmp.getName()));
				} else {
					past = past + time;
					q.add(tmp);
				}
			}
			
			while (ans.isEmpty() == false) {
				Task tmp = ans.remove();
				System.out.println(tmp.getName() + " " + tmp.getTIme());
			}
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} NumberFormatException e {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} e.printStackTrace() e.printStackTrace e catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} IOException e {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} e.printStackTrace() e.printStackTrace e {
			String[] param = in.readLine().split(" ");
			int lim = Integer.parseInt(param[0]);
			int time = Integer.parseInt(param[1]);
			
			for (int i = 0; i < lim; i++) {
				param = in.readLine().split(" ");
				
				Task t = new Task(Integer.parseInt(param[1]), param[0]);
				q.add(t);
			}
			
			int past = 0;
			while (q.isEmpty() == false) {
				Task tmp = q.remove();
				boolean flag = tmp.minusTime(time);
				
				if (flag == true) {
					past = past + tmp.getTIme() + time;
					ans.add(new Task(past, tmp.getName()));
				} else {
					past = past + time;
					q.add(tmp);
				}
			}
			
			while (ans.isEmpty() == false) {
				Task tmp = ans.remove();
				System.out.println(tmp.getName() + " " + tmp.getTIme());
			}
		} String[] param = in.readLine().split(" "); param in.readLine().split(" ") in.readLine().split in.readLine() in.readLine in " " int lim = Integer.parseInt(param[0]); lim Integer.parseInt(param[0]) Integer.parseInt Integer param[0] param 0 int time = Integer.parseInt(param[1]); time Integer.parseInt(param[1]) Integer.parseInt Integer param[1] param 1 for (int i = 0; i < lim; i++) {
				param = in.readLine().split(" ");
				
				Task t = new Task(Integer.parseInt(param[1]), param[0]);
				q.add(t);
			} int i = 0; int i = 0; i 0 i < lim i lim i++ i++ i {
				param = in.readLine().split(" ");
				
				Task t = new Task(Integer.parseInt(param[1]), param[0]);
				q.add(t);
			} {
				param = in.readLine().split(" ");
				
				Task t = new Task(Integer.parseInt(param[1]), param[0]);
				q.add(t);
			} param = in.readLine().split(" ") param in.readLine().split(" ") in.readLine().split in.readLine() in.readLine in " " Task t = new Task(Integer.parseInt(param[1]), param[0]); t new Task(Integer.parseInt(param[1]), param[0]) q.add(t) q.add q t int past = 0; past 0 while (q.isEmpty() == false) {
				Task tmp = q.remove();
				boolean flag = tmp.minusTime(time);
				
				if (flag == true) {
					past = past + tmp.getTIme() + time;
					ans.add(new Task(past, tmp.getName()));
				} else {
					past = past + time;
					q.add(tmp);
				}
			} q.isEmpty() == false q.isEmpty() q.isEmpty q false {
				Task tmp = q.remove();
				boolean flag = tmp.minusTime(time);
				
				if (flag == true) {
					past = past + tmp.getTIme() + time;
					ans.add(new Task(past, tmp.getName()));
				} else {
					past = past + time;
					q.add(tmp);
				}
			} Task tmp = q.remove(); tmp q.remove() q.remove q boolean flag = tmp.minusTime(time); flag tmp.minusTime(time) tmp.minusTime tmp time if (flag == true) {
					past = past + tmp.getTIme() + time;
					ans.add(new Task(past, tmp.getName()));
				} else {
					past = past + time;
					q.add(tmp);
				} flag == true flag true {
					past = past + tmp.getTIme() + time;
					ans.add(new Task(past, tmp.getName()));
				} past = past + tmp.getTIme() + time past past + tmp.getTIme() + time past + tmp.getTIme() + time past tmp.getTIme() tmp.getTIme tmp time ans.add(new Task(past, tmp.getName())) ans.add ans new Task(past, tmp.getName()) {
					past = past + time;
					q.add(tmp);
				} past = past + time past past + time past time q.add(tmp) q.add q tmp while (ans.isEmpty() == false) {
				Task tmp = ans.remove();
				System.out.println(tmp.getName() + " " + tmp.getTIme());
			} ans.isEmpty() == false ans.isEmpty() ans.isEmpty ans false {
				Task tmp = ans.remove();
				System.out.println(tmp.getName() + " " + tmp.getTIme());
			} Task tmp = ans.remove(); tmp ans.remove() ans.remove ans System.out.println(tmp.getName() + " " + tmp.getTIme()) System.out.println System.out System System.out tmp.getName() + " " + tmp.getTIme() tmp.getName() + " " + tmp.getTIme() tmp.getName() tmp.getName tmp " " tmp.getTIme() tmp.getTIme tmp String[] args args class Task {
	private int time;
	private String name;
	
	public Task(int t, String n) {
		time = t;
		name = n;
	}
	
	public int getTIme() {
		return time;
	}
	
	public String getName() {
		return name;
	}
	
	public boolean minusTime(int t) {
		time = time - t;
		if (time <= 0) return true;
		return false;
	}
} Task private int time; time private String name; name public Task(int t, String n) {
		time = t;
		name = n;
	} Task {
		time = t;
		name = n;
	} time = t time t name = n name n int t t String n n public int getTIme() {
		return time;
	} getTIme {
		return time;
	} return time; time public String getName() {
		return name;
	} getName {
		return name;
	} return name; name public boolean minusTime(int t) {
		time = time - t;
		if (time <= 0) return true;
		return false;
	} minusTime {
		time = time - t;
		if (time <= 0) return true;
		return false;
	} time = time - t time time - t time t if (time <= 0) return true; time <= 0 time 0 return true; true return false; false int t t public class Main {
	public static void main(String[] args) {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		ArrayDeque<Task> q = new ArrayDeque<Task>();
		ArrayDeque<Task> ans = new ArrayDeque<Task>();
		
		try {
			String[] param = in.readLine().split(" ");
			int lim = Integer.parseInt(param[0]);
			int time = Integer.parseInt(param[1]);
			
			for (int i = 0; i < lim; i++) {
				param = in.readLine().split(" ");
				
				Task t = new Task(Integer.parseInt(param[1]), param[0]);
				q.add(t);
			}
			
			int past = 0;
			while (q.isEmpty() == false) {
				Task tmp = q.remove();
				boolean flag = tmp.minusTime(time);
				
				if (flag == true) {
					past = past + tmp.getTIme() + time;
					ans.add(new Task(past, tmp.getName()));
				} else {
					past = past + time;
					q.add(tmp);
				}
			}
			
			while (ans.isEmpty() == false) {
				Task tmp = ans.remove();
				System.out.println(tmp.getName() + " " + tmp.getTIme());
			}
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
} public class Main {
	public static void main(String[] args) {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		ArrayDeque<Task> q = new ArrayDeque<Task>();
		ArrayDeque<Task> ans = new ArrayDeque<Task>();
		
		try {
			String[] param = in.readLine().split(" ");
			int lim = Integer.parseInt(param[0]);
			int time = Integer.parseInt(param[1]);
			
			for (int i = 0; i < lim; i++) {
				param = in.readLine().split(" ");
				
				Task t = new Task(Integer.parseInt(param[1]), param[0]);
				q.add(t);
			}
			
			int past = 0;
			while (q.isEmpty() == false) {
				Task tmp = q.remove();
				boolean flag = tmp.minusTime(time);
				
				if (flag == true) {
					past = past + tmp.getTIme() + time;
					ans.add(new Task(past, tmp.getName()));
				} else {
					past = past + time;
					q.add(tmp);
				}
			}
			
			while (ans.isEmpty() == false) {
				Task tmp = ans.remove();
				System.out.println(tmp.getName() + " " + tmp.getTIme());
			}
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;

public class Main {
	public static void main(String[] args) {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		ArrayDeque<Task> q = new ArrayDeque<Task>();
		ArrayDeque<Task> ans = new ArrayDeque<Task>();
		
		try {
			String[] param = in.readLine().split(" ");
			int lim = Integer.parseInt(param[0]);
			int time = Integer.parseInt(param[1]);
			
			for (int i = 0; i < lim; i++) {
				param = in.readLine().split(" ");
				
				Task t = new Task(Integer.parseInt(param[1]), param[0]);
				q.add(t);
			}
			
			int past = 0;
			while (q.isEmpty() == false) {
				Task tmp = q.remove();
				boolean flag = tmp.minusTime(time);
				
				if (flag == true) {
					past = past + tmp.getTIme() + time;
					ans.add(new Task(past, tmp.getName()));
				} else {
					past = past + time;
					q.add(tmp);
				}
			}
			
			while (ans.isEmpty() == false) {
				Task tmp = ans.remove();
				System.out.println(tmp.getName() + " " + tmp.getTIme());
			}
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}

class Task {
	private int time;
	private String name;
	
	public Task(int t, String n) {
		time = t;
		name = n;
	}
	
	public int getTIme() {
		return time;
	}
	
	public String getName() {
		return name;
	}
	
	public boolean minusTime(int t) {
		time = time - t;
		if (time <= 0) return true;
		return false;
	}
}