import java.util.*;
import java.io.*;
import java.math.*;

public class Main {

	void solve (FastScanner in, PrintWriter out, Methods ms) {

		int n = in.nextInt(), q = in.nextInt();
		ArrayDeque<Process> dq = new ArrayDeque<>();
		for (int i=0; i<n; i++) dq.addLast(new Process(in.next(), in.nextInt()));
		
		int time = 0;
		while (dq.size() > 0) {
			
			if (dq.getFirst().time <= q) {
				time += dq.getFirst().time;
				out.println(dq.getFirst().name+" "+time);
				dq.removeFirst();
			}
			else {
				time += q;
				dq.getFirst().decTime(q);
				dq.addLast(dq.removeFirst());
			}
			
		}

	}
	
	static class Process {
		String name;
		int time;
		Process (String s, int n) {
			name = s; time = n;
		}
		void decTime (int n) {
			time -= n;
		}
	}



	public static void main(String[] args) {
		Main main = new Main();
		FastScanner in = new FastScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		Methods ms = new Methods();
		main.solve(in, out, ms);
		in.close();
		out.close();
	}

	static class Methods {

		public void print (Object... ar) {System.out.println(Arrays.deepToString(ar));}

		public void yesno (PrintWriter out, boolean b) {out.println(b?"Yes":"No");}

		public void YESNO (PrintWriter out, boolean b) {out.println(b?"YES":"NO");}

		public int max (int... ar) {Arrays.sort(ar); return ar[ar.length-1];}

		public int min (int... ar) {Arrays.sort(ar); return ar[0];}

		public long gcd (long a, long b) {return b>0?gcd(b,a%b):a;}

		public long lcm (long a, long b) {return a/gcd(a,b)*b;}

	}

	static class FastScanner {

		private InputStream in;
		private byte[] buffer = new byte[1024];
		private  int length = 0, p = 0;

		public FastScanner (InputStream stream) {
			in = stream;
		}

		public boolean hasNextByte () {
			if (p < length) return true;
			else {
				p = 0;
				try {length = in.read(buffer);}
				catch (Exception e) {e.printStackTrace();}
				if (length <= 0) return false;
			}
			return true;
		}

		public int readByte () {
			if (hasNextByte() == true) return buffer[p++];
			return -1;
		}

		public boolean isPrintable (int n) {return 33<=n&&n<=126;}

		public void skip () {
			while (hasNextByte() && !isPrintable(buffer[p])) p++;
		}

		public boolean hasNext () {skip(); return hasNextByte();}

		public String next () {
			if (!hasNext()) throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int t = readByte();
			while (isPrintable(t)) {
				sb.appendCodePoint(t);
				t = readByte();
			}
			return sb.toString();
		}

		public String[] nextArray (int n) {
			String[] ar = new String[n];
			for (int i=0; i<n; i++) ar[i] = next();
			return ar;
		}

		public int nextInt () {return Math.toIntExact(nextLong());}

		public int[] nextIntArray (int n) {
			int[] ar = new int[n];
			for (int i=0; i<n; i++) ar[i] = nextInt();
			return ar;
		}

		public long nextLong () {
			if (!hasNext()) throw new NoSuchElementException();
			boolean minus = false;
			int temp = readByte();
			if (temp == '-') {
				minus = true;
				temp = readByte();
			}
			if (temp<'0' || '9'<temp) throw new NumberFormatException();
			long n = 0;
			while (isPrintable(temp)) {
				if ('0'<=temp && temp<='9') {
					n *= 10;
					n += temp - '0';
				}
				else throw new NumberFormatException();
				temp = readByte();
			}
			return minus? -n : n;
		}

		public long[] nextLongArray (int n) {
			long[] ar = new long[n];
			for (int i=0; i<n; i++) ar[i] = nextLong();
			return ar;
		}

		public double nextDouble () {
			return Double.parseDouble(next());
		}

		public double[] nextDoubleArray (int n) {
			double[] ar = new double[n];
			for (int i=0; i<n; i++) ar[i] = nextDouble();
			return ar;
		}

