
import java.util.Scanner;

/*
 * ??\?????????
5 100
p1 150
p2 80
p3 200
p4 350
p5 20
 */
public class Main{

    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int totalTime = 0;
        int n = scanner.nextInt();
        int q = scanner.nextInt();
        
        int[] A = new int[n];
        Queue queue = new Queue(n);
        
        for(int i=1;i<=n;i++){
            Process process = new Process(scanner.next(),scanner.nextInt());
            queue.enqueue(process);
        }
        while(true){
        	Process p= queue.dequeue();
        	if(p==null){
        		break;
        	}
        	int time =p.getProcessTime();
        	int remainingTime = time-q;
        	if(remainingTime <=0){
        		totalTime += time;
        		System.out.println(p.getProcessName()+" "+totalTime);
        	}else{
        		totalTime += q;
        		p.setProcessTime(time-q);
        		queue.enqueue(p);
        	}
        }
    }
}
class Queue{
	int startIndex;
	int endIndex;
	int size;
    String[] queueName;
    int[] queueTime;
    
	Queue(int n){
    	startIndex =0;
    	endIndex = 0;
    	size = n;
        queueName = new String[n];
        queueTime = new int[n];
	}
	void enqueue(Process process){
		//System.out.println("??¨????????\???"+process.getProcessName()+","+process.getProcessTime());

		queueName[endIndex]=process.getProcessName();
		queueTime[endIndex]=process.getProcessTime();
		endIndex++;
		endIndex %= size;
	}
	Process dequeue(){
		//System.out.println("????????\???"+queueName[startIndex]+","+queueTime[startIndex]);
		if(queueName[startIndex].equals("")){
			return null;
		}
		Process process = new Process(queueName[startIndex],queueTime[startIndex]);
		queueName[startIndex]="";
		startIndex++;
		startIndex %= size;
		return process;
	}
}

