import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
  
public class Main {
	private static final String EOF = System.lineSeparator();
	private MyIntQueue queue = new MyIntQueue();
	private ProcessManager pm = new ProcessManager();
    public static void main(String[] args) throws IOException {
        new Main().exec();
    }
    
    public void exec() throws IOException {
    	SimpleInputUtil in = new SimpleInputUtil();
        PrintWriter out = new PrintWriter(System.out);
        StringBuilder sb = new StringBuilder();
    	
        int[] tmp = in.readIntArray(new int[2]);
    	int n = tmp[0];
    	int q = tmp[1];
    	
    	for(int i=0; i<n; i++) {
    		queue.add(pm.addProcess(in.readStrArray(" ")));
    	}
    	
    	int totalTime = 0;
    	while(!queue.isEmpty()) {
    		int procId = queue.remove();
    		int time = pm.getTime(procId);
    		if(time <= q) {
    			//Process Finish
    			totalTime += time;
    			sb.append(pm.getName(procId)).append(" ").append(totalTime).append(EOF);
    		}else{
    			//Process Continue
    			queue.add(procId);
    			pm.setTime(procId, time - q);
    			totalTime += q;
    		}
    	}
        out.print(sb.toString());
    	out.flush();
    }
}

class ProcessManager {
	private static final int CAPACITY = 100000;
	private String[] names = new String[CAPACITY];
	private int[] times = new int[CAPACITY];
	private int ptr = 0;
	
	public int addProcess(String[] procInfo) {
		names[ptr] = procInfo[0];
		times[ptr] = Integer.parseInt(procInfo[1]);
		return ptr++;
	}
	
	public String getName(int procId) {
		return names[procId];
	}
	
	public int getTime(int procId) {
		return times[procId];
	}
	
	public void setTime(int procId, int time) {
		times[procId] = time;
	}
}

class MyIntQueue {
	private static final int CAPACITY = 100000;
	private int[] queue = new int[CAPACITY];
    private int head = 0;
    private int tail = 0;
    
    public boolean isEmpty(){return head == tail;}
    public boolean isFull(){return (head+1)%CAPACITY == tail;}
    
    public int remove() {
    	if(isEmpty()) throw new IllegalStateException();
    	int ret = queue[tail++];
    	tail %= CAPACITY;
    	return ret;
    }
   
    public int add(int value) {
    	if(isFull()) throw new IllegalStateException();
    	int ret =  queue[head++] = value;
    	head %= CAPACITY;
    	return ret;
    }
}

class SimpleInputUtil {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    public String[] readStrArray(String delim) throws NumberFormatException, IOException{
    	return br.readLine().split(delim);
    }
    
    public int readInt() throws NumberFormatException, IOException{
    	return Integer.parseInt(br.readLine());
    }
    
