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

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

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		// BufferedReader br = new BufferedReader(new FileReader("in1.txt"));
		String[] line1 = br.readLine().split(" ");
		int n = Integer.parseInt(line1[0]), q = Integer.parseInt(line1[1]);
		Deque<Process> que = new ArrayDeque<Process>();
		for (int i = 0; i < n; i++) {
			String[] line = br.readLine().split(" ");
			que.addLast(new Process(line[0], Integer.parseInt(line[1])));
		}
		
		StringBuilder sb = new StringBuilder();
		int timeStamp = 0;
		while (!que.isEmpty()) {
			Process p = que.removeFirst();
			if (p.time <= q) {
				timeStamp += p.time;
				sb.append(p.name);
				sb.append(' ');
				sb.append(timeStamp);
				sb.append('\n');
			} else {
				timeStamp += q;
				p.time -= q;
				que.addLast(p);
			}
		}
		
		System.out.print(sb.toString());
	}
} import java.io.BufferedReader; BufferedReader java.io import java.io.FileReader; FileReader java.io import java.io.InputStreamReader; InputStreamReader java.io import java.util.ArrayDeque; ArrayDeque java.util import java.util.Deque; Deque java.util class Process {
	String name;
	int time;
	
	Process(String name, int time) {
		this.name = name;
		this.time = time;
	}
} Process String name; name int time; time Process(String name, int time) {
		this.name = name;
		this.time = time;
	} 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 class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		// BufferedReader br = new BufferedReader(new FileReader("in1.txt"));
		String[] line1 = br.readLine().split(" ");
		int n = Integer.parseInt(line1[0]), q = Integer.parseInt(line1[1]);
		Deque<Process> que = new ArrayDeque<Process>();
		for (int i = 0; i < n; i++) {
			String[] line = br.readLine().split(" ");
			que.addLast(new Process(line[0], Integer.parseInt(line[1])));
		}
		
		StringBuilder sb = new StringBuilder();
		int timeStamp = 0;
		while (!que.isEmpty()) {
			Process p = que.removeFirst();
			if (p.time <= q) {
				timeStamp += p.time;
				sb.append(p.name);
				sb.append(' ');
				sb.append(timeStamp);
				sb.append('\n');
			} else {
				timeStamp += q;
				p.time -= q;
				que.addLast(p);
			}
		}
		
		System.out.print(sb.toString());
	}
} Main public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		// BufferedReader br = new BufferedReader(new FileReader("in1.txt"));
		String[] line1 = br.readLine().split(" ");
		int n = Integer.parseInt(line1[0]), q = Integer.parseInt(line1[1]);
		Deque<Process> que = new ArrayDeque<Process>();
		for (int i = 0; i < n; i++) {
			String[] line = br.readLine().split(" ");
			que.addLast(new Process(line[0], Integer.parseInt(line[1])));
		}
		
		StringBuilder sb = new StringBuilder();
		int timeStamp = 0;
		while (!que.isEmpty()) {
			Process p = que.removeFirst();
			if (p.time <= q) {
				timeStamp += p.time;
				sb.append(p.name);
				sb.append(' ');
				sb.append(timeStamp);
				sb.append('\n');
			} else {
				timeStamp += q;
				p.time -= q;
				que.addLast(p);
			}
		}
		
		System.out.print(sb.toString());
	} main {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		// BufferedReader br = new BufferedReader(new FileReader("in1.txt"));
		String[] line1 = br.readLine().split(" ");
		int n = Integer.parseInt(line1[0]), q = Integer.parseInt(line1[1]);
		Deque<Process> que = new ArrayDeque<Process>();
		for (int i = 0; i < n; i++) {
			String[] line = br.readLine().split(" ");
			que.addLast(new Process(line[0], Integer.parseInt(line[1])));
		}
		
		StringBuilder sb = new StringBuilder();
		int timeStamp = 0;
		while (!que.isEmpty()) {
			Process p = que.removeFirst();
			if (p.time <= q) {
				timeStamp += p.time;
				sb.append(p.name);
				sb.append(' ');
				sb.append(timeStamp);
				sb.append('\n');
			} else {
				timeStamp += q;
				p.time -= q;
				que.addLast(p);
			}
		}
		
		System.out.print(sb.toString());
	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) String[] line1 = br.readLine().split(" "); line1 br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " int n = Integer.parseInt(line1[0]) n Integer.parseInt(line1[0]) Integer.parseInt Integer line1[0] line1 0 q = Integer.parseInt(line1[1]); q Integer.parseInt(line1[1]) Integer.parseInt Integer line1[1] line1 1 Deque<Process> que = new ArrayDeque<Process>(); que new ArrayDeque<Process>() for (int i = 0; i < n; i++) {
			String[] line = br.readLine().split(" ");
			que.addLast(new Process(line[0], Integer.parseInt(line[1])));
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			String[] line = br.readLine().split(" ");
			que.addLast(new Process(line[0], Integer.parseInt(line[1])));
		} {
			String[] line = br.readLine().split(" ");
			que.addLast(new Process(line[0], Integer.parseInt(line[1])));
		} String[] line = br.readLine().split(" "); line br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " que.addLast(new Process(line[0], Integer.parseInt(line[1]))) que.addLast que new Process(line[0], Integer.parseInt(line[1])) StringBuilder sb = new StringBuilder(); sb new StringBuilder() int timeStamp = 0; timeStamp 0 while (!que.isEmpty()) {
			Process p = que.removeFirst();
			if (p.time <= q) {
				timeStamp += p.time;
				sb.append(p.name);
				sb.append(' ');
				sb.append(timeStamp);
				sb.append('\n');
			} else {
				timeStamp += q;
				p.time -= q;
				que.addLast(p);
			}
		} !que.isEmpty() que.isEmpty() que.isEmpty que {
			Process p = que.removeFirst();
			if (p.time <= q) {
				timeStamp += p.time;
				sb.append(p.name);
				sb.append(' ');
				sb.append(timeStamp);
				sb.append('\n');
			} else {
				timeStamp += q;
				p.time -= q;
				que.addLast(p);
			}
		} Process p = que.removeFirst(); p que.removeFirst() que.removeFirst que if (p.time <= q) {
				timeStamp += p.time;
				sb.append(p.name);
				sb.append(' ');
				sb.append(timeStamp);
				sb.append('\n');
			} else {
				timeStamp += q;
				p.time -= q;
				que.addLast(p);
			} p.time <= q p.time p p.time q {
				timeStamp += p.time;
				sb.append(p.name);
				sb.append(' ');
				sb.append(timeStamp);
				sb.append('\n');
			} timeStamp += p.time timeStamp p.time p p.time sb.append(p.name) sb.append sb p.name p p.name sb.append(' ') sb.append sb ' ' sb.append(timeStamp) sb.append sb timeStamp sb.append('\n') sb.append sb '\n' {
				timeStamp += q;
				p.time -= q;
				que.addLast(p);
			} timeStamp += q timeStamp q p.time -= q p.time p p.time q que.addLast(p) que.addLast que p System.out.print(sb.toString()) System.out.print System.out System System.out sb.toString() sb.toString sb String[] args args public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		// BufferedReader br = new BufferedReader(new FileReader("in1.txt"));
		String[] line1 = br.readLine().split(" ");
		int n = Integer.parseInt(line1[0]), q = Integer.parseInt(line1[1]);
		Deque<Process> que = new ArrayDeque<Process>();
		for (int i = 0; i < n; i++) {
			String[] line = br.readLine().split(" ");
			que.addLast(new Process(line[0], Integer.parseInt(line[1])));
		}
		
		StringBuilder sb = new StringBuilder();
		int timeStamp = 0;
		while (!que.isEmpty()) {
			Process p = que.removeFirst();
			if (p.time <= q) {
				timeStamp += p.time;
				sb.append(p.name);
				sb.append(' ');
				sb.append(timeStamp);
				sb.append('\n');
			} else {
				timeStamp += q;
				p.time -= q;
				que.addLast(p);
			}
		}
		
		System.out.print(sb.toString());
	}
} public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		// BufferedReader br = new BufferedReader(new FileReader("in1.txt"));
		String[] line1 = br.readLine().split(" ");
		int n = Integer.parseInt(line1[0]), q = Integer.parseInt(line1[1]);
		Deque<Process> que = new ArrayDeque<Process>();
		for (int i = 0; i < n; i++) {
			String[] line = br.readLine().split(" ");
			que.addLast(new Process(line[0], Integer.parseInt(line[1])));
		}
		
		StringBuilder sb = new StringBuilder();
		int timeStamp = 0;
		while (!que.isEmpty()) {
			Process p = que.removeFirst();
			if (p.time <= q) {
				timeStamp += p.time;
				sb.append(p.name);
				sb.append(' ');
				sb.append(timeStamp);
				sb.append('\n');
			} else {
				timeStamp += q;
				p.time -= q;
				que.addLast(p);
			}
		}
		
		System.out.print(sb.toString());
	}
} Main
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Deque;

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

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		// BufferedReader br = new BufferedReader(new FileReader("in1.txt"));
		String[] line1 = br.readLine().split(" ");
		int n = Integer.parseInt(line1[0]), q = Integer.parseInt(line1[1]);
		Deque<Process> que = new ArrayDeque<Process>();
		for (int i = 0; i < n; i++) {
			String[] line = br.readLine().split(" ");
			que.addLast(new Process(line[0], Integer.parseInt(line[1])));
		}
		
		StringBuilder sb = new StringBuilder();
		int timeStamp = 0;
		while (!que.isEmpty()) {
			Process p = que.removeFirst();
			if (p.time <= q) {
				timeStamp += p.time;
				sb.append(p.name);
				sb.append(' ');
				sb.append(timeStamp);
				sb.append('\n');
			} else {
				timeStamp += q;
				p.time -= q;
				que.addLast(p);
			}
		}
		
		System.out.print(sb.toString());
	}
}