		public void close () {
			try {in.close();}
			catch(Exception e){}
		}

	}

} import java.util.*; util.* java import java.io.*; io.* java import java.math.*; math.* java public class Main {

	void solve (FastScanner in, PrintWriter out, Methods ms) {

		int n = in.nextInt(), q = in.nextInt();
		ArrayDeque<Process> dq = new ArrayDeque<>();
		for (int i=0; i<n; i++) dq.addLast(new Process(in.next(), in.nextInt()));
		
		int time = 0;
		while (dq.size() > 0) {
			
			if (dq.getFirst().time <= q) {
				time += dq.getFirst().time;
				out.println(dq.getFirst().name+" "+time);
				dq.removeFirst();
			}
			else {
				time += q;
				dq.getFirst().decTime(q);
				dq.addLast(dq.removeFirst());
			}
			
		}

	}
	
	static class Process {
		String name;
		int time;
		Process (String s, int n) {
			name = s; time = n;
		}
		void decTime (int n) {
			time -= n;
		}
	}



	public static void main(String[] args) {
		Main main = new Main();
		FastScanner in = new FastScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		Methods ms = new Methods();
		main.solve(in, out, ms);
		in.close();
		out.close();
	}

	static class Methods {

		public void print (Object... ar) {System.out.println(Arrays.deepToString(ar));}

		public void yesno (PrintWriter out, boolean b) {out.println(b?"Yes":"No");}

		public void YESNO (PrintWriter out, boolean b) {out.println(b?"YES":"NO");}

		public int max (int... ar) {Arrays.sort(ar); return ar[ar.length-1];}

		public int min (int... ar) {Arrays.sort(ar); return ar[0];}

		public long gcd (long a, long b) {return b>0?gcd(b,a%b):a;}

		public long lcm (long a, long b) {return a/gcd(a,b)*b;}

	}

	static class FastScanner {

		private InputStream in;
		private byte[] buffer = new byte[1024];
		private  int length = 0, p = 0;

		public FastScanner (InputStream stream) {
			in = stream;
		}

		public boolean hasNextByte () {
			if (p < length) return true;
			else {
				p = 0;
				try {length = in.read(buffer);}
				catch (Exception e) {e.printStackTrace();}
				if (length <= 0) return false;
			}
			return true;
		}

		public int readByte () {
			if (hasNextByte() == true) return buffer[p++];
			return -1;
		}

		public boolean isPrintable (int n) {return 33<=n&&n<=126;}

		public void skip () {
			while (hasNextByte() && !isPrintable(buffer[p])) p++;
		}

		public boolean hasNext () {skip(); return hasNextByte();}

		public String next () {
			if (!hasNext()) throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int t = readByte();
			while (isPrintable(t)) {
				sb.appendCodePoint(t);
				t = readByte();
			}
			return sb.toString();
		}

		public String[] nextArray (int n) {
			String[] ar = new String[n];
			for (int i=0; i<n; i++) ar[i] = next();
			return ar;
		}

		public int nextInt () {return Math.toIntExact(nextLong());}

		public int[] nextIntArray (int n) {
			int[] ar = new int[n];
			for (int i=0; i<n; i++) ar[i] = nextInt();
			return ar;
		}

		public long nextLong () {
			if (!hasNext()) throw new NoSuchElementException();
			boolean minus = false;
			int temp = readByte();
			if (temp == '-') {
				minus = true;
				temp = readByte();
			}
			if (temp<'0' || '9'<temp) throw new NumberFormatException();
			long n = 0;
			while (isPrintable(temp)) {
				if ('0'<=temp && temp<='9') {
					n *= 10;
					n += temp - '0';
				}
				else throw new NumberFormatException();
				temp = readByte();
			}
			return minus? -n : n;
		}

		public long[] nextLongArray (int n) {
			long[] ar = new long[n];
			for (int i=0; i<n; i++) ar[i] = nextLong();
			return ar;
		}

		public double nextDouble () {
			return Double.parseDouble(next());
		}

		public double[] nextDoubleArray (int n) {
			double[] ar = new double[n];
			for (int i=0; i<n; i++) ar[i] = nextDouble();
			return ar;
		}

		public void close () {
			try {in.close();}
			catch(Exception e){}
		}

	}

} Main void solve (FastScanner in, PrintWriter out, Methods ms) {

		int n = in.nextInt(), q = in.nextInt();
		ArrayDeque<Process> dq = new ArrayDeque<>();
		for (int i=0; i<n; i++) dq.addLast(new Process(in.next(), in.nextInt()));
		
		int time = 0;
		while (dq.size() > 0) {
			
			if (dq.getFirst().time <= q) {
				time += dq.getFirst().time;
				out.println(dq.getFirst().name+" "+time);
				dq.removeFirst();
			}
			else {
				time += q;
				dq.getFirst().decTime(q);
				dq.addLast(dq.removeFirst());
			}
			
		}

	} solve {

		int n = in.nextInt(), q = in.nextInt();
		ArrayDeque<Process> dq = new ArrayDeque<>();
		for (int i=0; i<n; i++) dq.addLast(new Process(in.next(), in.nextInt()));
		
		int time = 0;
		while (dq.size() > 0) {
			
			if (dq.getFirst().time <= q) {
				time += dq.getFirst().time;
				out.println(dq.getFirst().name+" "+time);
				dq.removeFirst();
			}
			else {
				time += q;
				dq.getFirst().decTime(q);
				dq.addLast(dq.removeFirst());
			}
			
		}

	} int n = in.nextInt() n in.nextInt() in.nextInt in q = in.nextInt(); q in.nextInt() in.nextInt in ArrayDeque<Process> dq = new ArrayDeque<>(); dq new ArrayDeque<>() for (int i=0; i<n; i++) dq.addLast(new Process(in.next(), in.nextInt())); int i=0; int i=0; i 0 i<n i n i++ i++ i dq.addLast(new Process(in.next(), in.nextInt())); dq.addLast(new Process(in.next(), in.nextInt())) dq.addLast dq new Process(in.next(), in.nextInt()) int time = 0; time 0 while (dq.size() > 0) {
			
			if (dq.getFirst().time <= q) {
				time += dq.getFirst().time;
				out.println(dq.getFirst().name+" "+time);
				dq.removeFirst();
			}
			else {
				time += q;
				dq.getFirst().decTime(q);
				dq.addLast(dq.removeFirst());
			}
			
		} dq.size() > 0 dq.size() dq.size dq 0 {
			
			if (dq.getFirst().time <= q) {
				time += dq.getFirst().time;
				out.println(dq.getFirst().name+" "+time);
				dq.removeFirst();
			}
			else {
				time += q;
				dq.getFirst().decTime(q);
				dq.addLast(dq.removeFirst());
			}
			
		} if (dq.getFirst().time <= q) {
				time += dq.getFirst().time;
				out.println(dq.getFirst().name+" "+time);
				dq.removeFirst();
			}
			else {
				time += q;
				dq.getFirst().decTime(q);
				dq.addLast(dq.removeFirst());
			} dq.getFirst().time <= q dq.getFirst().time dq.getFirst() dq.getFirst dq dq.getFirst().time q {
				time += dq.getFirst().time;
				out.println(dq.getFirst().name+" "+time);
				dq.removeFirst();
			} time += dq.getFirst().time time dq.getFirst().time dq.getFirst() dq.getFirst dq dq.getFirst().time out.println(dq.getFirst().name+" "+time) out.println out dq.getFirst().name+" "+time dq.getFirst().name+" "+time dq.getFirst().name dq.getFirst() dq.getFirst dq dq.getFirst().name " " time dq.removeFirst() dq.removeFirst dq {
				time += q;
				dq.getFirst().decTime(q);
				dq.addLast(dq.removeFirst());
			} time += q time q dq.getFirst().decTime(q) dq.getFirst().decTime dq.getFirst() dq.getFirst dq q dq.addLast(dq.removeFirst()) dq.addLast dq dq.removeFirst() dq.removeFirst dq FastScanner in in PrintWriter out out Methods ms ms public static void main(String[] args) {
		Main main = new Main();
		FastScanner in = new FastScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		Methods ms = new Methods();
		main.solve(in, out, ms);
		in.close();
		out.close();
	} main {
		Main main = new Main();
		FastScanner in = new FastScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		Methods ms = new Methods();
		main.solve(in, out, ms);
		in.close();
		out.close();
	} Main main = new Main(); main new Main() FastScanner in = new FastScanner(System.in); in new FastScanner(System.in) PrintWriter out = new PrintWriter(System.out); out new PrintWriter(System.out) Methods ms = new Methods(); ms new Methods() main.solve(in, out, ms) main.solve main in out ms in.close() in.close in out.close() out.close out String[] args args static class Process {
		String name;
		int time;
		Process (String s, int n) {
			name = s; time = n;
		}
		void decTime (int n) {
			time -= n;
		}
	} Process String name; name int time; time Process (String s, int n) {
			name = s; time = n;
		} Process {
			name = s; time = n;
		} name = s name s time = n time n String s s int n n void decTime (int n) {
			time -= n;
		} decTime {
			time -= n;
		} time -= n time n int n n static class Methods {

		public void print (Object... ar) {System.out.println(Arrays.deepToString(ar));}

		public void yesno (PrintWriter out, boolean b) {out.println(b?"Yes":"No");}

		public void YESNO (PrintWriter out, boolean b) {out.println(b?"YES":"NO");}

		public int max (int... ar) {Arrays.sort(ar); return ar[ar.length-1];}

		public int min (int... ar) {Arrays.sort(ar); return ar[0];}

		public long gcd (long a, long b) {return b>0?gcd(b,a%b):a;}

		public long lcm (long a, long b) {return a/gcd(a,b)*b;}

	} Methods public void print (Object... ar) {System.out.println(Arrays.deepToString(ar));} print {System.out.println(Arrays.deepToString(ar));} System.out.println(Arrays.deepToString(ar)) System.out.println System.out System System.out Arrays.deepToString(ar) Arrays.deepToString Arrays ar Object... ar ar public void yesno (PrintWriter out, boolean b) {out.println(b?"Yes":"No");} yesno {out.println(b?"Yes":"No");} out.println(b?"Yes":"No") out.println out b?"Yes":"No" b "Yes" "No" PrintWriter out out boolean b b public void YESNO (PrintWriter out, boolean b) {out.println(b?"YES":"NO");} YESNO {out.println(b?"YES":"NO");} out.println(b?"YES":"NO") out.println out b?"YES":"NO" b "YES" "NO" PrintWriter out out boolean b b public int max (int... ar) {Arrays.sort(ar); return ar[ar.length-1];} max {Arrays.sort(ar); return ar[ar.length-1];} Arrays.sort(ar) Arrays.sort Arrays ar return ar[ar.length-1]; ar[ar.length-1] ar ar.length-1 ar.length ar ar.length 1 int... ar ar public int min (int... ar) {Arrays.sort(ar); return ar[0];} min {Arrays.sort(ar); return ar[0];} Arrays.sort(ar) Arrays.sort Arrays ar return ar[0]; ar[0] ar 0 int... ar ar public long gcd (long a, long b) {return b>0?gcd(b,a%b):a;} gcd {return b>0?gcd(b,a%b):a;} return b>0?gcd(b,a%b):a; b>0?gcd(b,a%b):a b>0 b 0 gcd(b,a%b) gcd b a%b a b a long a a long b b public long lcm (long a, long b) {return a/gcd(a,b)*b;} lcm {return a/gcd(a,b)*b;} return a/gcd(a,b)*b; a/gcd(a,b)*b a/gcd(a,b) a gcd(a,b) gcd a b b long a a long b b static class FastScanner {

		private InputStream in;
		private byte[] buffer = new byte[1024];
		private  int length = 0, p = 0;

		public FastScanner (InputStream stream) {
			in = stream;
		}

		public boolean hasNextByte () {
			if (p < length) return true;
			else {
				p = 0;
				try {length = in.read(buffer);}
				catch (Exception e) {e.printStackTrace();}
				if (length <= 0) return false;
			}
			return true;
		}

		public int readByte () {
			if (hasNextByte() == true) return buffer[p++];
			return -1;
		}

		public boolean isPrintable (int n) {return 33<=n&&n<=126;}

		public void skip () {
			while (hasNextByte() && !isPrintable(buffer[p])) p++;
		}

		public boolean hasNext () {skip(); return hasNextByte();}

		public String next () {
			if (!hasNext()) throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int t = readByte();
			while (isPrintable(t)) {
				sb.appendCodePoint(t);
				t = readByte();
			}
			return sb.toString();
		}

		public String[] nextArray (int n) {
			String[] ar = new String[n];
			for (int i=0; i<n; i++) ar[i] = next();
			return ar;
		}

		public int nextInt () {return Math.toIntExact(nextLong());}

		public int[] nextIntArray (int n) {
			int[] ar = new int[n];
			for (int i=0; i<n; i++) ar[i] = nextInt();
			return ar;
		}

		public long nextLong () {
			if (!hasNext()) throw new NoSuchElementException();
			boolean minus = false;
			int temp = readByte();
			if (temp == '-') {
				minus = true;
				temp = readByte();
			}
			if (temp<'0' || '9'<temp) throw new NumberFormatException();
			long n = 0;
			while (isPrintable(temp)) {
				if ('0'<=temp && temp<='9') {
					n *= 10;
					n += temp - '0';
				}
				else throw new NumberFormatException();
				temp = readByte();
			}
			return minus? -n : n;
		}

		public long[] nextLongArray (int n) {
			long[] ar = new long[n];
			for (int i=0; i<n; i++) ar[i] = nextLong();
			return ar;
		}

		public double nextDouble () {
			return Double.parseDouble(next());
		}

		public double[] nextDoubleArray (int n) {
			double[] ar = new double[n];
			for (int i=0; i<n; i++) ar[i] = nextDouble();
			return ar;
		}

		public void close () {
			try {in.close();}
			catch(Exception e){}
		}

	} FastScanner private InputStream in; in private byte[] buffer = new byte[1024]; buffer new byte[1024] 1024 private  int length = 0 length 0 p = 0; p 0 public FastScanner (InputStream stream) {
			in = stream;
		} FastScanner {
			in = stream;
		} in = stream in stream InputStream stream stream public boolean hasNextByte () {
			if (p < length) return true;
			else {
				p = 0;
				try {length = in.read(buffer);}
				catch (Exception e) {e.printStackTrace();}
				if (length <= 0) return false;
			}
			return true;
		} hasNextByte {
			if (p < length) return true;
			else {
				p = 0;
				try {length = in.read(buffer);}
				catch (Exception e) {e.printStackTrace();}
				if (length <= 0) return false;
			}
			return true;
		} if (p < length) return true;
			else {
				p = 0;
				try {length = in.read(buffer);}
				catch (Exception e) {e.printStackTrace();}
				if (length <= 0) return false;
			} p < length p length return true; true {
				p = 0;
				try {length = in.read(buffer);}
				catch (Exception e) {e.printStackTrace();}
				if (length <= 0) return false;
			} p = 0 p 0 try {length = in.read(buffer);}
				catch (Exception e) {e.printStackTrace();} catch (Exception e) {e.printStackTrace();} Exception e {e.printStackTrace();} e.printStackTrace() e.printStackTrace e {length = in.read(buffer);} length = in.read(buffer) length in.read(buffer) in.read in buffer if (length <= 0) return false; length <= 0 length 0 return false; false return true; true public int readByte () {
			if (hasNextByte() == true) return buffer[p++];
			return -1;
		} readByte {
			if (hasNextByte() == true) return buffer[p++];
			return -1;
		} if (hasNextByte() == true) return buffer[p++]; hasNextByte() == true hasNextByte() hasNextByte true return buffer[p++]; buffer[p++] buffer p++ p return -1; -1 1 public boolean isPrintable (int n) {return 33<=n&&n<=126;} isPrintable {return 33<=n&&n<=126;} return 33<=n&&n<=126; 33<=n&&n<=126 33<=n 33 n n<=126 n 126 int n n public void skip () {
			while (hasNextByte() && !isPrintable(buffer[p])) p++;
		} skip {
			while (hasNextByte() && !isPrintable(buffer[p])) p++;
		} while (hasNextByte() && !isPrintable(buffer[p])) p++; hasNextByte() && !isPrintable(buffer[p]) hasNextByte() hasNextByte !isPrintable(buffer[p]) isPrintable(buffer[p]) isPrintable buffer[p] buffer p p++ p public boolean hasNext () {skip(); return hasNextByte();} hasNext {skip(); return hasNextByte();} skip() skip return hasNextByte(); hasNextByte() hasNextByte public String next () {
			if (!hasNext()) throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int t = readByte();
			while (isPrintable(t)) {
				sb.appendCodePoint(t);
				t = readByte();
			}
			return sb.toString();
		} next {
			if (!hasNext()) throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int t = readByte();
			while (isPrintable(t)) {
				sb.appendCodePoint(t);
				t = readByte();
			}
			return sb.toString();
		} if (!hasNext()) throw new NoSuchElementException(); !hasNext() hasNext() hasNext throw new NoSuchElementException(); new NoSuchElementException() StringBuilder sb = new StringBuilder(); sb new StringBuilder() int t = readByte(); t readByte() readByte while (isPrintable(t)) {
				sb.appendCodePoint(t);
				t = readByte();
			} isPrintable(t) isPrintable t {
				sb.appendCodePoint(t);
				t = readByte();
			} sb.appendCodePoint(t) sb.appendCodePoint sb t t = readByte() t readByte() readByte return sb.toString(); sb.toString() sb.toString sb public String[] nextArray (int n) {
			String[] ar = new String[n];
			for (int i=0; i<n; i++) ar[i] = next();
			return ar;
		} nextArray {
			String[] ar = new String[n];
			for (int i=0; i<n; i++) ar[i] = next();
			return ar;
		} String[] ar = new String[n]; ar new String[n] n for (int i=0; i<n; i++) ar[i] = next(); int i=0; int i=0; i 0 i<n i n i++ i++ i ar[i] = next(); ar[i] = next() ar[i] ar i next() next return ar; ar int n n public int nextInt () {return Math.toIntExact(nextLong());} nextInt {return Math.toIntExact(nextLong());} return Math.toIntExact(nextLong()); Math.toIntExact(nextLong()) Math.toIntExact Math nextLong() nextLong public int[] nextIntArray (int n) {
			int[] ar = new int[n];
			for (int i=0; i<n; i++) ar[i] = nextInt();
			return ar;
		} nextIntArray {
			int[] ar = new int[n];
			for (int i=0; i<n; i++) ar[i] = nextInt();
			return ar;
		} int[] ar = new int[n]; ar new int[n] n for (int i=0; i<n; i++) ar[i] = nextInt(); int i=0; int i=0; i 0 i<n i n i++ i++ i ar[i] = nextInt(); ar[i] = nextInt() ar[i] ar i nextInt() nextInt return ar; ar int n n public long nextLong () {
			if (!hasNext()) throw new NoSuchElementException();
			boolean minus = false;
			int temp = readByte();
			if (temp == '-') {
				minus = true;
				temp = readByte();
			}
			if (temp<'0' || '9'<temp) throw new NumberFormatException();
			long n = 0;
			while (isPrintable(temp)) {
				if ('0'<=temp && temp<='9') {
					n *= 10;
					n += temp - '0';
				}
				else throw new NumberFormatException();
				temp = readByte();
			}
			return minus? -n : n;
		} nextLong {
			if (!hasNext()) throw new NoSuchElementException();
			boolean minus = false;
			int temp = readByte();
			if (temp == '-') {
				minus = true;
				temp = readByte();
			}
			if (temp<'0' || '9'<temp) throw new NumberFormatException();
			long n = 0;
			while (isPrintable(temp)) {
				if ('0'<=temp && temp<='9') {
					n *= 10;
					n += temp - '0';
				}
				else throw new NumberFormatException();
				temp = readByte();
			}
			return minus? -n : n;
		} if (!hasNext()) throw new NoSuchElementException(); !hasNext() hasNext() hasNext throw new NoSuchElementException(); new NoSuchElementException() boolean minus = false; minus false int temp = readByte(); temp readByte() readByte if (temp == '-') {
				minus = true;
				temp = readByte();
			} temp == '-' temp '-' {
				minus = true;
				temp = readByte();
			} minus = true minus true temp = readByte() temp readByte() readByte if (temp<'0' || '9'<temp) throw new NumberFormatException(); temp<'0' || '9'<temp temp<'0' temp '0' '9'<temp '9' temp throw new NumberFormatException(); new NumberFormatException() long n = 0; n 0 while (isPrintable(temp)) {
				if ('0'<=temp && temp<='9') {
					n *= 10;
					n += temp - '0';
				}
				else throw new NumberFormatException();
				temp = readByte();
			} isPrintable(temp) isPrintable temp {
				if ('0'<=temp && temp<='9') {
					n *= 10;
					n += temp - '0';
				}
				else throw new NumberFormatException();
				temp = readByte();
			} if ('0'<=temp && temp<='9') {
					n *= 10;
					n += temp - '0';
				}
				else throw new NumberFormatException(); '0'<=temp && temp<='9' '0'<=temp '0' temp temp<='9' temp '9' {
					n *= 10;
					n += temp - '0';
				} n *= 10 n 10 n += temp - '0' n temp - '0' temp '0' throw new NumberFormatException(); new NumberFormatException() temp = readByte() temp readByte() readByte return minus? -n : n; minus? -n : n minus -n n n public long[] nextLongArray (int n) {
			long[] ar = new long[n];
			for (int i=0; i<n; i++) ar[i] = nextLong();
			return ar;
		} nextLongArray {
			long[] ar = new long[n];
			for (int i=0; i<n; i++) ar[i] = nextLong();
			return ar;
		} long[] ar = new long[n]; ar new long[n] n for (int i=0; i<n; i++) ar[i] = nextLong(); int i=0; int i=0; i 0 i<n i n i++ i++ i ar[i] = nextLong(); ar[i] = nextLong() ar[i] ar i nextLong() nextLong return ar; ar int n n public double nextDouble () {
			return Double.parseDouble(next());
		} nextDouble {
			return Double.parseDouble(next());
		} return Double.parseDouble(next()); Double.parseDouble(next()) Double.parseDouble Double next() next public double[] nextDoubleArray (int n) {
			double[] ar = new double[n];
			for (int i=0; i<n; i++) ar[i] = nextDouble();
			return ar;
		} nextDoubleArray {
			double[] ar = new double[n];
			for (int i=0; i<n; i++) ar[i] = nextDouble();
			return ar;
		} double[] ar = new double[n]; ar new double[n] n for (int i=0; i<n; i++) ar[i] = nextDouble(); int i=0; int i=0; i 0 i<n i n i++ i++ i ar[i] = nextDouble(); ar[i] = nextDouble() ar[i] ar i nextDouble() nextDouble return ar; ar int n n public void close () {
			try {in.close();}
			catch(Exception e){}
		} close {
			try {in.close();}
			catch(Exception e){}
		} try {in.close();}
			catch(Exception e){} catch(Exception e){} Exception e {} {in.close();} in.close() in.close in public class Main {

	void solve (FastScanner in, PrintWriter out, Methods ms) {

		int n = in.nextInt(), q = in.nextInt();
		ArrayDeque<Process> dq = new ArrayDeque<>();
		for (int i=0; i<n; i++) dq.addLast(new Process(in.next(), in.nextInt()));
		
		int time = 0;
		while (dq.size() > 0) {
			
			if (dq.getFirst().time <= q) {
				time += dq.getFirst().time;
				out.println(dq.getFirst().name+" "+time);
				dq.removeFirst();
			}
			else {
				time += q;
				dq.getFirst().decTime(q);
				dq.addLast(dq.removeFirst());
			}
			
		}

	}
	
	static class Process {
		String name;
		int time;
		Process (String s, int n) {
			name = s; time = n;
		}
		void decTime (int n) {
			time -= n;
		}
	}



	public static void main(String[] args) {
		Main main = new Main();
		FastScanner in = new FastScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		Methods ms = new Methods();
		main.solve(in, out, ms);
		in.close();
		out.close();
	}

	static class Methods {

		public void print (Object... ar) {System.out.println(Arrays.deepToString(ar));}

		public void yesno (PrintWriter out, boolean b) {out.println(b?"Yes":"No");}

		public void YESNO (PrintWriter out, boolean b) {out.println(b?"YES":"NO");}

		public int max (int... ar) {Arrays.sort(ar); return ar[ar.length-1];}

		public int min (int... ar) {Arrays.sort(ar); return ar[0];}

		public long gcd (long a, long b) {return b>0?gcd(b,a%b):a;}

		public long lcm (long a, long b) {return a/gcd(a,b)*b;}

	}

	static class FastScanner {

		private InputStream in;
		private byte[] buffer = new byte[1024];
		private  int length = 0, p = 0;

		public FastScanner (InputStream stream) {
			in = stream;
		}

		public boolean hasNextByte () {
			if (p < length) return true;
			else {
				p = 0;
				try {length = in.read(buffer);}
				catch (Exception e) {e.printStackTrace();}
				if (length <= 0) return false;
			}
			return true;
		}

		public int readByte () {
			if (hasNextByte() == true) return buffer[p++];
			return -1;
		}

		public boolean isPrintable (int n) {return 33<=n&&n<=126;}

		public void skip () {
			while (hasNextByte() && !isPrintable(buffer[p])) p++;
		}

		public boolean hasNext () {skip(); return hasNextByte();}

		public String next () {
			if (!hasNext()) throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int t = readByte();
			while (isPrintable(t)) {
				sb.appendCodePoint(t);
				t = readByte();
			}
			return sb.toString();
		}

		public String[] nextArray (int n) {
			String[] ar = new String[n];
			for (int i=0; i<n; i++) ar[i] = next();
			return ar;
		}

		public int nextInt () {return Math.toIntExact(nextLong());}

		public int[] nextIntArray (int n) {
			int[] ar = new int[n];
			for (int i=0; i<n; i++) ar[i] = nextInt();
			return ar;
		}

		public long nextLong () {
			if (!hasNext()) throw new NoSuchElementException();
			boolean minus = false;
			int temp = readByte();
			if (temp == '-') {
				minus = true;
				temp = readByte();
			}
			if (temp<'0' || '9'<temp) throw new NumberFormatException();
			long n = 0;
			while (isPrintable(temp)) {
				if ('0'<=temp && temp<='9') {
					n *= 10;
					n += temp - '0';
				}
				else throw new NumberFormatException();
				temp = readByte();
			}
			return minus? -n : n;
		}

		public long[] nextLongArray (int n) {
			long[] ar = new long[n];
			for (int i=0; i<n; i++) ar[i] = nextLong();
			return ar;
		}

		public double nextDouble () {
			return Double.parseDouble(next());
		}

		public double[] nextDoubleArray (int n) {
			double[] ar = new double[n];
			for (int i=0; i<n; i++) ar[i] = nextDouble();
			return ar;
		}

		public void close () {
			try {in.close();}
			catch(Exception e){}
		}

	}

} public class Main {

	void solve (FastScanner in, PrintWriter out, Methods ms) {

		int n = in.nextInt(), q = in.nextInt();
		ArrayDeque<Process> dq = new ArrayDeque<>();
		for (int i=0; i<n; i++) dq.addLast(new Process(in.next(), in.nextInt()));
		
		int time = 0;
		while (dq.size() > 0) {
			
			if (dq.getFirst().time <= q) {
				time += dq.getFirst().time;
				out.println(dq.getFirst().name+" "+time);
				dq.removeFirst();
			}
			else {
				time += q;
				dq.getFirst().decTime(q);
				dq.addLast(dq.removeFirst());
			}
			
		}

	}
	
	static class Process {
		String name;
		int time;
		Process (String s, int n) {
			name = s; time = n;
		}
		void decTime (int n) {
			time -= n;
		}
	}



	public static void main(String[] args) {
		Main main = new Main();
		FastScanner in = new FastScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		Methods ms = new Methods();
		main.solve(in, out, ms);
		in.close();
		out.close();
	}

	static class Methods {

		public void print (Object... ar) {System.out.println(Arrays.deepToString(ar));}

		public void yesno (PrintWriter out, boolean b) {out.println(b?"Yes":"No");}

		public void YESNO (PrintWriter out, boolean b) {out.println(b?"YES":"NO");}

		public int max (int... ar) {Arrays.sort(ar); return ar[ar.length-1];}

		public int min (int... ar) {Arrays.sort(ar); return ar[0];}

		public long gcd (long a, long b) {return b>0?gcd(b,a%b):a;}

		public long lcm (long a, long b) {return a/gcd(a,b)*b;}

	}

	static class FastScanner {

		private InputStream in;
		private byte[] buffer = new byte[1024];
		private  int length = 0, p = 0;

		public FastScanner (InputStream stream) {
			in = stream;
		}

		public boolean hasNextByte () {
			if (p < length) return true;
			else {
				p = 0;
				try {length = in.read(buffer);}
				catch (Exception e) {e.printStackTrace();}
				if (length <= 0) return false;
			}
			return true;
		}

		public int readByte () {
			if (hasNextByte() == true) return buffer[p++];
			return -1;
		}

		public boolean isPrintable (int n) {return 33<=n&&n<=126;}

		public void skip () {
			while (hasNextByte() && !isPrintable(buffer[p])) p++;
		}

		public boolean hasNext () {skip(); return hasNextByte();}

		public String next () {
			if (!hasNext()) throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int t = readByte();
			while (isPrintable(t)) {
				sb.appendCodePoint(t);
				t = readByte();
			}
			return sb.toString();
		}

		public String[] nextArray (int n) {
			String[] ar = new String[n];
			for (int i=0; i<n; i++) ar[i] = next();
			return ar;
		}

		public int nextInt () {return Math.toIntExact(nextLong());}

		public int[] nextIntArray (int n) {
			int[] ar = new int[n];
			for (int i=0; i<n; i++) ar[i] = nextInt();
			return ar;
		}

		public long nextLong () {
			if (!hasNext()) throw new NoSuchElementException();
			boolean minus = false;
			int temp = readByte();
			if (temp == '-') {
				minus = true;
				temp = readByte();
			}
			if (temp<'0' || '9'<temp) throw new NumberFormatException();
			long n = 0;
			while (isPrintable(temp)) {
				if ('0'<=temp && temp<='9') {
					n *= 10;
					n += temp - '0';
				}
				else throw new NumberFormatException();
				temp = readByte();
			}
			return minus? -n : n;
		}

		public long[] nextLongArray (int n) {
			long[] ar = new long[n];
			for (int i=0; i<n; i++) ar[i] = nextLong();
			return ar;
		}

		public double nextDouble () {
			return Double.parseDouble(next());
		}

		public double[] nextDoubleArray (int n) {
			double[] ar = new double[n];
			for (int i=0; i<n; i++) ar[i] = nextDouble();
			return ar;
		}

		public void close () {
			try {in.close();}
			catch(Exception e){}
		}

	}

} Main
import java.util.*;
import java.io.*;
import java.math.*;

