import java.util.*;

public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int n, q, time, i;
		queue que = new queue();
		
		n = sc.nextInt();
		q = sc.nextInt();
		
		for(i = 0; i < n; i++){
			String name = new String(sc.next());
			time = sc.nextInt();
			
			que.enqueue(name, time);
		}
		
		que.simulate(q);
	}
}

class data{
	String name;
	int time;
	
	data(String name, int time){
		this.name = name;
		this.time = time;
	}
}

class queue{
	ArrayList<data> Q;
	int head, tail;
	
	queue(){
		Q = new ArrayList<data>();
		head = tail = 0;
	}
	
	void enqueue(String name, int time){
		data process = new data(name, time);
		
		Q.add(process);
		tail ++;
	}
	
	data dequeue(){
		data process = Q.get(head);
		
		head ++;
		
		return process;
	}
	
	boolean isEmpty(){
		if(head == tail){
			return true;
		}
		else{
			return false;
		}
	}
	
	void simulate(int q){
		int sum = 0, cnt = 0, t;
		ArrayList<data> finish = new ArrayList<data>();
		
		while(!isEmpty()){
			data temp = dequeue();
			if(temp.time <= q){
				sum += temp.time;
				temp.time = sum;
				finish.add(temp);
				
				cnt ++;
			}
			else{
				sum += q;
				enqueue(temp.name, temp.time - q);
			}
		}
		
		for(int i = 0; i < cnt; i++){
			System.out.println(finish.get(i).name.toString() + " " + finish.get(i).time);
		}
	}
} import java.util.*; util.* java public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int n, q, time, i;
		queue que = new queue();
		
		n = sc.nextInt();
		q = sc.nextInt();
		
		for(i = 0; i < n; i++){
			String name = new String(sc.next());
			time = sc.nextInt();
			
			que.enqueue(name, time);
		}
		
		que.simulate(q);
	}
} Main public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int n, q, time, i;
		queue que = new queue();
		
		n = sc.nextInt();
		q = sc.nextInt();
		
		for(i = 0; i < n; i++){
			String name = new String(sc.next());
			time = sc.nextInt();
			
			que.enqueue(name, time);
		}
		
		que.simulate(q);
	} main {
		Scanner sc = new Scanner(System.in);
		int n, q, time, i;
		queue que = new queue();
		
		n = sc.nextInt();
		q = sc.nextInt();
		
		for(i = 0; i < n; i++){
			String name = new String(sc.next());
			time = sc.nextInt();
			
			que.enqueue(name, time);
		}
		
		que.simulate(q);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n n q q time time i; i queue que = new queue(); que new queue() n = sc.nextInt() n sc.nextInt() sc.nextInt sc q = sc.nextInt() q sc.nextInt() sc.nextInt sc for(i = 0; i < n; i++){
			String name = new String(sc.next());
			time = sc.nextInt();
			
			que.enqueue(name, time);
		} i = 0; i = 0 i 0 i < n i n i++ i++ i {
			String name = new String(sc.next());
			time = sc.nextInt();
			
			que.enqueue(name, time);
		} {
			String name = new String(sc.next());
			time = sc.nextInt();
			
			que.enqueue(name, time);
		} String name = new String(sc.next()); name new String(sc.next()) time = sc.nextInt() time sc.nextInt() sc.nextInt sc que.enqueue(name, time) que.enqueue que name time que.simulate(q) que.simulate que q String args[] args class data{
	String name;
	int time;
	
	data(String name, int time){
		this.name = name;
		this.time = time;
	}
} data String name; name int time; time data(String name, int time){
		this.name = name;
		this.time = time;
	} data {
		this.name = name;
		this.time = time;
	} this.name = name this.name this this.name name this.time = time this.time this this.time time String name name int time time class queue{
	ArrayList<data> Q;
	int head, tail;
	
	queue(){
		Q = new ArrayList<data>();
		head = tail = 0;
	}
	
	void enqueue(String name, int time){
		data process = new data(name, time);
		
		Q.add(process);
		tail ++;
	}
	
	data dequeue(){
		data process = Q.get(head);
		
		head ++;
		
		return process;
	}
	
	boolean isEmpty(){
		if(head == tail){
			return true;
		}
		else{
			return false;
		}
	}
	
	void simulate(int q){
		int sum = 0, cnt = 0, t;
		ArrayList<data> finish = new ArrayList<data>();
		
		while(!isEmpty()){
			data temp = dequeue();
			if(temp.time <= q){
				sum += temp.time;
				temp.time = sum;
				finish.add(temp);
				
				cnt ++;
			}
			else{
				sum += q;
				enqueue(temp.name, temp.time - q);
			}
		}
		
		for(int i = 0; i < cnt; i++){
			System.out.println(finish.get(i).name.toString() + " " + finish.get(i).time);
		}
	}
} queue ArrayList<data> Q; Q int head head tail; tail queue(){
		Q = new ArrayList<data>();
		head = tail = 0;
	} queue {
		Q = new ArrayList<data>();
		head = tail = 0;
	} Q = new ArrayList<data>() Q new ArrayList<data>() head = tail = 0 head tail = 0 tail 0 void enqueue(String name, int time){
		data process = new data(name, time);
		
		Q.add(process);
		tail ++;
	} enqueue {
		data process = new data(name, time);
		
		Q.add(process);
		tail ++;
	} data process = new data(name, time); process new data(name, time) Q.add(process) Q.add Q process tail ++ tail String name name int time time data dequeue(){
		data process = Q.get(head);
		
		head ++;
		
		return process;
	} dequeue {
		data process = Q.get(head);
		
		head ++;
		
		return process;
	} data process = Q.get(head); process Q.get(head) Q.get Q head head ++ head return process; process 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 void simulate(int q){
		int sum = 0, cnt = 0, t;
		ArrayList<data> finish = new ArrayList<data>();
		
		while(!isEmpty()){
			data temp = dequeue();
			if(temp.time <= q){
				sum += temp.time;
				temp.time = sum;
				finish.add(temp);
				
				cnt ++;
			}
			else{
				sum += q;
				enqueue(temp.name, temp.time - q);
			}
		}
		
		for(int i = 0; i < cnt; i++){
			System.out.println(finish.get(i).name.toString() + " " + finish.get(i).time);
		}
	} simulate {
		int sum = 0, cnt = 0, t;
		ArrayList<data> finish = new ArrayList<data>();
		
		while(!isEmpty()){
			data temp = dequeue();
			if(temp.time <= q){
				sum += temp.time;
				temp.time = sum;
				finish.add(temp);
				
				cnt ++;
			}
			else{
				sum += q;
				enqueue(temp.name, temp.time - q);
			}
		}
		
		for(int i = 0; i < cnt; i++){
			System.out.println(finish.get(i).name.toString() + " " + finish.get(i).time);
		}
	} int sum = 0 sum 0 cnt = 0 cnt 0 t; t ArrayList<data> finish = new ArrayList<data>(); finish new ArrayList<data>() while(!isEmpty()){
			data temp = dequeue();
			if(temp.time <= q){
				sum += temp.time;
				temp.time = sum;
				finish.add(temp);
				
				cnt ++;
			}
			else{
				sum += q;
				enqueue(temp.name, temp.time - q);
			}
		} !isEmpty() isEmpty() isEmpty {
			data temp = dequeue();
			if(temp.time <= q){
				sum += temp.time;
				temp.time = sum;
				finish.add(temp);
				
				cnt ++;
			}
			else{
				sum += q;
				enqueue(temp.name, temp.time - q);
			}
		} data temp = dequeue(); temp dequeue() dequeue if(temp.time <= q){
				sum += temp.time;
				temp.time = sum;
				finish.add(temp);
				
				cnt ++;
			}
			else{
				sum += q;
				enqueue(temp.name, temp.time - q);
			} temp.time <= q temp.time temp temp.time q {
				sum += temp.time;
				temp.time = sum;
				finish.add(temp);
				
				cnt ++;
			} sum += temp.time sum temp.time temp temp.time temp.time = sum temp.time temp temp.time sum finish.add(temp) finish.add finish temp cnt ++ cnt {
				sum += q;
				enqueue(temp.name, temp.time - q);
			} sum += q sum q enqueue(temp.name, temp.time - q) enqueue temp.name temp temp.name temp.time - q temp.time temp temp.time q for(int i = 0; i < cnt; i++){
			System.out.println(finish.get(i).name.toString() + " " + finish.get(i).time);
		} int i = 0; int i = 0; i 0 i < cnt i cnt i++ i++ i {
			System.out.println(finish.get(i).name.toString() + " " + finish.get(i).time);
		} {
			System.out.println(finish.get(i).name.toString() + " " + finish.get(i).time);
		} System.out.println(finish.get(i).name.toString() + " " + finish.get(i).time) System.out.println System.out System System.out finish.get(i).name.toString() + " " + finish.get(i).time finish.get(i).name.toString() + " " + finish.get(i).time finish.get(i).name.toString() finish.get(i).name.toString finish.get(i).name finish.get(i) finish.get finish i finish.get(i).name " " finish.get(i).time finish.get(i) finish.get finish i finish.get(i).time int q q public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int n, q, time, i;
		queue que = new queue();
		
		n = sc.nextInt();
		q = sc.nextInt();
		
		for(i = 0; i < n; i++){
			String name = new String(sc.next());
			time = sc.nextInt();
			
			que.enqueue(name, time);
		}
		
		que.simulate(q);
	}
} public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int n, q, time, i;
		queue que = new queue();
		
		n = sc.nextInt();
		q = sc.nextInt();
		
		for(i = 0; i < n; i++){
			String name = new String(sc.next());
			time = sc.nextInt();
			
			que.enqueue(name, time);
		}
		
		que.simulate(q);
	}
} Main
import java.util.*;