class Process{
	private String processName;
	private int processTime;
	Process(String processName,int processTime){
		this.processName = processName;
		this.processTime = processTime;
	}
	String getProcessName(){
		return processName;
	}
	void setProcessName(String processName){
		this.processName = processName;
	}
	public int getProcessTime() {
		return processTime;
	}
	public void setProcessTime(int processTime) {
		this.processTime = processTime;
	}

	
} import java.util.Scanner; Scanner java.util public class Main{

    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int totalTime = 0;
        int n = scanner.nextInt();
        int q = scanner.nextInt();
        
        int[] A = new int[n];
        Queue queue = new Queue(n);
        
        for(int i=1;i<=n;i++){
            Process process = new Process(scanner.next(),scanner.nextInt());
            queue.enqueue(process);
        }
        while(true){
        	Process p= queue.dequeue();
        	if(p==null){
        		break;
        	}
        	int time =p.getProcessTime();
        	int remainingTime = time-q;
        	if(remainingTime <=0){
        		totalTime += time;
        		System.out.println(p.getProcessName()+" "+totalTime);
        	}else{
        		totalTime += q;
        		p.setProcessTime(time-q);
        		queue.enqueue(p);
        	}
        }
    }
} Main public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int totalTime = 0;
        int n = scanner.nextInt();
        int q = scanner.nextInt();
        
        int[] A = new int[n];
        Queue queue = new Queue(n);
        
        for(int i=1;i<=n;i++){
            Process process = new Process(scanner.next(),scanner.nextInt());
            queue.enqueue(process);
        }
        while(true){
        	Process p= queue.dequeue();
        	if(p==null){
        		break;
        	}
        	int time =p.getProcessTime();
        	int remainingTime = time-q;
        	if(remainingTime <=0){
        		totalTime += time;
        		System.out.println(p.getProcessName()+" "+totalTime);
        	}else{
        		totalTime += q;
        		p.setProcessTime(time-q);
        		queue.enqueue(p);
        	}
        }
    } main {
        Scanner scanner = new Scanner(System.in);
        int totalTime = 0;
        int n = scanner.nextInt();
        int q = scanner.nextInt();
        
        int[] A = new int[n];
        Queue queue = new Queue(n);
        
        for(int i=1;i<=n;i++){
            Process process = new Process(scanner.next(),scanner.nextInt());
            queue.enqueue(process);
        }
        while(true){
        	Process p= queue.dequeue();
        	if(p==null){
        		break;
        	}
        	int time =p.getProcessTime();
        	int remainingTime = time-q;
        	if(remainingTime <=0){
        		totalTime += time;
        		System.out.println(p.getProcessName()+" "+totalTime);
        	}else{
        		totalTime += q;
        		p.setProcessTime(time-q);
        		queue.enqueue(p);
        	}
        }
    } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int totalTime = 0; totalTime 0 int n = scanner.nextInt(); n scanner.nextInt() scanner.nextInt scanner int q = scanner.nextInt(); q scanner.nextInt() scanner.nextInt scanner int[] A = new int[n]; A new int[n] n Queue queue = new Queue(n); queue new Queue(n) for(int i=1;i<=n;i++){
            Process process = new Process(scanner.next(),scanner.nextInt());
            queue.enqueue(process);
        } int i=1; int i=1; i 1 i<=n i n i++ i++ i {
            Process process = new Process(scanner.next(),scanner.nextInt());
            queue.enqueue(process);
        } {
            Process process = new Process(scanner.next(),scanner.nextInt());
            queue.enqueue(process);
        } Process process = new Process(scanner.next(),scanner.nextInt()); process new Process(scanner.next(),scanner.nextInt()) queue.enqueue(process) queue.enqueue queue process while(true){
        	Process p= queue.dequeue();
        	if(p==null){
        		break;
        	}
        	int time =p.getProcessTime();
        	int remainingTime = time-q;
        	if(remainingTime <=0){
        		totalTime += time;
        		System.out.println(p.getProcessName()+" "+totalTime);
        	}else{
        		totalTime += q;
        		p.setProcessTime(time-q);
        		queue.enqueue(p);
        	}
        } true {
        	Process p= queue.dequeue();
        	if(p==null){
        		break;
        	}
        	int time =p.getProcessTime();
        	int remainingTime = time-q;
        	if(remainingTime <=0){
        		totalTime += time;
        		System.out.println(p.getProcessName()+" "+totalTime);
        	}else{
        		totalTime += q;
        		p.setProcessTime(time-q);
        		queue.enqueue(p);
        	}
        } Process p= queue.dequeue(); p queue.dequeue() queue.dequeue queue if(p==null){
        		break;
        	} p==null p null {
        		break;
        	} break; int time =p.getProcessTime(); time p.getProcessTime() p.getProcessTime p int remainingTime = time-q; remainingTime time-q time q if(remainingTime <=0){
        		totalTime += time;
        		System.out.println(p.getProcessName()+" "+totalTime);
        	}else{
        		totalTime += q;
        		p.setProcessTime(time-q);
        		queue.enqueue(p);
        	} remainingTime <=0 remainingTime 0 {
        		totalTime += time;
        		System.out.println(p.getProcessName()+" "+totalTime);
        	} totalTime += time totalTime time System.out.println(p.getProcessName()+" "+totalTime) System.out.println System.out System System.out p.getProcessName()+" "+totalTime p.getProcessName()+" "+totalTime p.getProcessName() p.getProcessName p " " totalTime {
        		totalTime += q;
        		p.setProcessTime(time-q);
        		queue.enqueue(p);
        	} totalTime += q totalTime q p.setProcessTime(time-q) p.setProcessTime p time-q time q queue.enqueue(p) queue.enqueue queue p String[] args args class Queue{
	int startIndex;
	int endIndex;
	int size;
    String[] queueName;
    int[] queueTime;
    
	Queue(int n){
    	startIndex =0;
    	endIndex = 0;
    	size = n;
        queueName = new String[n];
        queueTime = new int[n];
	}
	void enqueue(Process process){
		//System.out.println("??¨????????\???"+process.getProcessName()+","+process.getProcessTime());

		queueName[endIndex]=process.getProcessName();
		queueTime[endIndex]=process.getProcessTime();
		endIndex++;
		endIndex %= size;
	}
	Process dequeue(){
		//System.out.println("????????\???"+queueName[startIndex]+","+queueTime[startIndex]);
		if(queueName[startIndex].equals("")){
			return null;
		}
		Process process = new Process(queueName[startIndex],queueTime[startIndex]);
		queueName[startIndex]="";
		startIndex++;
		startIndex %= size;
		return process;
	}
} Queue int startIndex; startIndex int endIndex; endIndex int size; size String[] queueName; queueName int[] queueTime; queueTime Queue(int n){
    	startIndex =0;
    	endIndex = 0;
    	size = n;
        queueName = new String[n];
        queueTime = new int[n];
	} Queue {
    	startIndex =0;
    	endIndex = 0;
    	size = n;
        queueName = new String[n];
        queueTime = new int[n];
	} startIndex =0 startIndex 0 endIndex = 0 endIndex 0 size = n size n queueName = new String[n] queueName new String[n] n queueTime = new int[n] queueTime new int[n] n int n n void enqueue(Process process){
		//System.out.println("??¨????????\???"+process.getProcessName()+","+process.getProcessTime());

		queueName[endIndex]=process.getProcessName();
		queueTime[endIndex]=process.getProcessTime();
		endIndex++;
		endIndex %= size;
	} enqueue {
		//System.out.println("??¨????????\???"+process.getProcessName()+","+process.getProcessTime());

		queueName[endIndex]=process.getProcessName();
		queueTime[endIndex]=process.getProcessTime();
		endIndex++;
		endIndex %= size;
	} queueName[endIndex]=process.getProcessName() queueName[endIndex] queueName endIndex process.getProcessName() process.getProcessName process queueTime[endIndex]=process.getProcessTime() queueTime[endIndex] queueTime endIndex process.getProcessTime() process.getProcessTime process endIndex++ endIndex endIndex %= size endIndex size Process process process Process dequeue(){
		//System.out.println("????????\???"+queueName[startIndex]+","+queueTime[startIndex]);
		if(queueName[startIndex].equals("")){
			return null;
		}
		Process process = new Process(queueName[startIndex],queueTime[startIndex]);
		queueName[startIndex]="";
		startIndex++;
		startIndex %= size;
		return process;
	} dequeue {
		//System.out.println("????????\???"+queueName[startIndex]+","+queueTime[startIndex]);
		if(queueName[startIndex].equals("")){
			return null;
		}
		Process process = new Process(queueName[startIndex],queueTime[startIndex]);
		queueName[startIndex]="";
		startIndex++;
		startIndex %= size;
		return process;
	} if(queueName[startIndex].equals("")){
			return null;
		} queueName[startIndex].equals("") queueName[startIndex].equals queueName[startIndex] queueName startIndex "" {
			return null;
		} return null; null Process process = new Process(queueName[startIndex],queueTime[startIndex]); process new Process(queueName[startIndex],queueTime[startIndex]) queueName[startIndex]="" queueName[startIndex] queueName startIndex "" startIndex++ startIndex startIndex %= size startIndex size return process; process class Process{
	private String processName;
	private int processTime;
	Process(String processName,int processTime){
		this.processName = processName;
		this.processTime = processTime;
	}
	String getProcessName(){
		return processName;
	}
	void setProcessName(String processName){
		this.processName = processName;
	}
	public int getProcessTime() {
		return processTime;
	}
	public void setProcessTime(int processTime) {
		this.processTime = processTime;
	}

	
} Process private String processName; processName private int processTime; processTime Process(String processName,int processTime){
		this.processName = processName;
		this.processTime = processTime;
	} Process {
		this.processName = processName;
		this.processTime = processTime;
	} this.processName = processName this.processName this this.processName processName this.processTime = processTime this.processTime this this.processTime processTime String processName processName int processTime processTime String getProcessName(){
		return processName;
	} getProcessName {
		return processName;
	} return processName; processName void setProcessName(String processName){
		this.processName = processName;
	} setProcessName {
		this.processName = processName;
	} this.processName = processName this.processName this this.processName processName String processName processName public int getProcessTime() {
		return processTime;
	} getProcessTime {
		return processTime;
	} return processTime; processTime public void setProcessTime(int processTime) {
		this.processTime = processTime;
	} setProcessTime {
		this.processTime = processTime;
	} this.processTime = processTime this.processTime this this.processTime processTime int processTime processTime public class Main{

    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int totalTime = 0;
        int n = scanner.nextInt();
        int q = scanner.nextInt();
        
        int[] A = new int[n];
        Queue queue = new Queue(n);
        
        for(int i=1;i<=n;i++){
            Process process = new Process(scanner.next(),scanner.nextInt());
            queue.enqueue(process);
        }
        while(true){
        	Process p= queue.dequeue();
        	if(p==null){
        		break;
        	}
        	int time =p.getProcessTime();
        	int remainingTime = time-q;
        	if(remainingTime <=0){
        		totalTime += time;
        		System.out.println(p.getProcessName()+" "+totalTime);
        	}else{
        		totalTime += q;
        		p.setProcessTime(time-q);
        		queue.enqueue(p);
        	}
        }
    }
} public class Main{

    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int totalTime = 0;
        int n = scanner.nextInt();
        int q = scanner.nextInt();
        
        int[] A = new int[n];
        Queue queue = new Queue(n);
        
        for(int i=1;i<=n;i++){
            Process process = new Process(scanner.next(),scanner.nextInt());
            queue.enqueue(process);
        }
        while(true){
        	Process p= queue.dequeue();
        	if(p==null){
        		break;
        	}
        	int time =p.getProcessTime();
        	int remainingTime = time-q;
        	if(remainingTime <=0){
        		totalTime += time;
        		System.out.println(p.getProcessName()+" "+totalTime);
        	}else{
        		totalTime += q;
        		p.setProcessTime(time-q);
        		queue.enqueue(p);
        	}
        }
    }
} Main

