import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Queue;

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO ?????????????????????????????????????????????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String[] strArray = br.readLine().split(" ");
		
		int n = Integer.parseInt(strArray[0]);
		int q = Integer.parseInt(strArray[1]);
		
		Queue<Process> queue = new ArrayDeque<Process>();
		for(int i = 0; i < n ;i++){
			strArray = br.readLine().split(" ");
			queue.add(new Process(strArray[0], Integer.parseInt(strArray[1])));
		}
		
		int currentTime = 0;
		while(queue.size() > 0){
			if(queue.element().remainTime > q){
				queue.element().remainTime -= q;
				queue.add(queue.poll());
				currentTime += q;
			}
			else{
				currentTime += queue.element().remainTime;
				System.out.println(queue.element().name + " " + currentTime);
				queue.poll();
			}
			
		}
	}

}

class Process {
	String name;
	int remainTime;
	int finishedTime;
	
	public Process (String name, int time){
		this.name = name;
		this.remainTime = time;
	}
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io import java.util.ArrayDeque; ArrayDeque java.util import java.util.Queue; Queue java.util public class Main {

	public static void main(String[] args) throws IOException {
		// TODO ?????????????????????????????????????????????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String[] strArray = br.readLine().split(" ");
		
		int n = Integer.parseInt(strArray[0]);
		int q = Integer.parseInt(strArray[1]);
		
		Queue<Process> queue = new ArrayDeque<Process>();
		for(int i = 0; i < n ;i++){
			strArray = br.readLine().split(" ");
			queue.add(new Process(strArray[0], Integer.parseInt(strArray[1])));
		}
		
		int currentTime = 0;
		while(queue.size() > 0){
			if(queue.element().remainTime > q){
				queue.element().remainTime -= q;
				queue.add(queue.poll());
				currentTime += q;
			}
			else{
				currentTime += queue.element().remainTime;
				System.out.println(queue.element().name + " " + currentTime);
				queue.poll();
			}
			
		}
	}

} Main public static void main(String[] args) throws IOException {
		// TODO ?????????????????????????????????????????????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String[] strArray = br.readLine().split(" ");
		
		int n = Integer.parseInt(strArray[0]);
		int q = Integer.parseInt(strArray[1]);
		
		Queue<Process> queue = new ArrayDeque<Process>();
		for(int i = 0; i < n ;i++){
			strArray = br.readLine().split(" ");
			queue.add(new Process(strArray[0], Integer.parseInt(strArray[1])));
		}
		
		int currentTime = 0;
		while(queue.size() > 0){
			if(queue.element().remainTime > q){
				queue.element().remainTime -= q;
				queue.add(queue.poll());
				currentTime += q;
			}
			else{
				currentTime += queue.element().remainTime;
				System.out.println(queue.element().name + " " + currentTime);
				queue.poll();
			}
			
		}
	} main {
		// TODO ?????????????????????????????????????????????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String[] strArray = br.readLine().split(" ");
		
		int n = Integer.parseInt(strArray[0]);
		int q = Integer.parseInt(strArray[1]);
		
		Queue<Process> queue = new ArrayDeque<Process>();
		for(int i = 0; i < n ;i++){
			strArray = br.readLine().split(" ");
			queue.add(new Process(strArray[0], Integer.parseInt(strArray[1])));
		}
		
		int currentTime = 0;
		while(queue.size() > 0){
			if(queue.element().remainTime > q){
				queue.element().remainTime -= q;
				queue.add(queue.poll());
				currentTime += q;
			}
			else{
				currentTime += queue.element().remainTime;
				System.out.println(queue.element().name + " " + currentTime);
				queue.poll();
			}
			
		}
	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) String[] strArray = br.readLine().split(" "); strArray br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " int n = Integer.parseInt(strArray[0]); n Integer.parseInt(strArray[0]) Integer.parseInt Integer strArray[0] strArray 0 int q = Integer.parseInt(strArray[1]); q Integer.parseInt(strArray[1]) Integer.parseInt Integer strArray[1] strArray 1 Queue<Process> queue = new ArrayDeque<Process>(); queue new ArrayDeque<Process>() for(int i = 0; i < n ;i++){
			strArray = br.readLine().split(" ");
			queue.add(new Process(strArray[0], Integer.parseInt(strArray[1])));
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			strArray = br.readLine().split(" ");
			queue.add(new Process(strArray[0], Integer.parseInt(strArray[1])));
		} {
			strArray = br.readLine().split(" ");
			queue.add(new Process(strArray[0], Integer.parseInt(strArray[1])));
		} strArray = br.readLine().split(" ") strArray br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " queue.add(new Process(strArray[0], Integer.parseInt(strArray[1]))) queue.add queue new Process(strArray[0], Integer.parseInt(strArray[1])) int currentTime = 0; currentTime 0 while(queue.size() > 0){
			if(queue.element().remainTime > q){
				queue.element().remainTime -= q;
				queue.add(queue.poll());
				currentTime += q;
			}
			else{
				currentTime += queue.element().remainTime;
				System.out.println(queue.element().name + " " + currentTime);
				queue.poll();
			}
			
		} queue.size() > 0 queue.size() queue.size queue 0 {
			if(queue.element().remainTime > q){
				queue.element().remainTime -= q;
				queue.add(queue.poll());
				currentTime += q;
			}
			else{
				currentTime += queue.element().remainTime;
				System.out.println(queue.element().name + " " + currentTime);
				queue.poll();
			}
			
		} if(queue.element().remainTime > q){
				queue.element().remainTime -= q;
				queue.add(queue.poll());
				currentTime += q;
			}
			else{
				currentTime += queue.element().remainTime;
				System.out.println(queue.element().name + " " + currentTime);
				queue.poll();
			} queue.element().remainTime > q queue.element().remainTime queue.element() queue.element queue queue.element().remainTime q {
				queue.element().remainTime -= q;
				queue.add(queue.poll());
				currentTime += q;
			} queue.element().remainTime -= q queue.element().remainTime queue.element() queue.element queue queue.element().remainTime q queue.add(queue.poll()) queue.add queue queue.poll() queue.poll queue currentTime += q currentTime q {
				currentTime += queue.element().remainTime;
				System.out.println(queue.element().name + " " + currentTime);
				queue.poll();
			} currentTime += queue.element().remainTime currentTime queue.element().remainTime queue.element() queue.element queue queue.element().remainTime System.out.println(queue.element().name + " " + currentTime) System.out.println System.out System System.out queue.element().name + " " + currentTime queue.element().name + " " + currentTime queue.element().name queue.element() queue.element queue queue.element().name " " currentTime queue.poll() queue.poll queue String[] args args class Process {
	String name;
	int remainTime;
	int finishedTime;
	
	public Process (String name, int time){
		this.name = name;
		this.remainTime = time;
	}
} Process String name; name int remainTime; remainTime int finishedTime; finishedTime public Process (String name, int time){
		this.name = name;
		this.remainTime = time;
	} Process {
		this.name = name;
		this.remainTime = time;
	} this.name = name this.name this this.name name this.remainTime = time this.remainTime this this.remainTime time String name name int time time public class Main {

	public static void main(String[] args) throws IOException {
		// TODO ?????????????????????????????????????????????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String[] strArray = br.readLine().split(" ");
		
		int n = Integer.parseInt(strArray[0]);
		int q = Integer.parseInt(strArray[1]);
		
		Queue<Process> queue = new ArrayDeque<Process>();
		for(int i = 0; i < n ;i++){
			strArray = br.readLine().split(" ");
			queue.add(new Process(strArray[0], Integer.parseInt(strArray[1])));
		}
		
		int currentTime = 0;
		while(queue.size() > 0){
			if(queue.element().remainTime > q){
				queue.element().remainTime -= q;
				queue.add(queue.poll());
				currentTime += q;
			}
			else{
				currentTime += queue.element().remainTime;
				System.out.println(queue.element().name + " " + currentTime);
				queue.poll();
			}
			
		}
	}

} public class Main {

	public static void main(String[] args) throws IOException {
		// TODO ?????????????????????????????????????????????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String[] strArray = br.readLine().split(" ");
		
		int n = Integer.parseInt(strArray[0]);
		int q = Integer.parseInt(strArray[1]);
		
		Queue<Process> queue = new ArrayDeque<Process>();
		for(int i = 0; i < n ;i++){
			strArray = br.readLine().split(" ");
			queue.add(new Process(strArray[0], Integer.parseInt(strArray[1])));
		}
		
		int currentTime = 0;
		while(queue.size() > 0){
			if(queue.element().remainTime > q){
				queue.element().remainTime -= q;
				queue.add(queue.poll());
				currentTime += q;
			}
			else{
				currentTime += queue.element().remainTime;
				System.out.println(queue.element().name + " " + currentTime);
				queue.poll();
			}
			
		}
	}

} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Queue;

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO ?????????????????????????????????????????????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String[] strArray = br.readLine().split(" ");
		
		int n = Integer.parseInt(strArray[0]);
		int q = Integer.parseInt(strArray[1]);
		
		Queue<Process> queue = new ArrayDeque<Process>();
		for(int i = 0; i < n ;i++){
			strArray = br.readLine().split(" ");
			queue.add(new Process(strArray[0], Integer.parseInt(strArray[1])));
		}
		
		int currentTime = 0;
		while(queue.size() > 0){
			if(queue.element().remainTime > q){
				queue.element().remainTime -= q;
				queue.add(queue.poll());
				currentTime += q;
			}
			else{
				currentTime += queue.element().remainTime;
				System.out.println(queue.element().name + " " + currentTime);
				queue.poll();
			}
			
		}
	}

}

class Process {
	String name;
	int remainTime;
	int finishedTime;
	
	public Process (String name, int time){
		this.name = name;
		this.remainTime = time;
	}
}