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

public class Main{




	public static void main(String[] args){

		String array[];

		BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));

		try{
		String str=reader.readLine();
		array=str.split(" ");
		int num=Integer.parseInt(array[0]);
		int q=Integer.parseInt(array[1]);
		int sum=0;
		Queue queue=new Queue(num);

		String x;
		int y;



		for(int i=0;i<num;i++){
			str=reader.readLine();
			queue.enqueue(str);
		}

		while(queue.num!=0){
			str=queue.dequeue();
			 array=str.split(" ");
			    x=array[0];
				y=Integer.parseInt(array[1]);

			    if(y>q){
			    	y=y-q;
			    	sum+=q;
			    	queue.enqueue(x+" "+y);
			    	} else{

			    	sum+=y;
			          System.out.println(x+" "+sum);
			    }
		}






		}catch(IOException e){

		}

	}//main
}

class Queue{
	int max;
	int num;
	String[] array;
	int front, rear;

	Queue(int capacity){//?????????????????????
		max=capacity;
		num=rear=front=0;
		array=new String[max];
	}
	public void enqueue(String str){
		array[rear++]=str;
		num++;
		if(rear==max)rear=0;
	}

	public String dequeue(){
		String str=array[front++];
		num--;
		if(front==max)front=0;

		return str;
	}

}//stack????????? import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main{




	public static void main(String[] args){

		String array[];

		BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));

		try{
		String str=reader.readLine();
		array=str.split(" ");
		int num=Integer.parseInt(array[0]);
		int q=Integer.parseInt(array[1]);
		int sum=0;
		Queue queue=new Queue(num);

		String x;
		int y;



		for(int i=0;i<num;i++){
			str=reader.readLine();
			queue.enqueue(str);
		}

		while(queue.num!=0){
			str=queue.dequeue();
			 array=str.split(" ");
			    x=array[0];
				y=Integer.parseInt(array[1]);

			    if(y>q){
			    	y=y-q;
			    	sum+=q;
			    	queue.enqueue(x+" "+y);
			    	} else{

			    	sum+=y;
			          System.out.println(x+" "+sum);
			    }
		}






		}catch(IOException e){

		}

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

		String array[];

		BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));

		try{
		String str=reader.readLine();
		array=str.split(" ");
		int num=Integer.parseInt(array[0]);
		int q=Integer.parseInt(array[1]);
		int sum=0;
		Queue queue=new Queue(num);

		String x;
		int y;



		for(int i=0;i<num;i++){
			str=reader.readLine();
			queue.enqueue(str);
		}

		while(queue.num!=0){
			str=queue.dequeue();
			 array=str.split(" ");
			    x=array[0];
				y=Integer.parseInt(array[1]);

			    if(y>q){
			    	y=y-q;
			    	sum+=q;
			    	queue.enqueue(x+" "+y);
			    	} else{

			    	sum+=y;
			          System.out.println(x+" "+sum);
			    }
		}






		}catch(IOException e){

		}

	}//main main {

		String array[];

		BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));

		try{
		String str=reader.readLine();
		array=str.split(" ");
		int num=Integer.parseInt(array[0]);
		int q=Integer.parseInt(array[1]);
		int sum=0;
		Queue queue=new Queue(num);

		String x;
		int y;



		for(int i=0;i<num;i++){
			str=reader.readLine();
			queue.enqueue(str);
		}

		while(queue.num!=0){
			str=queue.dequeue();
			 array=str.split(" ");
			    x=array[0];
				y=Integer.parseInt(array[1]);

			    if(y>q){
			    	y=y-q;
			    	sum+=q;
			    	queue.enqueue(x+" "+y);
			    	} else{

			    	sum+=y;
			          System.out.println(x+" "+sum);
			    }
		}






		}catch(IOException e){

		}

	} String array[]; array BufferedReader reader=new BufferedReader(new InputStreamReader(System.in)); reader new BufferedReader(new InputStreamReader(System.in)) try{
		String str=reader.readLine();
		array=str.split(" ");
		int num=Integer.parseInt(array[0]);
		int q=Integer.parseInt(array[1]);
		int sum=0;
		Queue queue=new Queue(num);

		String x;
		int y;



		for(int i=0;i<num;i++){
			str=reader.readLine();
			queue.enqueue(str);
		}

		while(queue.num!=0){
			str=queue.dequeue();
			 array=str.split(" ");
			    x=array[0];
				y=Integer.parseInt(array[1]);

			    if(y>q){
			    	y=y-q;
			    	sum+=q;
			    	queue.enqueue(x+" "+y);
			    	} else{

			    	sum+=y;
			          System.out.println(x+" "+sum);
			    }
		}






		}catch(IOException e){

		} catch(IOException e){

		} IOException e {

		} {
		String str=reader.readLine();
		array=str.split(" ");
		int num=Integer.parseInt(array[0]);
		int q=Integer.parseInt(array[1]);
		int sum=0;
		Queue queue=new Queue(num);

		String x;
		int y;



		for(int i=0;i<num;i++){
			str=reader.readLine();
			queue.enqueue(str);
		}

		while(queue.num!=0){
			str=queue.dequeue();
			 array=str.split(" ");
			    x=array[0];
				y=Integer.parseInt(array[1]);

			    if(y>q){
			    	y=y-q;
			    	sum+=q;
			    	queue.enqueue(x+" "+y);
			    	} else{

			    	sum+=y;
			          System.out.println(x+" "+sum);
			    }
		}






		} String str=reader.readLine(); str reader.readLine() reader.readLine reader array=str.split(" ") array str.split(" ") str.split str " " int num=Integer.parseInt(array[0]); num Integer.parseInt(array[0]) Integer.parseInt Integer array[0] array 0 int q=Integer.parseInt(array[1]); q Integer.parseInt(array[1]) Integer.parseInt Integer array[1] array 1 int sum=0; sum 0 Queue queue=new Queue(num); queue new Queue(num) String x; x int y; y for(int i=0;i<num;i++){
			str=reader.readLine();
			queue.enqueue(str);
		} int i=0; int i=0; i 0 i<num i num i++ i++ i {
			str=reader.readLine();
			queue.enqueue(str);
		} {
			str=reader.readLine();
			queue.enqueue(str);
		} str=reader.readLine() str reader.readLine() reader.readLine reader queue.enqueue(str) queue.enqueue queue str while(queue.num!=0){
			str=queue.dequeue();
			 array=str.split(" ");
			    x=array[0];
				y=Integer.parseInt(array[1]);

			    if(y>q){
			    	y=y-q;
			    	sum+=q;
			    	queue.enqueue(x+" "+y);
			    	} else{

			    	sum+=y;
			          System.out.println(x+" "+sum);
			    }
		} queue.num!=0 queue.num queue queue.num 0 {
			str=queue.dequeue();
			 array=str.split(" ");
			    x=array[0];
				y=Integer.parseInt(array[1]);

			    if(y>q){
			    	y=y-q;
			    	sum+=q;
			    	queue.enqueue(x+" "+y);
			    	} else{

			    	sum+=y;
			          System.out.println(x+" "+sum);
			    }
		} str=queue.dequeue() str queue.dequeue() queue.dequeue queue array=str.split(" ") array str.split(" ") str.split str " " x=array[0] x array[0] array 0 y=Integer.parseInt(array[1]) y Integer.parseInt(array[1]) Integer.parseInt Integer array[1] array 1 if(y>q){
			    	y=y-q;
			    	sum+=q;
			    	queue.enqueue(x+" "+y);
			    	} else{

			    	sum+=y;
			          System.out.println(x+" "+sum);
			    } y>q y q {
			    	y=y-q;
			    	sum+=q;
			    	queue.enqueue(x+" "+y);
			    	} y=y-q y y-q y q sum+=q sum q queue.enqueue(x+" "+y) queue.enqueue queue x+" "+y x+" "+y x " " y {

			    	sum+=y;
			          System.out.println(x+" "+sum);
			    } sum+=y sum y System.out.println(x+" "+sum) System.out.println System.out System System.out x+" "+sum x+" "+sum x " " sum String[] args args class Queue{
	int max;
	int num;
	String[] array;
	int front, rear;

	Queue(int capacity){//?????????????????????
		max=capacity;
		num=rear=front=0;
		array=new String[max];
	}
	public void enqueue(String str){
		array[rear++]=str;
		num++;
		if(rear==max)rear=0;
	}

	public String dequeue(){
		String str=array[front++];
		num--;
		if(front==max)front=0;

		return str;
	}

}//stack????????? Queue int max; max int num; num String[] array; array int front front rear; rear Queue(int capacity){//?????????????????????
		max=capacity;
		num=rear=front=0;
		array=new String[max];
	} Queue {//?????????????????????
		max=capacity;
		num=rear=front=0;
		array=new String[max];
	} max=capacity max capacity num=rear=front=0 num rear=front=0 rear front=0 front 0 array=new String[max] array new String[max] max int capacity capacity public void enqueue(String str){
		array[rear++]=str;
		num++;
		if(rear==max)rear=0;
	} enqueue {
		array[rear++]=str;
		num++;
		if(rear==max)rear=0;
	} array[rear++]=str array[rear++] array rear++ rear str num++ num if(rear==max)rear=0; rear==max rear max rear=0 rear 0 String str str public String dequeue(){
		String str=array[front++];
		num--;
		if(front==max)front=0;

		return str;
	} dequeue {
		String str=array[front++];
		num--;
		if(front==max)front=0;

		return str;
	} String str=array[front++]; str array[front++] array front++ front num-- num if(front==max)front=0; front==max front max front=0 front 0 return str; str public class Main{




	public static void main(String[] args){

		String array[];

		BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));

		try{
		String str=reader.readLine();
		array=str.split(" ");
		int num=Integer.parseInt(array[0]);
		int q=Integer.parseInt(array[1]);
		int sum=0;
		Queue queue=new Queue(num);

		String x;
		int y;



		for(int i=0;i<num;i++){
			str=reader.readLine();
			queue.enqueue(str);
		}

		while(queue.num!=0){
			str=queue.dequeue();
			 array=str.split(" ");
			    x=array[0];
				y=Integer.parseInt(array[1]);

			    if(y>q){
			    	y=y-q;
			    	sum+=q;
			    	queue.enqueue(x+" "+y);
			    	} else{

			    	sum+=y;
			          System.out.println(x+" "+sum);
			    }
		}






		}catch(IOException e){

		}

	}//main
} public class Main{




	public static void main(String[] args){

		String array[];

		BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));

		try{
		String str=reader.readLine();
		array=str.split(" ");
		int num=Integer.parseInt(array[0]);
		int q=Integer.parseInt(array[1]);
		int sum=0;
		Queue queue=new Queue(num);

		String x;
		int y;



		for(int i=0;i<num;i++){
			str=reader.readLine();
			queue.enqueue(str);
		}

		while(queue.num!=0){
			str=queue.dequeue();
			 array=str.split(" ");
			    x=array[0];
				y=Integer.parseInt(array[1]);

			    if(y>q){
			    	y=y-q;
			    	sum+=q;
			    	queue.enqueue(x+" "+y);
			    	} else{

			    	sum+=y;
			          System.out.println(x+" "+sum);
			    }
		}






		}catch(IOException e){

		}

	}//main
} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{




	public static void main(String[] args){

		String array[];

		BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));

		try{
		String str=reader.readLine();
		array=str.split(" ");
		int num=Integer.parseInt(array[0]);
		int q=Integer.parseInt(array[1]);
		int sum=0;
		Queue queue=new Queue(num);

		String x;
		int y;



		for(int i=0;i<num;i++){
			str=reader.readLine();
			queue.enqueue(str);
		}

		while(queue.num!=0){
			str=queue.dequeue();
			 array=str.split(" ");
			    x=array[0];
				y=Integer.parseInt(array[1]);

			    if(y>q){
			    	y=y-q;
			    	sum+=q;
			    	queue.enqueue(x+" "+y);
			    	} else{

			    	sum+=y;
			          System.out.println(x+" "+sum);
			    }
		}






		}catch(IOException e){

		}

	}//main
}

class Queue{
	int max;
	int num;
	String[] array;
	int front, rear;

	Queue(int capacity){//?????????????????????
		max=capacity;
		num=rear=front=0;
		array=new String[max];
	}
	public void enqueue(String str){
		array[rear++]=str;
		num++;
		if(rear==max)rear=0;
	}

	public String dequeue(){
		String str=array[front++];
		num--;
		if(front==max)front=0;

		return str;
	}

}//stack?????????