public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int n, q, time, i;
		queue que = new queue();
		
		n = sc.nextInt();
		q = sc.nextInt();
		
		for(i = 0; i < n; i++){
			String name = new String(sc.next());
			time = sc.nextInt();
			
			que.enqueue(name, time);
		}
		
		que.simulate(q);
	}
}

class data{
	String name;
	int time;
	
	data(String name, int time){
		this.name = name;
		this.time = time;
	}
}

class queue{
	ArrayList<data> Q;
	int head, tail;
	
	queue(){
		Q = new ArrayList<data>();
		head = tail = 0;
	}
	
	void enqueue(String name, int time){
		data process = new data(name, time);
		
		Q.add(process);
		tail ++;
	}
	
	data dequeue(){
		data process = Q.get(head);
		
		head ++;
		
		return process;
	}
	
	boolean isEmpty(){
		if(head == tail){
			return true;
		}
		else{
			return false;
		}
	}
	
	void simulate(int q){
		int sum = 0, cnt = 0, t;
		ArrayList<data> finish = new ArrayList<data>();
		
		while(!isEmpty()){
			data temp = dequeue();
			if(temp.time <= q){
				sum += temp.time;
				temp.time = sum;
				finish.add(temp);
				
				cnt ++;
			}
			else{
				sum += q;
				enqueue(temp.name, temp.time - q);
			}
		}
		
		for(int i = 0; i < cnt; i++){
			System.out.println(finish.get(i).name.toString() + " " + finish.get(i).time);
		}
	}
}