import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

class Main{

	public static void main(String[] args) throws IOException{

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		Queue queue = new Queue();
		String[] input;
		int n, q;
		int end_time = 0;
		String[] name;
		int[] time;

		input = br.readLine().split(" ");
		n = Integer.parseInt(input[0]);
		q = Integer.parseInt(input[1]);
		name = new String[n];
		time = new int[n];

		for(int i = 0; i < n; i++){

			input = br.readLine().split(" ");
			name[i] = input[0];
			time[i] = Integer.parseInt(input[1]);
			queue.enqueue(i);

		}

		while(!queue.isEmpty()){

			int index = queue.dequeue();

			if(time[index] > q){
				end_time += q;
				time[index] -= q;
				queue.enqueue(index);
			}else{
				end_time += time[index];
				time[index] = 0;
				System.out.println(name[index] + " " + end_time);
			}

		}

	}

}

class Queue{

	private int head = 0;
	private int tail = 0;
	private int len = 100000;
	private int[] data = new int[len];

	public void enqueue(int x){

		data[tail] = x;

		if(tail == len - 1){
			tail = 0;
		}else{
			tail++;
		}

	}

	public int dequeue(){

		int x = data[head];

		if(head == len - 1){
			head = 0;
		}else{
			head++;
		}

		return x;

	}

	public boolean isEmpty(){

		if(head == tail){
			return true;
		}else{
			return false;
		}

	}

} import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io import java.io.IOException; IOException java.io class Main{

	public static void main(String[] args) throws IOException{

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		Queue queue = new Queue();
		String[] input;
		int n, q;
		int end_time = 0;
		String[] name;
		int[] time;

		input = br.readLine().split(" ");
		n = Integer.parseInt(input[0]);
		q = Integer.parseInt(input[1]);
		name = new String[n];
		time = new int[n];

		for(int i = 0; i < n; i++){

			input = br.readLine().split(" ");
			name[i] = input[0];
			time[i] = Integer.parseInt(input[1]);
			queue.enqueue(i);

		}

		while(!queue.isEmpty()){

			int index = queue.dequeue();

			if(time[index] > q){
				end_time += q;
				time[index] -= q;
				queue.enqueue(index);
			}else{
				end_time += time[index];
				time[index] = 0;
				System.out.println(name[index] + " " + end_time);
			}

		}

	}

} Main public static void main(String[] args) throws IOException{

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		Queue queue = new Queue();
		String[] input;
		int n, q;
		int end_time = 0;
		String[] name;
		int[] time;

		input = br.readLine().split(" ");
		n = Integer.parseInt(input[0]);
		q = Integer.parseInt(input[1]);
		name = new String[n];
		time = new int[n];

		for(int i = 0; i < n; i++){

			input = br.readLine().split(" ");
			name[i] = input[0];
			time[i] = Integer.parseInt(input[1]);
			queue.enqueue(i);

		}

		while(!queue.isEmpty()){

			int index = queue.dequeue();

			if(time[index] > q){
				end_time += q;
				time[index] -= q;
				queue.enqueue(index);
			}else{
				end_time += time[index];
				time[index] = 0;
				System.out.println(name[index] + " " + end_time);
			}

		}

	} main {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		Queue queue = new Queue();
		String[] input;
		int n, q;
		int end_time = 0;
		String[] name;
		int[] time;

		input = br.readLine().split(" ");
		n = Integer.parseInt(input[0]);
		q = Integer.parseInt(input[1]);
		name = new String[n];
		time = new int[n];

		for(int i = 0; i < n; i++){

			input = br.readLine().split(" ");
			name[i] = input[0];
			time[i] = Integer.parseInt(input[1]);
			queue.enqueue(i);

		}

		while(!queue.isEmpty()){

			int index = queue.dequeue();

			if(time[index] > q){
				end_time += q;
				time[index] -= q;
				queue.enqueue(index);
			}else{
				end_time += time[index];
				time[index] = 0;
				System.out.println(name[index] + " " + end_time);
			}

		}

	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) Queue queue = new Queue(); queue new Queue() String[] input; input int n n q; q int end_time = 0; end_time 0 String[] name; name int[] time; time input = br.readLine().split(" ") input br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " n = Integer.parseInt(input[0]) n Integer.parseInt(input[0]) Integer.parseInt Integer input[0] input 0 q = Integer.parseInt(input[1]) q Integer.parseInt(input[1]) Integer.parseInt Integer input[1] input 1 name = new String[n] name new String[n] n time = new int[n] time new int[n] n for(int i = 0; i < n; i++){

			input = br.readLine().split(" ");
			name[i] = input[0];
			time[i] = Integer.parseInt(input[1]);
			queue.enqueue(i);

		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {

			input = br.readLine().split(" ");
			name[i] = input[0];
			time[i] = Integer.parseInt(input[1]);
			queue.enqueue(i);

		} {

			input = br.readLine().split(" ");
			name[i] = input[0];
			time[i] = Integer.parseInt(input[1]);
			queue.enqueue(i);

		} input = br.readLine().split(" ") input br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " name[i] = input[0] name[i] name i input[0] input 0 time[i] = Integer.parseInt(input[1]) time[i] time i Integer.parseInt(input[1]) Integer.parseInt Integer input[1] input 1 queue.enqueue(i) queue.enqueue queue i while(!queue.isEmpty()){

			int index = queue.dequeue();

			if(time[index] > q){
				end_time += q;
				time[index] -= q;
				queue.enqueue(index);
			}else{
				end_time += time[index];
				time[index] = 0;
				System.out.println(name[index] + " " + end_time);
			}

		} !queue.isEmpty() queue.isEmpty() queue.isEmpty queue {

			int index = queue.dequeue();

			if(time[index] > q){
				end_time += q;
				time[index] -= q;
				queue.enqueue(index);
			}else{
				end_time += time[index];
				time[index] = 0;
				System.out.println(name[index] + " " + end_time);
			}

		} int index = queue.dequeue(); index queue.dequeue() queue.dequeue queue if(time[index] > q){
				end_time += q;
				time[index] -= q;
				queue.enqueue(index);
			}else{
				end_time += time[index];
				time[index] = 0;
				System.out.println(name[index] + " " + end_time);
			} time[index] > q time[index] time index q {
				end_time += q;
				time[index] -= q;
				queue.enqueue(index);
			} end_time += q end_time q time[index] -= q time[index] time index q queue.enqueue(index) queue.enqueue queue index {
				end_time += time[index];
				time[index] = 0;
				System.out.println(name[index] + " " + end_time);
			} end_time += time[index] end_time time[index] time index time[index] = 0 time[index] time index 0 System.out.println(name[index] + " " + end_time) System.out.println System.out System System.out name[index] + " " + end_time name[index] + " " + end_time name[index] name index " " end_time String[] args args class Queue{

	private int head = 0;
	private int tail = 0;
	private int len = 100000;
	private int[] data = new int[len];

	public void enqueue(int x){

		data[tail] = x;

		if(tail == len - 1){
			tail = 0;
		}else{
			tail++;
		}

	}

	public int dequeue(){

		int x = data[head];

		if(head == len - 1){
			head = 0;
		}else{
			head++;
		}

		return x;

	}

	public boolean isEmpty(){

		if(head == tail){
			return true;
		}else{
			return false;
		}

	}

} Queue private int head = 0; head 0 private int tail = 0; tail 0 private int len = 100000; len 100000 private int[] data = new int[len]; data new int[len] len public void enqueue(int x){

		data[tail] = x;

		if(tail == len - 1){
			tail = 0;
		}else{
			tail++;
		}

	} enqueue {

		data[tail] = x;

		if(tail == len - 1){
			tail = 0;
		}else{
			tail++;
		}

	} data[tail] = x data[tail] data tail x if(tail == len - 1){
			tail = 0;
		}else{
			tail++;
		} tail == len - 1 tail len - 1 len 1 {
			tail = 0;
		} tail = 0 tail 0 {
			tail++;
		} tail++ tail int x x public int dequeue(){

		int x = data[head];

		if(head == len - 1){
			head = 0;
		}else{
			head++;
		}

		return x;

	} dequeue {

		int x = data[head];

		if(head == len - 1){
			head = 0;
		}else{
			head++;
		}

		return x;

	} int x = data[head]; x data[head] data head if(head == len - 1){
			head = 0;
		}else{
			head++;
		} head == len - 1 head len - 1 len 1 {
			head = 0;
		} head = 0 head 0 {
			head++;
		} head++ head return x; x public boolean isEmpty(){

		if(head == tail){
			return true;
		}else{
			return false;
		}

	} isEmpty {

		if(head == tail){
			return true;
		}else{
			return false;
		}

	} if(head == tail){
			return true;
		}else{
			return false;
		} head == tail head tail {
			return true;
		} return true; true {
			return false;
		} return false; false
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