import java.util.Scanner;

/*
 * ??\?????????
5 100
p1 150
p2 80
p3 200
p4 350
p5 20
 */
public class Main{

    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int totalTime = 0;
        int n = scanner.nextInt();
        int q = scanner.nextInt();
        
        int[] A = new int[n];
        Queue queue = new Queue(n);
        
        for(int i=1;i<=n;i++){
            Process process = new Process(scanner.next(),scanner.nextInt());
            queue.enqueue(process);
        }
        while(true){
        	Process p= queue.dequeue();
        	if(p==null){
        		break;
        	}
        	int time =p.getProcessTime();
        	int remainingTime = time-q;
        	if(remainingTime <=0){
        		totalTime += time;
        		System.out.println(p.getProcessName()+" "+totalTime);
        	}else{
        		totalTime += q;
        		p.setProcessTime(time-q);
        		queue.enqueue(p);
        	}
        }
    }
}
class Queue{
	int startIndex;
	int endIndex;
	int size;
    String[] queueName;
    int[] queueTime;
    
	Queue(int n){
    	startIndex =0;
    	endIndex = 0;
    	size = n;
        queueName = new String[n];
        queueTime = new int[n];
	}
	void enqueue(Process process){
		//System.out.println("??¨????????\???"+process.getProcessName()+","+process.getProcessTime());

		queueName[endIndex]=process.getProcessName();
		queueTime[endIndex]=process.getProcessTime();
		endIndex++;
		endIndex %= size;
	}
	Process dequeue(){
		//System.out.println("????????\???"+queueName[startIndex]+","+queueTime[startIndex]);
		if(queueName[startIndex].equals("")){
			return null;
		}
		Process process = new Process(queueName[startIndex],queueTime[startIndex]);
		queueName[startIndex]="";
		startIndex++;
		startIndex %= size;
		return process;
	}
}

class Process{
	private String processName;
	private int processTime;
	Process(String processName,int processTime){
		this.processName = processName;
		this.processTime = processTime;
	}
	String getProcessName(){
		return processName;
	}
	void setProcessName(String processName){
		this.processName = processName;
	}
	public int getProcessTime() {
		return processTime;
	}
	public void setProcessTime(int processTime) {
		this.processTime = processTime;
	}

	
}