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

public class Main {
	private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

	public static void main(String[] args) throws Exception {
		String[] list = br.readLine().split(" ");
		int n = Integer.parseInt(list[0]);
		int q = Integer.parseInt(list[1]);
		
		Deque<ALDS1_3_B_Process> deque = new ArrayDeque<>();
		
		for(int i = 0; i < n; i++){
			list = br.readLine().split(" ");
			String name = list[0];
			int time = Integer.parseInt(list[1]);
			deque.addLast(new ALDS1_3_B_Process(name, time));
		}
		
		int timer = 0;
		
		while(!deque.isEmpty()){
			ALDS1_3_B_Process process = deque.pollFirst();
			int time = process.getTime();
			if(time <= q){
				timer += time;
				System.out.println(process.getName() + " " + timer);
			}else{
				timer += q;
				time -= q;
				process.setTime(time);
				deque.offerLast(process);
			}
		}
		
	}
}

class ALDS1_3_B_Process{
	private String name;
	private int time;
	
	public ALDS1_3_B_Process(String name, int time) {
		this.name = name;
		this.time = time;
	}

	public String getName() {
		return name;
	}

	public int getTime() {
		return time;
	}
	
	public void setTime(int time){
		this.time = time;
	}
} import java.io.BufferedReader; BufferedReader 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 {
	private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

	public static void main(String[] args) throws Exception {
		String[] list = br.readLine().split(" ");
		int n = Integer.parseInt(list[0]);
		int q = Integer.parseInt(list[1]);
		
		Deque<ALDS1_3_B_Process> deque = new ArrayDeque<>();
		
		for(int i = 0; i < n; i++){
			list = br.readLine().split(" ");
			String name = list[0];
			int time = Integer.parseInt(list[1]);
			deque.addLast(new ALDS1_3_B_Process(name, time));
		}
		
		int timer = 0;
		
		while(!deque.isEmpty()){
			ALDS1_3_B_Process process = deque.pollFirst();
			int time = process.getTime();
			if(time <= q){
				timer += time;
				System.out.println(process.getName() + " " + timer);
			}else{
				timer += q;
				time -= q;
				process.setTime(time);
				deque.offerLast(process);
			}
		}
		
	}
} Main private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) public static void main(String[] args) throws Exception {
		String[] list = br.readLine().split(" ");
		int n = Integer.parseInt(list[0]);
		int q = Integer.parseInt(list[1]);
		
		Deque<ALDS1_3_B_Process> deque = new ArrayDeque<>();
		
		for(int i = 0; i < n; i++){
			list = br.readLine().split(" ");
			String name = list[0];
			int time = Integer.parseInt(list[1]);
			deque.addLast(new ALDS1_3_B_Process(name, time));
		}
		
		int timer = 0;
		
		while(!deque.isEmpty()){
			ALDS1_3_B_Process process = deque.pollFirst();
			int time = process.getTime();
			if(time <= q){
				timer += time;
				System.out.println(process.getName() + " " + timer);
			}else{
				timer += q;
				time -= q;
				process.setTime(time);
				deque.offerLast(process);
			}
		}
		
	} main {
		String[] list = br.readLine().split(" ");
		int n = Integer.parseInt(list[0]);
		int q = Integer.parseInt(list[1]);
		
		Deque<ALDS1_3_B_Process> deque = new ArrayDeque<>();
		
		for(int i = 0; i < n; i++){
			list = br.readLine().split(" ");
			String name = list[0];
			int time = Integer.parseInt(list[1]);
			deque.addLast(new ALDS1_3_B_Process(name, time));
		}
		
		int timer = 0;
		
		while(!deque.isEmpty()){
			ALDS1_3_B_Process process = deque.pollFirst();
			int time = process.getTime();
			if(time <= q){
				timer += time;
				System.out.println(process.getName() + " " + timer);
			}else{
				timer += q;
				time -= q;
				process.setTime(time);
				deque.offerLast(process);
			}
		}
		
	} String[] list = br.readLine().split(" "); list br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " int n = Integer.parseInt(list[0]); n Integer.parseInt(list[0]) Integer.parseInt Integer list[0] list 0 int q = Integer.parseInt(list[1]); q Integer.parseInt(list[1]) Integer.parseInt Integer list[1] list 1 Deque<ALDS1_3_B_Process> deque = new ArrayDeque<>(); deque new ArrayDeque<>() for(int i = 0; i < n; i++){
			list = br.readLine().split(" ");
			String name = list[0];
			int time = Integer.parseInt(list[1]);
			deque.addLast(new ALDS1_3_B_Process(name, time));
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			list = br.readLine().split(" ");
			String name = list[0];
			int time = Integer.parseInt(list[1]);
			deque.addLast(new ALDS1_3_B_Process(name, time));
		} {
			list = br.readLine().split(" ");
			String name = list[0];
			int time = Integer.parseInt(list[1]);
			deque.addLast(new ALDS1_3_B_Process(name, time));
		} list = br.readLine().split(" ") list br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " String name = list[0]; name list[0] list 0 int time = Integer.parseInt(list[1]); time Integer.parseInt(list[1]) Integer.parseInt Integer list[1] list 1 deque.addLast(new ALDS1_3_B_Process(name, time)) deque.addLast deque new ALDS1_3_B_Process(name, time) int timer = 0; timer 0 while(!deque.isEmpty()){
			ALDS1_3_B_Process process = deque.pollFirst();
			int time = process.getTime();
			if(time <= q){
				timer += time;
				System.out.println(process.getName() + " " + timer);
			}else{
				timer += q;
				time -= q;
				process.setTime(time);
				deque.offerLast(process);
			}
		} !deque.isEmpty() deque.isEmpty() deque.isEmpty deque {
			ALDS1_3_B_Process process = deque.pollFirst();
			int time = process.getTime();
			if(time <= q){
				timer += time;
				System.out.println(process.getName() + " " + timer);
			}else{
				timer += q;
				time -= q;
				process.setTime(time);
				deque.offerLast(process);
			}
		} ALDS1_3_B_Process process = deque.pollFirst(); process deque.pollFirst() deque.pollFirst deque int time = process.getTime(); time process.getTime() process.getTime process if(time <= q){
				timer += time;
				System.out.println(process.getName() + " " + timer);
			}else{
				timer += q;
				time -= q;
				process.setTime(time);
				deque.offerLast(process);
			} time <= q time q {
				timer += time;
				System.out.println(process.getName() + " " + timer);
			} timer += time timer time System.out.println(process.getName() + " " + timer) System.out.println System.out System System.out process.getName() + " " + timer process.getName() + " " + timer process.getName() process.getName process " " timer {
				timer += q;
				time -= q;
				process.setTime(time);
				deque.offerLast(process);
			} timer += q timer q time -= q time q process.setTime(time) process.setTime process time deque.offerLast(process) deque.offerLast deque process String[] args args class ALDS1_3_B_Process{
	private String name;
	private int time;
	
	public ALDS1_3_B_Process(String name, int time) {
		this.name = name;
		this.time = time;
	}

	public String getName() {
		return name;
	}

	public int getTime() {
		return time;
	}
	
	public void setTime(int time){
		this.time = time;
	}
} ALDS1_3_B_Process private String name; name private int time; time public ALDS1_3_B_Process(String name, int time) {
		this.name = name;
		this.time = time;
	} ALDS1_3_B_Process {
		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 public String getName() {
		return name;
	} getName {
		return name;
	} return name; name public int getTime() {
		return time;
	} getTime {
		return time;
	} return time; time public void setTime(int time){
		this.time = time;
	} setTime {
		this.time = time;
	} this.time = time this.time this this.time time int time time public class Main {
	private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

	public static void main(String[] args) throws Exception {
		String[] list = br.readLine().split(" ");
		int n = Integer.parseInt(list[0]);
		int q = Integer.parseInt(list[1]);
		
		Deque<ALDS1_3_B_Process> deque = new ArrayDeque<>();
		
		for(int i = 0; i < n; i++){
			list = br.readLine().split(" ");
			String name = list[0];
			int time = Integer.parseInt(list[1]);
			deque.addLast(new ALDS1_3_B_Process(name, time));
		}
		
		int timer = 0;
		
		while(!deque.isEmpty()){
			ALDS1_3_B_Process process = deque.pollFirst();
			int time = process.getTime();
			if(time <= q){
				timer += time;
				System.out.println(process.getName() + " " + timer);
			}else{
				timer += q;
				time -= q;
				process.setTime(time);
				deque.offerLast(process);
			}
		}
		
	}
} public class Main {
	private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

	public static void main(String[] args) throws Exception {
		String[] list = br.readLine().split(" ");
		int n = Integer.parseInt(list[0]);
		int q = Integer.parseInt(list[1]);
		
		Deque<ALDS1_3_B_Process> deque = new ArrayDeque<>();
		
		for(int i = 0; i < n; i++){
			list = br.readLine().split(" ");
			String name = list[0];
			int time = Integer.parseInt(list[1]);
			deque.addLast(new ALDS1_3_B_Process(name, time));
		}
		
		int timer = 0;
		
		while(!deque.isEmpty()){
			ALDS1_3_B_Process process = deque.pollFirst();
			int time = process.getTime();
			if(time <= q){
				timer += time;
				System.out.println(process.getName() + " " + timer);
			}else{
				timer += q;
				time -= q;
				process.setTime(time);
				deque.offerLast(process);
			}
		}
		
	}
} Main
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Deque;

public class Main {
	private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

	public static void main(String[] args) throws Exception {
		String[] list = br.readLine().split(" ");
		int n = Integer.parseInt(list[0]);
		int q = Integer.parseInt(list[1]);
		
		Deque<ALDS1_3_B_Process> deque = new ArrayDeque<>();
		
		for(int i = 0; i < n; i++){
			list = br.readLine().split(" ");
			String name = list[0];
			int time = Integer.parseInt(list[1]);
			deque.addLast(new ALDS1_3_B_Process(name, time));
		}
		
		int timer = 0;
		
		while(!deque.isEmpty()){
			ALDS1_3_B_Process process = deque.pollFirst();
			int time = process.getTime();
			if(time <= q){
				timer += time;
				System.out.println(process.getName() + " " + timer);
			}else{
				timer += q;
				time -= q;
				process.setTime(time);
				deque.offerLast(process);
			}
		}
		
	}
}

class ALDS1_3_B_Process{
	private String name;
	private int time;
	
	public ALDS1_3_B_Process(String name, int time) {
		this.name = name;
		this.time = time;
	}

	public String getName() {
		return name;
	}

	public int getTime() {
		return time;
	}
	
	public void setTime(int time){
		this.time = time;
	}
}
