import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.InputMismatchException;
import java.util.StringTokenizer;

class Main {
	
	static class Queue {
		public void queue (InputReader ir) {
			
			// プロセス数
			int n = ir.nextInt();
			
			// クオンタム
			int q = ir.nextInt();
			
			// プロセス情報
			Deque<String> process = new ArrayDeque<String>();
			Deque<Integer> quantum = new ArrayDeque<Integer>();
			for (int i = 0; i < n; i++) {
				process.add(ir.nextString());
				quantum.add(ir.nextInt());
			}
			
			int time = 0;
			StringBuilder sb = new StringBuilder();
			
			while (!quantum.isEmpty()) {
				String posname = process.poll();
				int postime = quantum.poll();
				
				if ( postime <= q) {
					time += postime;
					sb.append(posname).append(" ").append(Integer.toString(time)).append("\n");
				} else {
					postime -= q;
					time += q;
					process.add(posname);
					quantum.add(postime);
				}
			}
			System.out.print(sb);
		}
	}
	
	static class InputReader {
		BufferedReader br;
		StringTokenizer st;
		
		public String nextString() {
			
			 while (!st.hasMoreTokens()) {
	                try {
	                    st = new StringTokenizer(br.readLine(), " ");
	                } catch (IOException e) {
	                    throw new InputMismatchException();
	                }
	            }
			return st.nextToken();
		}
		
		public int nextInt() {
			return Integer.parseInt(nextString());
		}
					
		public InputReader (InputStream inputStream) {
			br = new BufferedReader (new InputStreamReader (inputStream));
			st = new StringTokenizer ("");
		}
		
	}
	