    public int[] readIntArray(int[] a) throws NumberFormatException, IOException{
        int i=0;
        while(i<a.length) {
            for(String s: br.readLine().split(" ")){
            	if(i<a.length) {
                    a[i++] = Integer.parseInt(s);
            	}
            }
        }
        return a;
    }
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io import java.io.PrintWriter; PrintWriter java.io public class Main {
	private static final String EOF = System.lineSeparator();
	private MyIntQueue queue = new MyIntQueue();
	private ProcessManager pm = new ProcessManager();
    public static void main(String[] args) throws IOException {
        new Main().exec();
    }
    
    public void exec() throws IOException {
    	SimpleInputUtil in = new SimpleInputUtil();
        PrintWriter out = new PrintWriter(System.out);
        StringBuilder sb = new StringBuilder();
    	
        int[] tmp = in.readIntArray(new int[2]);
    	int n = tmp[0];
    	int q = tmp[1];
    	
    	for(int i=0; i<n; i++) {
    		queue.add(pm.addProcess(in.readStrArray(" ")));
    	}
    	
    	int totalTime = 0;
    	while(!queue.isEmpty()) {
    		int procId = queue.remove();
    		int time = pm.getTime(procId);
    		if(time <= q) {
    			//Process Finish
    			totalTime += time;
    			sb.append(pm.getName(procId)).append(" ").append(totalTime).append(EOF);
    		}else{
    			//Process Continue
    			queue.add(procId);
    			pm.setTime(procId, time - q);
    			totalTime += q;
    		}
    	}
        out.print(sb.toString());
    	out.flush();
    }
} Main private static final String EOF = System.lineSeparator(); EOF System.lineSeparator() System.lineSeparator System private MyIntQueue queue = new MyIntQueue(); queue new MyIntQueue() private ProcessManager pm = new ProcessManager(); pm new ProcessManager() public static void main(String[] args) throws IOException {
        new Main().exec();
    } main {
        new Main().exec();
    } new Main().exec() new Main().exec new Main() String[] args args public void exec() throws IOException {
    	SimpleInputUtil in = new SimpleInputUtil();
        PrintWriter out = new PrintWriter(System.out);
        StringBuilder sb = new StringBuilder();
    	
        int[] tmp = in.readIntArray(new int[2]);
    	int n = tmp[0];
    	int q = tmp[1];
    	
    	for(int i=0; i<n; i++) {
    		queue.add(pm.addProcess(in.readStrArray(" ")));
    	}
    	
    	int totalTime = 0;
    	while(!queue.isEmpty()) {
    		int procId = queue.remove();
    		int time = pm.getTime(procId);
    		if(time <= q) {
    			//Process Finish
    			totalTime += time;
    			sb.append(pm.getName(procId)).append(" ").append(totalTime).append(EOF);
    		}else{
    			//Process Continue
    			queue.add(procId);
    			pm.setTime(procId, time - q);
    			totalTime += q;
    		}
    	}
        out.print(sb.toString());
    	out.flush();
    } exec {
    	SimpleInputUtil in = new SimpleInputUtil();
        PrintWriter out = new PrintWriter(System.out);
        StringBuilder sb = new StringBuilder();
    	
        int[] tmp = in.readIntArray(new int[2]);
    	int n = tmp[0];
    	int q = tmp[1];
    	
    	for(int i=0; i<n; i++) {
    		queue.add(pm.addProcess(in.readStrArray(" ")));
    	}
    	
    	int totalTime = 0;
    	while(!queue.isEmpty()) {
    		int procId = queue.remove();
    		int time = pm.getTime(procId);
    		if(time <= q) {
    			//Process Finish
    			totalTime += time;
    			sb.append(pm.getName(procId)).append(" ").append(totalTime).append(EOF);
    		}else{
    			//Process Continue
    			queue.add(procId);
    			pm.setTime(procId, time - q);
    			totalTime += q;
    		}
    	}
        out.print(sb.toString());
    	out.flush();
    } SimpleInputUtil in = new SimpleInputUtil(); in new SimpleInputUtil() PrintWriter out = new PrintWriter(System.out); out new PrintWriter(System.out) StringBuilder sb = new StringBuilder(); sb new StringBuilder() int[] tmp = in.readIntArray(new int[2]); tmp in.readIntArray(new int[2]) in.readIntArray in new int[2] 2 int n = tmp[0]; n tmp[0] tmp 0 int q = tmp[1]; q tmp[1] tmp 1 for(int i=0; i<n; i++) {
    		queue.add(pm.addProcess(in.readStrArray(" ")));
    	} int i=0; int i=0; i 0 i<n i n i++ i++ i {
    		queue.add(pm.addProcess(in.readStrArray(" ")));
    	} {
    		queue.add(pm.addProcess(in.readStrArray(" ")));
    	} queue.add(pm.addProcess(in.readStrArray(" "))) queue.add queue pm.addProcess(in.readStrArray(" ")) pm.addProcess pm in.readStrArray(" ") in.readStrArray in " " int totalTime = 0; totalTime 0 while(!queue.isEmpty()) {
    		int procId = queue.remove();
    		int time = pm.getTime(procId);
    		if(time <= q) {
    			//Process Finish
    			totalTime += time;
    			sb.append(pm.getName(procId)).append(" ").append(totalTime).append(EOF);
    		}else{
    			//Process Continue
    			queue.add(procId);
    			pm.setTime(procId, time - q);
    			totalTime += q;
    		}
    	} !queue.isEmpty() queue.isEmpty() queue.isEmpty queue {
    		int procId = queue.remove();
    		int time = pm.getTime(procId);
    		if(time <= q) {
    			//Process Finish
    			totalTime += time;
    			sb.append(pm.getName(procId)).append(" ").append(totalTime).append(EOF);
    		}else{
    			//Process Continue
    			queue.add(procId);
    			pm.setTime(procId, time - q);
    			totalTime += q;
    		}
    	} int procId = queue.remove(); procId queue.remove() queue.remove queue int time = pm.getTime(procId); time pm.getTime(procId) pm.getTime pm procId if(time <= q) {
    			//Process Finish
    			totalTime += time;
    			sb.append(pm.getName(procId)).append(" ").append(totalTime).append(EOF);
    		}else{
    			//Process Continue
    			queue.add(procId);
    			pm.setTime(procId, time - q);
    			totalTime += q;
    		} time <= q time q {
    			//Process Finish
    			totalTime += time;
    			sb.append(pm.getName(procId)).append(" ").append(totalTime).append(EOF);
    		} totalTime += time totalTime time sb.append(pm.getName(procId)).append(" ").append(totalTime).append(EOF) sb.append(pm.getName(procId)).append(" ").append(totalTime).append sb.append(pm.getName(procId)).append(" ").append(totalTime) sb.append(pm.getName(procId)).append(" ").append sb.append(pm.getName(procId)).append(" ") sb.append(pm.getName(procId)).append sb.append(pm.getName(procId)) sb.append sb pm.getName(procId) pm.getName pm procId " " totalTime EOF {
    			//Process Continue
    			queue.add(procId);
    			pm.setTime(procId, time - q);
    			totalTime += q;
    		} queue.add(procId) queue.add queue procId pm.setTime(procId, time - q) pm.setTime pm procId time - q time q totalTime += q totalTime q out.print(sb.toString()) out.print out sb.toString() sb.toString sb out.flush() out.flush out class ProcessManager {
	private static final int CAPACITY = 100000;
	private String[] names = new String[CAPACITY];
	private int[] times = new int[CAPACITY];
	private int ptr = 0;
	
	public int addProcess(String[] procInfo) {
		names[ptr] = procInfo[0];
		times[ptr] = Integer.parseInt(procInfo[1]);
		return ptr++;
	}
	
	public String getName(int procId) {
		return names[procId];
	}
	
	public int getTime(int procId) {
		return times[procId];
	}
	
	public void setTime(int procId, int time) {
		times[procId] = time;
	}
} ProcessManager private static final int CAPACITY = 100000; CAPACITY 100000 private String[] names = new String[CAPACITY]; names new String[CAPACITY] CAPACITY private int[] times = new int[CAPACITY]; times new int[CAPACITY] CAPACITY private int ptr = 0; ptr 0 public int addProcess(String[] procInfo) {
		names[ptr] = procInfo[0];
		times[ptr] = Integer.parseInt(procInfo[1]);
		return ptr++;
	} addProcess {
		names[ptr] = procInfo[0];
		times[ptr] = Integer.parseInt(procInfo[1]);
		return ptr++;
	} names[ptr] = procInfo[0] names[ptr] names ptr procInfo[0] procInfo 0 times[ptr] = Integer.parseInt(procInfo[1]) times[ptr] times ptr Integer.parseInt(procInfo[1]) Integer.parseInt Integer procInfo[1] procInfo 1 return ptr++; ptr++ ptr String[] procInfo procInfo public String getName(int procId) {
		return names[procId];
	} getName {
		return names[procId];
	} return names[procId]; names[procId] names procId int procId procId public int getTime(int procId) {
		return times[procId];
	} getTime {
		return times[procId];
	} return times[procId]; times[procId] times procId int procId procId public void setTime(int procId, int time) {
		times[procId] = time;
	} setTime {
		times[procId] = time;
	} times[procId] = time times[procId] times procId time int procId procId int time time class MyIntQueue {
	private static final int CAPACITY = 100000;
	private int[] queue = new int[CAPACITY];
    private int head = 0;
    private int tail = 0;
    
    public boolean isEmpty(){return head == tail;}
    public boolean isFull(){return (head+1)%CAPACITY == tail;}
    
    public int remove() {
    	if(isEmpty()) throw new IllegalStateException();
    	int ret = queue[tail++];
    	tail %= CAPACITY;
    	return ret;
    }
   
    public int add(int value) {
    	if(isFull()) throw new IllegalStateException();
    	int ret =  queue[head++] = value;
    	head %= CAPACITY;
    	return ret;
    }
} MyIntQueue private static final int CAPACITY = 100000; CAPACITY 100000 private int[] queue = new int[CAPACITY]; queue new int[CAPACITY] CAPACITY private int head = 0; head 0 private int tail = 0; tail 0 public boolean isEmpty(){return head == tail;} isEmpty {return head == tail;} return head == tail; head == tail head tail public boolean isFull(){return (head+1)%CAPACITY == tail;} isFull {return (head+1)%CAPACITY == tail;} return (head+1)%CAPACITY == tail; (head+1)%CAPACITY == tail (head+1)%CAPACITY (head+1) head 1 CAPACITY tail public int remove() {
    	if(isEmpty()) throw new IllegalStateException();
    	int ret = queue[tail++];
    	tail %= CAPACITY;
    	return ret;
    } remove {
    	if(isEmpty()) throw new IllegalStateException();
    	int ret = queue[tail++];
    	tail %= CAPACITY;
    	return ret;
    } if(isEmpty()) throw new IllegalStateException(); isEmpty() isEmpty throw new IllegalStateException(); new IllegalStateException() int ret = queue[tail++]; ret queue[tail++] queue tail++ tail tail %= CAPACITY tail CAPACITY return ret; ret public int add(int value) {
    	if(isFull()) throw new IllegalStateException();
    	int ret =  queue[head++] = value;
    	head %= CAPACITY;
    	return ret;
    } add {
    	if(isFull()) throw new IllegalStateException();
    	int ret =  queue[head++] = value;
    	head %= CAPACITY;
    	return ret;
    } if(isFull()) throw new IllegalStateException(); isFull() isFull throw new IllegalStateException(); new IllegalStateException() int ret =  queue[head++] = value; ret queue[head++] = value queue[head++] queue head++ head value head %= CAPACITY head CAPACITY return ret; ret int value value class SimpleInputUtil {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    public String[] readStrArray(String delim) throws NumberFormatException, IOException{
    	return br.readLine().split(delim);
    }
    
    public int readInt() throws NumberFormatException, IOException{
    	return Integer.parseInt(br.readLine());
    }
    
    public int[] readIntArray(int[] a) throws NumberFormatException, IOException{
        int i=0;
        while(i<a.length) {
            for(String s: br.readLine().split(" ")){
            	if(i<a.length) {
                    a[i++] = Integer.parseInt(s);
            	}
            }
        }
        return a;
    }
} SimpleInputUtil BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) public String[] readStrArray(String delim) throws NumberFormatException, IOException{
    	return br.readLine().split(delim);
    } readStrArray {
    	return br.readLine().split(delim);
    } return br.readLine().split(delim); br.readLine().split(delim) br.readLine().split br.readLine() br.readLine br delim String delim delim public int readInt() throws NumberFormatException, IOException{
    	return Integer.parseInt(br.readLine());
    } readInt {
    	return Integer.parseInt(br.readLine());
    } return Integer.parseInt(br.readLine()); Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br public int[] readIntArray(int[] a) throws NumberFormatException, IOException{
        int i=0;
        while(i<a.length) {
            for(String s: br.readLine().split(" ")){
            	if(i<a.length) {
                    a[i++] = Integer.parseInt(s);
            	}
            }
        }
        return a;
    } readIntArray {
        int i=0;
        while(i<a.length) {
            for(String s: br.readLine().split(" ")){
            	if(i<a.length) {
                    a[i++] = Integer.parseInt(s);
            	}
            }
        }
        return a;
    } int i=0; i 0 while(i<a.length) {
            for(String s: br.readLine().split(" ")){
            	if(i<a.length) {
                    a[i++] = Integer.parseInt(s);
            	}
            }
        } i<a.length i a.length a a.length {
            for(String s: br.readLine().split(" ")){
            	if(i<a.length) {
                    a[i++] = Integer.parseInt(s);
            	}
            }
        } for(String s: br.readLine().split(" ")){
            	if(i<a.length) {
                    a[i++] = Integer.parseInt(s);
            	}
            } String s br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " {
            	if(i<a.length) {
                    a[i++] = Integer.parseInt(s);
            	}
            } {
            	if(i<a.length) {
                    a[i++] = Integer.parseInt(s);
            	}
            } if(i<a.length) {
                    a[i++] = Integer.parseInt(s);
            	} i<a.length i a.length a a.length {
                    a[i++] = Integer.parseInt(s);
            	} a[i++] = Integer.parseInt(s) a[i++] a i++ i Integer.parseInt(s) Integer.parseInt Integer s return a; a int[] a a public class Main {
	private static final String EOF = System.lineSeparator();
	private MyIntQueue queue = new MyIntQueue();
	private ProcessManager pm = new ProcessManager();
    public static void main(String[] args) throws IOException {
        new Main().exec();
    }
    
    public void exec() throws IOException {
    	SimpleInputUtil in = new SimpleInputUtil();
        PrintWriter out = new PrintWriter(System.out);
        StringBuilder sb = new StringBuilder();
    	
        int[] tmp = in.readIntArray(new int[2]);
    	int n = tmp[0];
    	int q = tmp[1];
    	
    	for(int i=0; i<n; i++) {
    		queue.add(pm.addProcess(in.readStrArray(" ")));
    	}
    	
    	int totalTime = 0;
    	while(!queue.isEmpty()) {
    		int procId = queue.remove();
    		int time = pm.getTime(procId);
    		if(time <= q) {
    			//Process Finish
    			totalTime += time;
    			sb.append(pm.getName(procId)).append(" ").append(totalTime).append(EOF);
    		}else{
    			//Process Continue
    			queue.add(procId);
    			pm.setTime(procId, time - q);
    			totalTime += q;
    		}
    	}
        out.print(sb.toString());
    	out.flush();
    }
} public class Main {
	private static final String EOF = System.lineSeparator();
	private MyIntQueue queue = new MyIntQueue();
	private ProcessManager pm = new ProcessManager();
    public static void main(String[] args) throws IOException {
        new Main().exec();
    }
    
    public void exec() throws IOException {
    	SimpleInputUtil in = new SimpleInputUtil();
        PrintWriter out = new PrintWriter(System.out);
        StringBuilder sb = new StringBuilder();
    	
        int[] tmp = in.readIntArray(new int[2]);
    	int n = tmp[0];
    	int q = tmp[1];
    	
    	for(int i=0; i<n; i++) {
    		queue.add(pm.addProcess(in.readStrArray(" ")));
    	}
    	
    	int totalTime = 0;
    	while(!queue.isEmpty()) {
    		int procId = queue.remove();
    		int time = pm.getTime(procId);
    		if(time <= q) {
    			//Process Finish
    			totalTime += time;
    			sb.append(pm.getName(procId)).append(" ").append(totalTime).append(EOF);
    		}else{
    			//Process Continue
    			queue.add(procId);
    			pm.setTime(procId, time - q);
    			totalTime += q;
    		}
    	}
        out.print(sb.toString());
    	out.flush();
    }
} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
  