public class Main {

	void solve (FastScanner in, PrintWriter out, Methods ms) {

		int n = in.nextInt(), q = in.nextInt();
		ArrayDeque<Process> dq = new ArrayDeque<>();
		for (int i=0; i<n; i++) dq.addLast(new Process(in.next(), in.nextInt()));
		
		int time = 0;
		while (dq.size() > 0) {
			
			if (dq.getFirst().time <= q) {
				time += dq.getFirst().time;
				out.println(dq.getFirst().name+" "+time);
				dq.removeFirst();
			}
			else {
				time += q;
				dq.getFirst().decTime(q);
				dq.addLast(dq.removeFirst());
			}
			
		}

	}
	
	static class Process {
		String name;
		int time;
		Process (String s, int n) {
			name = s; time = n;
		}
		void decTime (int n) {
			time -= n;
		}
	}



	public static void main(String[] args) {
		Main main = new Main();
		FastScanner in = new FastScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		Methods ms = new Methods();
		main.solve(in, out, ms);
		in.close();
		out.close();
	}

	static class Methods {

		public void print (Object... ar) {System.out.println(Arrays.deepToString(ar));}

		public void yesno (PrintWriter out, boolean b) {out.println(b?"Yes":"No");}

		public void YESNO (PrintWriter out, boolean b) {out.println(b?"YES":"NO");}