	public static void main (String[] args) {
		InputStream inputStream = System.in;
		InputReader ir = new InputReader (inputStream);
		Queue obj = new Queue();
		obj.queue(ir);
	}
}
 import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStream; InputStream java.io import java.io.InputStreamReader; InputStreamReader java.io import java.util.ArrayDeque; ArrayDeque java.util import java.util.Deque; Deque java.util import java.util.InputMismatchException; InputMismatchException java.util import java.util.StringTokenizer; StringTokenizer java.util class Main {
	
	static class Queue {
		public void queue (InputReader ir) {
			
			// プロセス数
			int n = ir.nextInt();
			
			// クオンタム
			int q = ir.nextInt();
			
			// プロセス情報
			Deque<String> process = new ArrayDeque<String>();
			Deque<Integer> quantum = new ArrayDeque<Integer>();
			for (int i = 0; i < n; i++) {
				process.add(ir.nextString());
				quantum.add(ir.nextInt());
			}
			
			int time = 0;
			StringBuilder sb = new StringBuilder();
			
			while (!quantum.isEmpty()) {
				String posname = process.poll();
				int postime = quantum.poll();
				
				if ( postime <= q) {
					time += postime;
					sb.append(posname).append(" ").append(Integer.toString(time)).append("\n");
				} else {
					postime -= q;
					time += q;
					process.add(posname);
					quantum.add(postime);
				}
			}
			System.out.print(sb);
		}
	}
	
	static class InputReader {
		BufferedReader br;
		StringTokenizer st;
		
		public String nextString() {
			
			 while (!st.hasMoreTokens()) {
	                try {
	                    st = new StringTokenizer(br.readLine(), " ");
	                } catch (IOException e) {
	                    throw new InputMismatchException();
	                }
	            }
			return st.nextToken();
		}
		
		public int nextInt() {
			return Integer.parseInt(nextString());
		}
					
		public InputReader (InputStream inputStream) {
			br = new BufferedReader (new InputStreamReader (inputStream));
			st = new StringTokenizer ("");
		}
		
	}
	
	public static void main (String[] args) {
		InputStream inputStream = System.in;
		InputReader ir = new InputReader (inputStream);
		Queue obj = new Queue();
		obj.queue(ir);
	}
} Main public static void main (String[] args) {
		InputStream inputStream = System.in;
		InputReader ir = new InputReader (inputStream);
		Queue obj = new Queue();
		obj.queue(ir);
	} main {
		InputStream inputStream = System.in;
		InputReader ir = new InputReader (inputStream);
		Queue obj = new Queue();
		obj.queue(ir);
	} InputStream inputStream = System.in; inputStream System.in System System.in InputReader ir = new InputReader (inputStream); ir new InputReader (inputStream) Queue obj = new Queue(); obj new Queue() obj.queue(ir) obj.queue obj ir String[] args args static class Queue {
		public void queue (InputReader ir) {
			
			// プロセス数
			int n = ir.nextInt();
			
			// クオンタム
			int q = ir.nextInt();
			
			// プロセス情報
			Deque<String> process = new ArrayDeque<String>();
			Deque<Integer> quantum = new ArrayDeque<Integer>();
			for (int i = 0; i < n; i++) {
				process.add(ir.nextString());
				quantum.add(ir.nextInt());
			}
			
			int time = 0;
			StringBuilder sb = new StringBuilder();
			
			while (!quantum.isEmpty()) {
				String posname = process.poll();
				int postime = quantum.poll();
				
				if ( postime <= q) {
					time += postime;
					sb.append(posname).append(" ").append(Integer.toString(time)).append("\n");
				} else {
					postime -= q;
					time += q;
					process.add(posname);
					quantum.add(postime);
				}
			}
			System.out.print(sb);
		}
	} Queue public void queue (InputReader ir) {
			
			// プロセス数
			int n = ir.nextInt();
			
			// クオンタム
			int q = ir.nextInt();
			
			// プロセス情報
			Deque<String> process = new ArrayDeque<String>();
			Deque<Integer> quantum = new ArrayDeque<Integer>();
			for (int i = 0; i < n; i++) {
				process.add(ir.nextString());
				quantum.add(ir.nextInt());
			}
			
			int time = 0;
			StringBuilder sb = new StringBuilder();
			
			while (!quantum.isEmpty()) {
				String posname = process.poll();
				int postime = quantum.poll();
				
				if ( postime <= q) {
					time += postime;
					sb.append(posname).append(" ").append(Integer.toString(time)).append("\n");
				} else {
					postime -= q;
					time += q;
					process.add(posname);
					quantum.add(postime);
				}
			}
			System.out.print(sb);
		} queue {
			
			// プロセス数
			int n = ir.nextInt();
			
			// クオンタム
			int q = ir.nextInt();
			
			// プロセス情報
			Deque<String> process = new ArrayDeque<String>();
			Deque<Integer> quantum = new ArrayDeque<Integer>();
			for (int i = 0; i < n; i++) {
				process.add(ir.nextString());
				quantum.add(ir.nextInt());
			}
			
			int time = 0;
			StringBuilder sb = new StringBuilder();
			
			while (!quantum.isEmpty()) {
				String posname = process.poll();
				int postime = quantum.poll();
				
				if ( postime <= q) {
					time += postime;
					sb.append(posname).append(" ").append(Integer.toString(time)).append("\n");
				} else {
					postime -= q;
					time += q;
					process.add(posname);
					quantum.add(postime);
				}
			}
			System.out.print(sb);
		} int n = ir.nextInt(); n ir.nextInt() ir.nextInt ir int q = ir.nextInt(); q ir.nextInt() ir.nextInt ir Deque<String> process = new ArrayDeque<String>(); process new ArrayDeque<String>() Deque<Integer> quantum = new ArrayDeque<Integer>(); quantum new ArrayDeque<Integer>() for (int i = 0; i < n; i++) {
				process.add(ir.nextString());
				quantum.add(ir.nextInt());
			} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
				process.add(ir.nextString());
				quantum.add(ir.nextInt());
			} {
				process.add(ir.nextString());
				quantum.add(ir.nextInt());
			} process.add(ir.nextString()) process.add process ir.nextString() ir.nextString ir quantum.add(ir.nextInt()) quantum.add quantum ir.nextInt() ir.nextInt ir int time = 0; time 0 StringBuilder sb = new StringBuilder(); sb new StringBuilder() while (!quantum.isEmpty()) {
				String posname = process.poll();
				int postime = quantum.poll();
				
				if ( postime <= q) {
					time += postime;
					sb.append(posname).append(" ").append(Integer.toString(time)).append("\n");
				} else {
					postime -= q;
					time += q;
					process.add(posname);
					quantum.add(postime);
				}
			} !quantum.isEmpty() quantum.isEmpty() quantum.isEmpty quantum {
				String posname = process.poll();
				int postime = quantum.poll();
				
				if ( postime <= q) {
					time += postime;
					sb.append(posname).append(" ").append(Integer.toString(time)).append("\n");
				} else {
					postime -= q;
					time += q;
					process.add(posname);
					quantum.add(postime);
				}
			} String posname = process.poll(); posname process.poll() process.poll process int postime = quantum.poll(); postime quantum.poll() quantum.poll quantum if ( postime <= q) {
					time += postime;
					sb.append(posname).append(" ").append(Integer.toString(time)).append("\n");
				} else {
					postime -= q;
					time += q;
					process.add(posname);
					quantum.add(postime);
				} postime <= q postime q {
					time += postime;
					sb.append(posname).append(" ").append(Integer.toString(time)).append("\n");
				} time += postime time postime sb.append(posname).append(" ").append(Integer.toString(time)).append("\n") sb.append(posname).append(" ").append(Integer.toString(time)).append sb.append(posname).append(" ").append(Integer.toString(time)) sb.append(posname).append(" ").append sb.append(posname).append(" ") sb.append(posname).append sb.append(posname) sb.append sb posname " " Integer.toString(time) Integer.toString Integer time "\n" {
					postime -= q;
					time += q;
					process.add(posname);
					quantum.add(postime);
				} postime -= q postime q time += q time q process.add(posname) process.add process posname quantum.add(postime) quantum.add quantum postime System.out.print(sb) System.out.print System.out System System.out sb InputReader ir ir static class InputReader {
		BufferedReader br;
		StringTokenizer st;
		
		public String nextString() {
			
			 while (!st.hasMoreTokens()) {
	                try {
	                    st = new StringTokenizer(br.readLine(), " ");
	                } catch (IOException e) {
	                    throw new InputMismatchException();
	                }
	            }
			return st.nextToken();
		}
		
		public int nextInt() {
			return Integer.parseInt(nextString());
		}
					
		public InputReader (InputStream inputStream) {
			br = new BufferedReader (new InputStreamReader (inputStream));
			st = new StringTokenizer ("");
		}
		
	} InputReader BufferedReader br; br StringTokenizer st; st public String nextString() {
			
			 while (!st.hasMoreTokens()) {
	                try {
	                    st = new StringTokenizer(br.readLine(), " ");
	                } catch (IOException e) {
	                    throw new InputMismatchException();
	                }
	            }
			return st.nextToken();
		} nextString {
			
			 while (!st.hasMoreTokens()) {
	                try {
	                    st = new StringTokenizer(br.readLine(), " ");
	                } catch (IOException e) {
	                    throw new InputMismatchException();
	                }
	            }
			return st.nextToken();
		} while (!st.hasMoreTokens()) {
	                try {
	                    st = new StringTokenizer(br.readLine(), " ");
	                } catch (IOException e) {
	                    throw new InputMismatchException();
	                }
	            } !st.hasMoreTokens() st.hasMoreTokens() st.hasMoreTokens st {
	                try {
	                    st = new StringTokenizer(br.readLine(), " ");
	                } catch (IOException e) {
	                    throw new InputMismatchException();
	                }
	            } try {
	                    st = new StringTokenizer(br.readLine(), " ");
	                } catch (IOException e) {
	                    throw new InputMismatchException();
	                } catch (IOException e) {
	                    throw new InputMismatchException();
	                } IOException e {
	                    throw new InputMismatchException();
	                } throw new InputMismatchException(); new InputMismatchException() {
	                    st = new StringTokenizer(br.readLine(), " ");
	                } st = new StringTokenizer(br.readLine(), " ") st new StringTokenizer(br.readLine(), " ") return st.nextToken(); st.nextToken() st.nextToken st public int nextInt() {
			return Integer.parseInt(nextString());
		} nextInt {
			return Integer.parseInt(nextString());
		} return Integer.parseInt(nextString()); Integer.parseInt(nextString()) Integer.parseInt Integer nextString() nextString public InputReader (InputStream inputStream) {
			br = new BufferedReader (new InputStreamReader (inputStream));
			st = new StringTokenizer ("");
		} InputReader {
			br = new BufferedReader (new InputStreamReader (inputStream));
			st = new StringTokenizer ("");
		} br = new BufferedReader (new InputStreamReader (inputStream)) br new BufferedReader (new InputStreamReader (inputStream)) st = new StringTokenizer ("") st new StringTokenizer ("") InputStream inputStream inputStream
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.InputMismatchException;
import java.util.StringTokenizer;