public class Main {
	private static final String EOF = System.lineSeparator();
	private MyIntQueue queue = new MyIntQueue();
	private ProcessManager pm = new ProcessManager();
    public static void main(String[] args) throws IOException {
        new Main().exec();
    }
    
    public void exec() throws IOException {
    	SimpleInputUtil in = new SimpleInputUtil();
        PrintWriter out = new PrintWriter(System.out);
        StringBuilder sb = new StringBuilder();
    	
        int[] tmp = in.readIntArray(new int[2]);
    	int n = tmp[0];
    	int q = tmp[1];
    	
    	for(int i=0; i<n; i++) {
    		queue.add(pm.addProcess(in.readStrArray(" ")));
    	}
    	
    	int totalTime = 0;
    	while(!queue.isEmpty()) {
    		int procId = queue.remove();
    		int time = pm.getTime(procId);
    		if(time <= q) {
    			//Process Finish
    			totalTime += time;
    			sb.append(pm.getName(procId)).append(" ").append(totalTime).append(EOF);
    		}else{
    			//Process Continue
    			queue.add(procId);
    			pm.setTime(procId, time - q);
    			totalTime += q;
    		}
    	}
        out.print(sb.toString());
    	out.flush();
    }
}

class ProcessManager {
	private static final int CAPACITY = 100000;
	private String[] names = new String[CAPACITY];
	private int[] times = new int[CAPACITY];
	private int ptr = 0;
	
