import java.io.IOException;
import java.io.InputStream;
import java.util.LinkedList;
import java.util.NoSuchElementException;
import java.util.Queue;

public class Main {
	private static FastScanner sc = new FastScanner();

	public static void main(String[] args) {
		int n = sc.nextInt();
		int q = sc.nextInt();
		
		Queue<Process> que = new LinkedList<>();
		for(int i=0; i<n; i++) {
			String name = sc.next();
			int time = sc.nextInt();
			que.add(new Process(name, time));
		}
		
		int timer = 0;
		while(!que.isEmpty()) {
			Process p = que.poll();
			if(p.time > q) {
				p.time -= q;
				timer += q;
				que.add(p);
			} else {
				timer += p.time;
				System.out.println(p.name + " " + timer);
			}
		}
	}
	
	static class Process {
		String name;
		int time;
		Process(String name, int time){
			this.name = name;
			this.time = time;
		}
	}
	
	static class FastScanner {
	    private final InputStream in = System.in;
	    private final byte[] buffer = new byte[1024];
	    private int ptr = 0;
	    private int buflen = 0;
	    private boolean hasNextByte() {
	        if (ptr < buflen) {
	            return true;
	        }else{
	            ptr = 0;
	            try {
	                buflen = in.read(buffer);
	            } catch (IOException e) {
	                e.printStackTrace();
	            }
	            if (buflen <= 0) {
	                return false;
	            }
	        }
	        return true;
	    }
	    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
	    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
	    private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
	    public boolean hasNext() { skipUnprintable(); return hasNextByte();}
	    public String next() {
	        if (!hasNext()) throw new NoSuchElementException();
	        StringBuilder sb = new StringBuilder();
	        int b = readByte();
	        while(isPrintableChar(b)) {
	            sb.appendCodePoint(b);
	            b = readByte();
	        }
	        return sb.toString();
	    }
	    public long nextLong() {
	        return Long.parseLong(next());
	    }
	    public int nextInt(){
	    	return Integer.parseInt(next());
	    }
	}

} import java.io.IOException; IOException java.io import java.io.InputStream; InputStream java.io import java.util.LinkedList; LinkedList java.util import java.util.NoSuchElementException; NoSuchElementException java.util import java.util.Queue; Queue java.util public class Main {
	private static FastScanner sc = new FastScanner();

	public static void main(String[] args) {
		int n = sc.nextInt();
		int q = sc.nextInt();
		
		Queue<Process> que = new LinkedList<>();
		for(int i=0; i<n; i++) {
			String name = sc.next();
			int time = sc.nextInt();
			que.add(new Process(name, time));
		}
		
		int timer = 0;
		while(!que.isEmpty()) {
			Process p = que.poll();
			if(p.time > q) {
				p.time -= q;
				timer += q;
				que.add(p);
			} else {
				timer += p.time;
				System.out.println(p.name + " " + timer);
			}
		}
	}
	
	static class Process {
		String name;
		int time;
		Process(String name, int time){
			this.name = name;
			this.time = time;
		}
	}
	
	static class FastScanner {
	    private final InputStream in = System.in;
	    private final byte[] buffer = new byte[1024];
	    private int ptr = 0;
	    private int buflen = 0;
	    private boolean hasNextByte() {
	        if (ptr < buflen) {
	            return true;
	        }else{
	            ptr = 0;
	            try {
	                buflen = in.read(buffer);
	            } catch (IOException e) {
	                e.printStackTrace();
	            }
	            if (buflen <= 0) {
	                return false;
	            }
	        }
	        return true;
	    }
	    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
	    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
	    private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
	    public boolean hasNext() { skipUnprintable(); return hasNextByte();}
	    public String next() {
	        if (!hasNext()) throw new NoSuchElementException();
	        StringBuilder sb = new StringBuilder();
	        int b = readByte();
	        while(isPrintableChar(b)) {
	            sb.appendCodePoint(b);
	            b = readByte();
	        }
	        return sb.toString();
	    }
	    public long nextLong() {
	        return Long.parseLong(next());
	    }
	    public int nextInt(){
	    	return Integer.parseInt(next());
	    }
	}

} Main private static FastScanner sc = new FastScanner(); sc new FastScanner() public static void main(String[] args) {
		int n = sc.nextInt();
		int q = sc.nextInt();
		
		Queue<Process> que = new LinkedList<>();
		for(int i=0; i<n; i++) {
			String name = sc.next();
			int time = sc.nextInt();
			que.add(new Process(name, time));
		}
		
		int timer = 0;
		while(!que.isEmpty()) {
			Process p = que.poll();
			if(p.time > q) {
				p.time -= q;
				timer += q;
				que.add(p);
			} else {
				timer += p.time;
				System.out.println(p.name + " " + timer);
			}
		}
	} main {
		int n = sc.nextInt();
		int q = sc.nextInt();
		
		Queue<Process> que = new LinkedList<>();
		for(int i=0; i<n; i++) {
			String name = sc.next();
			int time = sc.nextInt();
			que.add(new Process(name, time));
		}
		
		int timer = 0;
		while(!que.isEmpty()) {
			Process p = que.poll();
			if(p.time > q) {
				p.time -= q;
				timer += q;
				que.add(p);
			} else {
				timer += p.time;
				System.out.println(p.name + " " + timer);
			}
		}
	} int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int q = sc.nextInt(); q sc.nextInt() sc.nextInt sc Queue<Process> que = new LinkedList<>(); que new LinkedList<>() for(int i=0; i<n; i++) {
			String name = sc.next();
			int time = sc.nextInt();
			que.add(new Process(name, time));
		} int i=0; int i=0; i 0 i<n i n i++ i++ i {
			String name = sc.next();
			int time = sc.nextInt();
			que.add(new Process(name, time));
		} {
			String name = sc.next();
			int time = sc.nextInt();
			que.add(new Process(name, time));
		} String name = sc.next(); name sc.next() sc.next sc int time = sc.nextInt(); time sc.nextInt() sc.nextInt sc que.add(new Process(name, time)) que.add que new Process(name, time) int timer = 0; timer 0 while(!que.isEmpty()) {
			Process p = que.poll();
			if(p.time > q) {
				p.time -= q;
				timer += q;
				que.add(p);
			} else {
				timer += p.time;
				System.out.println(p.name + " " + timer);
			}
		} !que.isEmpty() que.isEmpty() que.isEmpty que {
			Process p = que.poll();
			if(p.time > q) {
				p.time -= q;
				timer += q;
				que.add(p);
			} else {
				timer += p.time;
				System.out.println(p.name + " " + timer);
			}
		} Process p = que.poll(); p que.poll() que.poll que if(p.time > q) {
				p.time -= q;
				timer += q;
				que.add(p);
			} else {
				timer += p.time;
				System.out.println(p.name + " " + timer);
			} p.time > q p.time p p.time q {
				p.time -= q;
				timer += q;
				que.add(p);
			} p.time -= q p.time p p.time q timer += q timer q que.add(p) que.add que p {
				timer += p.time;
				System.out.println(p.name + " " + timer);
			} timer += p.time timer p.time p p.time System.out.println(p.name + " " + timer) System.out.println System.out System System.out p.name + " " + timer p.name + " " + timer p.name p p.name " " timer String[] args args static class Process {
		String name;
		int time;
		Process(String name, int time){
			this.name = name;
			this.time = time;
		}
	} Process String name; name int time; time Process(String name, int time){
			this.name = name;
			this.time = time;
		} Process {
			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 static class FastScanner {
	    private final InputStream in = System.in;
	    private final byte[] buffer = new byte[1024];
	    private int ptr = 0;
	    private int buflen = 0;
	    private boolean hasNextByte() {
	        if (ptr < buflen) {
	            return true;
	        }else{
	            ptr = 0;
	            try {
	                buflen = in.read(buffer);
	            } catch (IOException e) {
	                e.printStackTrace();
	            }
	            if (buflen <= 0) {
	                return false;
	            }
	        }
	        return true;
	    }
	    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
	    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
	    private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
	    public boolean hasNext() { skipUnprintable(); return hasNextByte();}
	    public String next() {
	        if (!hasNext()) throw new NoSuchElementException();
	        StringBuilder sb = new StringBuilder();
	        int b = readByte();
	        while(isPrintableChar(b)) {
	            sb.appendCodePoint(b);
	            b = readByte();
	        }
	        return sb.toString();
	    }
	    public long nextLong() {
	        return Long.parseLong(next());
	    }
	    public int nextInt(){
	    	return Integer.parseInt(next());
	    }
	} FastScanner private final InputStream in = System.in; in System.in System System.in private final byte[] buffer = new byte[1024]; buffer new byte[1024] 1024 private int ptr = 0; ptr 0 private int buflen = 0; buflen 0 private boolean hasNextByte() {
	        if (ptr < buflen) {
	            return true;
	        }else{
	            ptr = 0;
	            try {
	                buflen = in.read(buffer);
	            } catch (IOException e) {
	                e.printStackTrace();
	            }
	            if (buflen <= 0) {
	                return false;
	            }
	        }
	        return true;
	    } hasNextByte {
	        if (ptr < buflen) {
	            return true;
	        }else{
	            ptr = 0;
	            try {
	                buflen = in.read(buffer);
	            } catch (IOException e) {
	                e.printStackTrace();
	            }
	            if (buflen <= 0) {
	                return false;
	            }
	        }
	        return true;
	    } if (ptr < buflen) {
	            return true;
	        }else{
	            ptr = 0;
	            try {
	                buflen = in.read(buffer);
	            } catch (IOException e) {
	                e.printStackTrace();
	            }
	            if (buflen <= 0) {
	                return false;
	            }
	        } ptr < buflen ptr buflen {
	            return true;
	        } return true; true {
	            ptr = 0;
	            try {
	                buflen = in.read(buffer);
	            } catch (IOException e) {
	                e.printStackTrace();
	            }
	            if (buflen <= 0) {
	                return false;
	            }
	        } ptr = 0 ptr 0 try {
	                buflen = in.read(buffer);
	            } catch (IOException e) {
	                e.printStackTrace();
	            } catch (IOException e) {
	                e.printStackTrace();
	            } IOException e {
	                e.printStackTrace();
	            } e.printStackTrace() e.printStackTrace e {
	                buflen = in.read(buffer);
	            } buflen = in.read(buffer) buflen in.read(buffer) in.read in buffer if (buflen <= 0) {
	                return false;
	            } buflen <= 0 buflen 0 {
	                return false;
	            } return false; false return true; true private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;} readByte { if (hasNextByte()) return buffer[ptr++]; else return -1;} if (hasNextByte()) return buffer[ptr++]; else return -1; hasNextByte() hasNextByte return buffer[ptr++]; buffer[ptr++] buffer ptr++ ptr return -1; -1 1 private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;} isPrintableChar { return 33 <= c && c <= 126;} return 33 <= c && c <= 126; 33 <= c && c <= 126 33 <= c 33 c c <= 126 c 126 int c c private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;} skipUnprintable { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;} while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; hasNextByte() && !isPrintableChar(buffer[ptr]) hasNextByte() hasNextByte !isPrintableChar(buffer[ptr]) isPrintableChar(buffer[ptr]) isPrintableChar buffer[ptr] buffer ptr ptr++ ptr public boolean hasNext() { skipUnprintable(); return hasNextByte();} hasNext { skipUnprintable(); return hasNextByte();} skipUnprintable() skipUnprintable return hasNextByte(); hasNextByte() hasNextByte public String next() {
	        if (!hasNext()) throw new NoSuchElementException();
	        StringBuilder sb = new StringBuilder();
	        int b = readByte();
	        while(isPrintableChar(b)) {
	            sb.appendCodePoint(b);
	            b = readByte();
	        }
	        return sb.toString();
	    } next {
	        if (!hasNext()) throw new NoSuchElementException();
	        StringBuilder sb = new StringBuilder();
	        int b = readByte();
	        while(isPrintableChar(b)) {
	            sb.appendCodePoint(b);
	            b = 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 b = readByte(); b readByte() readByte while(isPrintableChar(b)) {
	            sb.appendCodePoint(b);
	            b = readByte();
	        } isPrintableChar(b) isPrintableChar b {
	            sb.appendCodePoint(b);
	            b = readByte();
	        } sb.appendCodePoint(b) sb.appendCodePoint sb b b = readByte() b readByte() readByte return sb.toString(); sb.toString() sb.toString sb public long nextLong() {
	        return Long.parseLong(next());
	    } nextLong {
	        return Long.parseLong(next());
	    } return Long.parseLong(next()); Long.parseLong(next()) Long.parseLong Long next() next public int nextInt(){
	    	return Integer.parseInt(next());
	    } nextInt {
	    	return Integer.parseInt(next());
	    } return Integer.parseInt(next()); Integer.parseInt(next()) Integer.parseInt Integer next() next public class Main {
	private static FastScanner sc = new FastScanner();

	public static void main(String[] args) {
		int n = sc.nextInt();
		int q = sc.nextInt();
		
		Queue<Process> que = new LinkedList<>();
		for(int i=0; i<n; i++) {
			String name = sc.next();
			int time = sc.nextInt();
			que.add(new Process(name, time));
		}
		
		int timer = 0;
		while(!que.isEmpty()) {
			Process p = que.poll();
			if(p.time > q) {
				p.time -= q;
				timer += q;
				que.add(p);
			} else {
				timer += p.time;
				System.out.println(p.name + " " + timer);
			}
		}
	}
	
	static class Process {
		String name;
		int time;
		Process(String name, int time){
			this.name = name;
			this.time = time;
		}
	}
	
	static class FastScanner {
	    private final InputStream in = System.in;
	    private final byte[] buffer = new byte[1024];
	    private int ptr = 0;
	    private int buflen = 0;
	    private boolean hasNextByte() {
	        if (ptr < buflen) {
	            return true;
	        }else{
	            ptr = 0;
	            try {
	                buflen = in.read(buffer);
	            } catch (IOException e) {
	                e.printStackTrace();
	            }
	            if (buflen <= 0) {
	                return false;
	            }
	        }
	        return true;
	    }
	    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
	    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
	    private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
	    public boolean hasNext() { skipUnprintable(); return hasNextByte();}
	    public String next() {
	        if (!hasNext()) throw new NoSuchElementException();
	        StringBuilder sb = new StringBuilder();
	        int b = readByte();
	        while(isPrintableChar(b)) {
	            sb.appendCodePoint(b);
	            b = readByte();
	        }
	        return sb.toString();
	    }
	    public long nextLong() {
	        return Long.parseLong(next());
	    }
	    public int nextInt(){
	    	return Integer.parseInt(next());
	    }
	}

} public class Main {
	private static FastScanner sc = new FastScanner();

	public static void main(String[] args) {
		int n = sc.nextInt();
		int q = sc.nextInt();
		
		Queue<Process> que = new LinkedList<>();
		for(int i=0; i<n; i++) {
			String name = sc.next();
			int time = sc.nextInt();
			que.add(new Process(name, time));
		}
		
		int timer = 0;
		while(!que.isEmpty()) {
			Process p = que.poll();
			if(p.time > q) {
				p.time -= q;
				timer += q;
				que.add(p);
			} else {
				timer += p.time;
				System.out.println(p.name + " " + timer);
			}
		}
	}
	
	static class Process {
		String name;
		int time;
		Process(String name, int time){
			this.name = name;
			this.time = time;
		}
	}
	
	static class FastScanner {
	    private final InputStream in = System.in;
	    private final byte[] buffer = new byte[1024];
	    private int ptr = 0;
	    private int buflen = 0;
	    private boolean hasNextByte() {
	        if (ptr < buflen) {
	            return true;
	        }else{
	            ptr = 0;
	            try {
	                buflen = in.read(buffer);
	            } catch (IOException e) {
	                e.printStackTrace();
	            }
	            if (buflen <= 0) {
	                return false;
	            }
	        }
	        return true;
	    }
	    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
	    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
	    private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
	    public boolean hasNext() { skipUnprintable(); return hasNextByte();}
	    public String next() {
	        if (!hasNext()) throw new NoSuchElementException();
	        StringBuilder sb = new StringBuilder();
	        int b = readByte();
	        while(isPrintableChar(b)) {
	            sb.appendCodePoint(b);
	            b = readByte();
	        }
	        return sb.toString();
	    }
	    public long nextLong() {
	        return Long.parseLong(next());
	    }
	    public int nextInt(){
	    	return Integer.parseInt(next());
	    }
	}

} Main
import java.io.IOException;
import java.io.InputStream;
import java.util.LinkedList;
import java.util.NoSuchElementException;
import java.util.Queue;

public class Main {
	private static FastScanner sc = new FastScanner();

	public static void main(String[] args) {
		int n = sc.nextInt();
		int q = sc.nextInt();
		
		Queue<Process> que = new LinkedList<>();
		for(int i=0; i<n; i++) {
			String name = sc.next();
			int time = sc.nextInt();
			que.add(new Process(name, time));
		}
		
		int timer = 0;
		while(!que.isEmpty()) {
			Process p = que.poll();
			if(p.time > q) {
				p.time -= q;
				timer += q;
				que.add(p);
			} else {
				timer += p.time;
				System.out.println(p.name + " " + timer);
			}
		}
	}
	
	static class Process {
		String name;
		int time;
		Process(String name, int time){
			this.name = name;
			this.time = time;
		}
	}
	
	static class FastScanner {
	    private final InputStream in = System.in;
	    private final byte[] buffer = new byte[1024];
	    private int ptr = 0;
	    private int buflen = 0;
	    private boolean hasNextByte() {
	        if (ptr < buflen) {
	            return true;
	        }else{
	            ptr = 0;
	            try {
	                buflen = in.read(buffer);
	            } catch (IOException e) {
	                e.printStackTrace();
	            }
	            if (buflen <= 0) {
	                return false;
	            }
	        }
	        return true;
	    }
	    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
	    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
	    private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
	    public boolean hasNext() { skipUnprintable(); return hasNextByte();}
	    public String next() {
	        if (!hasNext()) throw new NoSuchElementException();
	        StringBuilder sb = new StringBuilder();
	        int b = readByte();
	        while(isPrintableChar(b)) {
	            sb.appendCodePoint(b);
	            b = readByte();
	        }
	        return sb.toString();
	    }
	    public long nextLong() {
	        return Long.parseLong(next());
	    }
	    public int nextInt(){
	    	return Integer.parseInt(next());
	    }
	}

}