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

public class Main {

	public static void main(String[] args) throws IOException, NumberFormatException {
		// TODO ?????????????????????????????????????????????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		Deque<Pair> deq = new ArrayDeque<Pair>();
		
		String[] str = br.readLine().split(" ");
		
		int n = Integer.parseInt(str[0]);
		int q = Integer.parseInt(str[1]);
		
		
		for(int i = 0; i < n; i++){
			str = br.readLine().split(" ");
			deq.addFirst(new Pair(str[0], Integer.parseInt(str[1])));
		}
		
		int timeCount = 0;
		
		String[] name = new String[n];
		int[] time = new int[n];
		
		for(int i = 0; !deq.isEmpty();){
			
			Pair p = deq.removeLast();
			
			if(p.getTime() > q){
				p.overTime(q);
				deq.addFirst(p);
				timeCount += q;
			} else {
				timeCount += p.getTime();
				
				name[i] = p.getName();
				time[i] = timeCount;
				i++;
			}
		}
		
		for(int i = 0; i < n; i++){
			System.out.println(name[i] + " " + time[i]);
		}
	}

}

class Pair {
	String name;
	int time;
	
	Pair(String name, int time){
		this.name = name;
		this.time = time;
	}
	
	void overTime(int over){
		time -= over;
	}
	int getTime(){
		return time;
	}
	String getName(){
		return name;
	}
} 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.Deque; Deque java.util public class Main {

	public static void main(String[] args) throws IOException, NumberFormatException {
		// TODO ?????????????????????????????????????????????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		Deque<Pair> deq = new ArrayDeque<Pair>();
		
		String[] str = br.readLine().split(" ");
		
		int n = Integer.parseInt(str[0]);
		int q = Integer.parseInt(str[1]);
		
		
		for(int i = 0; i < n; i++){
			str = br.readLine().split(" ");
			deq.addFirst(new Pair(str[0], Integer.parseInt(str[1])));
		}
		
		int timeCount = 0;
		
		String[] name = new String[n];
		int[] time = new int[n];
		
		for(int i = 0; !deq.isEmpty();){
			
			Pair p = deq.removeLast();
			
			if(p.getTime() > q){
				p.overTime(q);
				deq.addFirst(p);
				timeCount += q;
			} else {
				timeCount += p.getTime();
				
				name[i] = p.getName();
				time[i] = timeCount;
				i++;
			}
		}
		
		for(int i = 0; i < n; i++){
			System.out.println(name[i] + " " + time[i]);
		}
	}

} Main public static void main(String[] args) throws IOException, NumberFormatException {
		// TODO ?????????????????????????????????????????????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		Deque<Pair> deq = new ArrayDeque<Pair>();
		
		String[] str = br.readLine().split(" ");
		
		int n = Integer.parseInt(str[0]);
		int q = Integer.parseInt(str[1]);
		
		
		for(int i = 0; i < n; i++){
			str = br.readLine().split(" ");
			deq.addFirst(new Pair(str[0], Integer.parseInt(str[1])));
		}
		
		int timeCount = 0;
		
		String[] name = new String[n];
		int[] time = new int[n];
		
		for(int i = 0; !deq.isEmpty();){
			
			Pair p = deq.removeLast();
			
			if(p.getTime() > q){
				p.overTime(q);
				deq.addFirst(p);
				timeCount += q;
			} else {
				timeCount += p.getTime();
				
				name[i] = p.getName();
				time[i] = timeCount;
				i++;
			}
		}
		
		for(int i = 0; i < n; i++){
			System.out.println(name[i] + " " + time[i]);
		}
	} main {
		// TODO ?????????????????????????????????????????????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		Deque<Pair> deq = new ArrayDeque<Pair>();
		
		String[] str = br.readLine().split(" ");
		
		int n = Integer.parseInt(str[0]);
		int q = Integer.parseInt(str[1]);
		
		
		for(int i = 0; i < n; i++){
			str = br.readLine().split(" ");
			deq.addFirst(new Pair(str[0], Integer.parseInt(str[1])));
		}
		
		int timeCount = 0;
		
		String[] name = new String[n];
		int[] time = new int[n];
		
		for(int i = 0; !deq.isEmpty();){
			
			Pair p = deq.removeLast();
			
			if(p.getTime() > q){
				p.overTime(q);
				deq.addFirst(p);
				timeCount += q;
			} else {
				timeCount += p.getTime();
				
				name[i] = p.getName();
				time[i] = timeCount;
				i++;
			}
		}
		
		for(int i = 0; i < n; i++){
			System.out.println(name[i] + " " + time[i]);
		}
	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) Deque<Pair> deq = new ArrayDeque<Pair>(); deq new ArrayDeque<Pair>() String[] str = br.readLine().split(" "); str br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " int n = Integer.parseInt(str[0]); n Integer.parseInt(str[0]) Integer.parseInt Integer str[0] str 0 int q = Integer.parseInt(str[1]); q Integer.parseInt(str[1]) Integer.parseInt Integer str[1] str 1 for(int i = 0; i < n; i++){
			str = br.readLine().split(" ");
			deq.addFirst(new Pair(str[0], Integer.parseInt(str[1])));
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			str = br.readLine().split(" ");
			deq.addFirst(new Pair(str[0], Integer.parseInt(str[1])));
		} {
			str = br.readLine().split(" ");
			deq.addFirst(new Pair(str[0], Integer.parseInt(str[1])));
		} str = br.readLine().split(" ") str br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " deq.addFirst(new Pair(str[0], Integer.parseInt(str[1]))) deq.addFirst deq new Pair(str[0], Integer.parseInt(str[1])) int timeCount = 0; timeCount 0 String[] name = new String[n]; name new String[n] n int[] time = new int[n]; time new int[n] n for(int i = 0; !deq.isEmpty();){
			
			Pair p = deq.removeLast();
			
			if(p.getTime() > q){
				p.overTime(q);
				deq.addFirst(p);
				timeCount += q;
			} else {
				timeCount += p.getTime();
				
				name[i] = p.getName();
				time[i] = timeCount;
				i++;
			}
		} int i = 0; int i = 0; i 0 !deq.isEmpty() deq.isEmpty() deq.isEmpty deq {
			
			Pair p = deq.removeLast();
			
			if(p.getTime() > q){
				p.overTime(q);
				deq.addFirst(p);
				timeCount += q;
			} else {
				timeCount += p.getTime();
				
				name[i] = p.getName();
				time[i] = timeCount;
				i++;
			}
		} {
			
			Pair p = deq.removeLast();
			
			if(p.getTime() > q){
				p.overTime(q);
				deq.addFirst(p);
				timeCount += q;
			} else {
				timeCount += p.getTime();
				
				name[i] = p.getName();
				time[i] = timeCount;
				i++;
			}
		} Pair p = deq.removeLast(); p deq.removeLast() deq.removeLast deq if(p.getTime() > q){
				p.overTime(q);
				deq.addFirst(p);
				timeCount += q;
			} else {
				timeCount += p.getTime();
				
				name[i] = p.getName();
				time[i] = timeCount;
				i++;
			} p.getTime() > q p.getTime() p.getTime p q {
				p.overTime(q);
				deq.addFirst(p);
				timeCount += q;
			} p.overTime(q) p.overTime p q deq.addFirst(p) deq.addFirst deq p timeCount += q timeCount q {
				timeCount += p.getTime();
				
				name[i] = p.getName();
				time[i] = timeCount;
				i++;
			} timeCount += p.getTime() timeCount p.getTime() p.getTime p name[i] = p.getName() name[i] name i p.getName() p.getName p time[i] = timeCount time[i] time i timeCount i++ i for(int i = 0; i < n; i++){
			System.out.println(name[i] + " " + time[i]);
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			System.out.println(name[i] + " " + time[i]);
		} {
			System.out.println(name[i] + " " + time[i]);
		} System.out.println(name[i] + " " + time[i]) System.out.println System.out System System.out name[i] + " " + time[i] name[i] + " " + time[i] name[i] name i " " time[i] time i String[] args args class Pair {
	String name;
	int time;
	
	Pair(String name, int time){
		this.name = name;
		this.time = time;
	}
	
	void overTime(int over){
		time -= over;
	}
	int getTime(){
		return time;
	}
	String getName(){
		return name;
	}
} Pair String name; name int time; time Pair(String name, int time){
		this.name = name;
		this.time = time;
	} Pair {
		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 void overTime(int over){
		time -= over;
	} overTime {
		time -= over;
	} time -= over time over int over over int getTime(){
		return time;
	} getTime {
		return time;
	} return time; time String getName(){
		return name;
	} getName {
		return name;
	} return name; name public class Main {

	public static void main(String[] args) throws IOException, NumberFormatException {
		// TODO ?????????????????????????????????????????????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		Deque<Pair> deq = new ArrayDeque<Pair>();
		
		String[] str = br.readLine().split(" ");
		
		int n = Integer.parseInt(str[0]);
		int q = Integer.parseInt(str[1]);
		
		
		for(int i = 0; i < n; i++){
			str = br.readLine().split(" ");
			deq.addFirst(new Pair(str[0], Integer.parseInt(str[1])));
		}
		
		int timeCount = 0;
		
		String[] name = new String[n];
		int[] time = new int[n];
		
		for(int i = 0; !deq.isEmpty();){
			
			Pair p = deq.removeLast();
			
			if(p.getTime() > q){
				p.overTime(q);
				deq.addFirst(p);
				timeCount += q;
			} else {
				timeCount += p.getTime();
				
				name[i] = p.getName();
				time[i] = timeCount;
				i++;
			}
		}
		
		for(int i = 0; i < n; i++){
			System.out.println(name[i] + " " + time[i]);
		}
	}

} public class Main {

	public static void main(String[] args) throws IOException, NumberFormatException {
		// TODO ?????????????????????????????????????????????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		Deque<Pair> deq = new ArrayDeque<Pair>();
		
		String[] str = br.readLine().split(" ");
		
		int n = Integer.parseInt(str[0]);
		int q = Integer.parseInt(str[1]);
		
		
		for(int i = 0; i < n; i++){
			str = br.readLine().split(" ");
			deq.addFirst(new Pair(str[0], Integer.parseInt(str[1])));
		}
		
		int timeCount = 0;
		
		String[] name = new String[n];
		int[] time = new int[n];
		
		for(int i = 0; !deq.isEmpty();){
			
			Pair p = deq.removeLast();
			
			if(p.getTime() > q){
				p.overTime(q);
				deq.addFirst(p);
				timeCount += q;
			} else {
				timeCount += p.getTime();
				
				name[i] = p.getName();
				time[i] = timeCount;
				i++;
			}
		}
		
		for(int i = 0; i < n; i++){
			System.out.println(name[i] + " " + time[i]);
		}
	}

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

public class Main {

	public static void main(String[] args) throws IOException, NumberFormatException {
		// TODO ?????????????????????????????????????????????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		Deque<Pair> deq = new ArrayDeque<Pair>();
		
		String[] str = br.readLine().split(" ");
		
		int n = Integer.parseInt(str[0]);
		int q = Integer.parseInt(str[1]);
		
		
		for(int i = 0; i < n; i++){
			str = br.readLine().split(" ");
			deq.addFirst(new Pair(str[0], Integer.parseInt(str[1])));
		}
		
		int timeCount = 0;
		
		String[] name = new String[n];
		int[] time = new int[n];
		
		for(int i = 0; !deq.isEmpty();){
			
			Pair p = deq.removeLast();
			
			if(p.getTime() > q){
				p.overTime(q);
				deq.addFirst(p);
				timeCount += q;
			} else {
				timeCount += p.getTime();
				
				name[i] = p.getName();
				time[i] = timeCount;
				i++;
			}
		}
		
		for(int i = 0; i < n; i++){
			System.out.println(name[i] + " " + time[i]);
		}
	}

}

class Pair {
	String name;
	int time;
	
	Pair(String name, int time){
		this.name = name;
		this.time = time;
	}
	
	void overTime(int over){
		time -= over;
	}
	int getTime(){
		return time;
	}
	String getName(){
		return name;
	}
}