	public int addProcess(String[] procInfo) {
		names[ptr] = procInfo[0];
		times[ptr] = Integer.parseInt(procInfo[1]);
		return ptr++;
	}
	
	public String getName(int procId) {
		return names[procId];
	}
	
	public int getTime(int procId) {
		return times[procId];
	}
	
	public void setTime(int procId, int time) {
		times[procId] = time;
	}
}

class MyIntQueue {
	private static final int CAPACITY = 100000;
	private int[] queue = new int[CAPACITY];
    private int head = 0;
    private int tail = 0;
    
    public boolean isEmpty(){return head == tail;}
    public boolean isFull(){return (head+1)%CAPACITY == tail;}
    
    public int remove() {
    	if(isEmpty()) throw new IllegalStateException();
    	int ret = queue[tail++];
    	tail %= CAPACITY;
    	return ret;
    }
   
    public int add(int value) {
    	if(isFull()) throw new IllegalStateException();
    	int ret =  queue[head++] = value;
    	head %= CAPACITY;
    	return ret;
    }
}

class SimpleInputUtil {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    public String[] readStrArray(String delim) throws NumberFormatException, IOException{
    	return br.readLine().split(delim);
    }
    
    public int readInt() throws NumberFormatException, IOException{
    	return Integer.parseInt(br.readLine());
    }
    
    public int[] readIntArray(int[] a) throws NumberFormatException, IOException{
        int i=0;
        while(i<a.length) {
            for(String s: br.readLine().split(" ")){
            	if(i<a.length) {
                    a[i++] = Integer.parseInt(s);
            	}
            }
        }
        return a;
    }
}