class Main{

	public static void main(String[] args) throws IOException{

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		Queue queue = new Queue();
		String[] input;
		int n, q;
		int end_time = 0;
		String[] name;
		int[] time;

		input = br.readLine().split(" ");
		n = Integer.parseInt(input[0]);
		q = Integer.parseInt(input[1]);
		name = new String[n];
		time = new int[n];

		for(int i = 0; i < n; i++){

			input = br.readLine().split(" ");
			name[i] = input[0];
			time[i] = Integer.parseInt(input[1]);
			queue.enqueue(i);

		}

		while(!queue.isEmpty()){

			int index = queue.dequeue();

			if(time[index] > q){
				end_time += q;
				time[index] -= q;
				queue.enqueue(index);
			}else{
				end_time += time[index];
				time[index] = 0;
				System.out.println(name[index] + " " + end_time);
			}

		}

	}

}

class Queue{

	private int head = 0;
	private int tail = 0;
	private int len = 100000;
	private int[] data = new int[len];

	public void enqueue(int x){

		data[tail] = x;

		if(tail == len - 1){
			tail = 0;
		}else{
			tail++;
		}

	}

	public int dequeue(){

		int x = data[head];

		if(head == len - 1){
			head = 0;
		}else{
			head++;
		}

		return x;

	}

	public boolean isEmpty(){

		if(head == tail){
			return true;
		}else{
			return false;
		}

	}

}