class Main {
	
	static class Queue {
		public void queue (InputReader ir) {
			
			// プロセス数
			int n = ir.nextInt();
			
			// クオンタム
			int q = ir.nextInt();
			
			// プロセス情報
			Deque<String> process = new ArrayDeque<String>();
			Deque<Integer> quantum = new ArrayDeque<Integer>();
			for (int i = 0; i < n; i++) {
				process.add(ir.nextString());
				quantum.add(ir.nextInt());
			}
			
			int time = 0;
			StringBuilder sb = new StringBuilder();
			
			while (!quantum.isEmpty()) {
				String posname = process.poll();
				int postime = quantum.poll();
				
				if ( postime <= q) {
					time += postime;
					sb.append(posname).append(" ").append(Integer.toString(time)).append("\n");
				} else {
					postime -= q;
					time += q;
					process.add(posname);
					quantum.add(postime);
				}
			}
			System.out.print(sb);
		}
	}
	
	static class InputReader {
		BufferedReader br;
		StringTokenizer st;
		
		public String nextString() {
			
			 while (!st.hasMoreTokens()) {
	                try {
	                    st = new StringTokenizer(br.readLine(), " ");
	                } catch (IOException e) {
	                    throw new InputMismatchException();
	                }
	            }
			return st.nextToken();
		}
		
		public int nextInt() {
			return Integer.parseInt(nextString());
		}
					
		public InputReader (InputStream inputStream) {
			br = new BufferedReader (new InputStreamReader (inputStream));
			st = new StringTokenizer ("");
		}
		
	}
	
	public static void main (String[] args) {
		InputStream inputStream = System.in;
		InputReader ir = new InputReader (inputStream);
		Queue obj = new Queue();
		obj.queue(ir);
	}
}