		public int max (int... ar) {Arrays.sort(ar); return ar[ar.length-1];}

		public int min (int... ar) {Arrays.sort(ar); return ar[0];}

		public long gcd (long a, long b) {return b>0?gcd(b,a%b):a;}

		public long lcm (long a, long b) {return a/gcd(a,b)*b;}

	}

	static class FastScanner {

		private InputStream in;
		private byte[] buffer = new byte[1024];
		private  int length = 0, p = 0;

		public FastScanner (InputStream stream) {
			in = stream;
		}

		public boolean hasNextByte () {
			if (p < length) return true;
			else {
				p = 0;
				try {length = in.read(buffer);}
				catch (Exception e) {e.printStackTrace();}
				if (length <= 0) return false;
			}
			return true;
		}

		public int readByte () {
			if (hasNextByte() == true) return buffer[p++];
			return -1;
		}

		public boolean isPrintable (int n) {return 33<=n&&n<=126;}

		public void skip () {
			while (hasNextByte() && !isPrintable(buffer[p])) p++;
		}

		public boolean hasNext () {skip(); return hasNextByte();}

		public String next () {
			if (!hasNext()) throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int t = readByte();
			while (isPrintable(t)) {
				sb.appendCodePoint(t);
				t = readByte();
			}
			return sb.toString();
		}

		public String[] nextArray (int n) {
			String[] ar = new String[n];
			for (int i=0; i<n; i++) ar[i] = next();
			return ar;
		}

		public int nextInt () {return Math.toIntExact(nextLong());}

		public int[] nextIntArray (int n) {
			int[] ar = new int[n];
			for (int i=0; i<n; i++) ar[i] = nextInt();
			return ar;
		}

		public long nextLong () {
			if (!hasNext()) throw new NoSuchElementException();
			boolean minus = false;
			int temp = readByte();
			if (temp == '-') {
				minus = true;
				temp = readByte();
			}
			if (temp<'0' || '9'<temp) throw new NumberFormatException();
			long n = 0;
			while (isPrintable(temp)) {
				if ('0'<=temp && temp<='9') {
					n *= 10;
					n += temp - '0';
				}
				else throw new NumberFormatException();
				temp = readByte();
			}
			return minus? -n : n;
		}

		public long[] nextLongArray (int n) {
			long[] ar = new long[n];
			for (int i=0; i<n; i++) ar[i] = nextLong();
			return ar;
		}

		public double nextDouble () {
			return Double.parseDouble(next());
		}

		public double[] nextDoubleArray (int n) {
			double[] ar = new double[n];
			for (int i=0; i<n; i++) ar[i] = nextDouble();
			return ar;
		}

		public void close () {
			try {in.close();}
			catch(Exception e){}
		}

	}

}
