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

class Queue {

	private String[] names;
	private int[] times;
	private int head;
	private int tail;
	public Queue(int size) {
		names = new String[size + 1];
		times = new int[size + 1];
	}

	public void enqueue(String name, int time) {
		names[tail] = name;
		times[tail] = time;
		if (tail++ == names.length - 1) {
			tail = 0;
		}
	}

	public int dequeue() {
		if (head == names.length - 1) {
			head = 0;
			return names.length - 1;
		}
		return head++;
	}

	public boolean isEmpty() {
		return head == tail;
	}

	public String getName(int index) {
		return names[index];
	}

	public int getTime(int index) {
		return times[index];
	}
}

public class Main {

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] strs = br.readLine().split(" ");
		int n = Integer.parseInt(strs[0]);
		int q = Integer.parseInt(strs[1]);
		Queue queue = new Queue(n);
		StringBuilder sb = new StringBuilder();
		int sumTime = 0;
		for (int i = 0; i < n; i++) {
			strs = br.readLine().split(" ");
			int time = Integer.parseInt(strs[1]);
			if (time <= q) {
				sumTime += time;
				sb.append(strs[0] + " " + sumTime + "\n");
			} else {
				sumTime += q;
				queue.enqueue(strs[0], time - q);
			}
		}
		while (!queue.isEmpty()) {
			int entryIdx = queue.dequeue();
			String name = queue.getName(entryIdx);
			int time = queue.getTime(entryIdx);
			if (time <= q) {
				sumTime += time;
				sb.append(name + " " + sumTime + "\n");
			} else {
				sumTime += 	q;
				queue.enqueue(name, time - q);
			}
		}
		System.out.print(sb.toString());
	}
} import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io class Queue {

	private String[] names;
	private int[] times;
	private int head;
	private int tail;
	public Queue(int size) {
		names = new String[size + 1];
		times = new int[size + 1];
	}

	public void enqueue(String name, int time) {
		names[tail] = name;
		times[tail] = time;
		if (tail++ == names.length - 1) {
			tail = 0;
		}
	}

	public int dequeue() {
		if (head == names.length - 1) {
			head = 0;
			return names.length - 1;
		}
		return head++;
	}

	public boolean isEmpty() {
		return head == tail;
	}

	public String getName(int index) {
		return names[index];
	}

	public int getTime(int index) {
		return times[index];
	}
} Queue private String[] names; names private int[] times; times private int head; head private int tail; tail public Queue(int size) {
		names = new String[size + 1];
		times = new int[size + 1];
	} Queue {
		names = new String[size + 1];
		times = new int[size + 1];
	} names = new String[size + 1] names new String[size + 1] size + 1 size 1 times = new int[size + 1] times new int[size + 1] size + 1 size 1 int size size public void enqueue(String name, int time) {
		names[tail] = name;
		times[tail] = time;
		if (tail++ == names.length - 1) {
			tail = 0;
		}
	} enqueue {
		names[tail] = name;
		times[tail] = time;
		if (tail++ == names.length - 1) {
			tail = 0;
		}
	} names[tail] = name names[tail] names tail name times[tail] = time times[tail] times tail time if (tail++ == names.length - 1) {
			tail = 0;
		} tail++ == names.length - 1 tail++ tail names.length - 1 names.length names names.length 1 {
			tail = 0;
		} tail = 0 tail 0 String name name int time time public int dequeue() {
		if (head == names.length - 1) {
			head = 0;
			return names.length - 1;
		}
		return head++;
	} dequeue {
		if (head == names.length - 1) {
			head = 0;
			return names.length - 1;
		}
		return head++;
	} if (head == names.length - 1) {
			head = 0;
			return names.length - 1;
		} head == names.length - 1 head names.length - 1 names.length names names.length 1 {
			head = 0;
			return names.length - 1;
		} head = 0 head 0 return names.length - 1; names.length - 1 names.length names names.length 1 return head++; head++ head public boolean isEmpty() {
		return head == tail;
	} isEmpty {
		return head == tail;
	} return head == tail; head == tail head tail public String getName(int index) {
		return names[index];
	} getName {
		return names[index];
	} return names[index]; names[index] names index int index index public int getTime(int index) {
		return times[index];
	} getTime {
		return times[index];
	} return times[index]; times[index] times index int index index public class Main {

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] strs = br.readLine().split(" ");
		int n = Integer.parseInt(strs[0]);
		int q = Integer.parseInt(strs[1]);
		Queue queue = new Queue(n);
		StringBuilder sb = new StringBuilder();
		int sumTime = 0;
		for (int i = 0; i < n; i++) {
			strs = br.readLine().split(" ");
			int time = Integer.parseInt(strs[1]);
			if (time <= q) {
				sumTime += time;
				sb.append(strs[0] + " " + sumTime + "\n");
			} else {
				sumTime += q;
				queue.enqueue(strs[0], time - q);
			}
		}
		while (!queue.isEmpty()) {
			int entryIdx = queue.dequeue();
			String name = queue.getName(entryIdx);
			int time = queue.getTime(entryIdx);
			if (time <= q) {
				sumTime += time;
				sb.append(name + " " + sumTime + "\n");
			} else {
				sumTime += 	q;
				queue.enqueue(name, time - q);
			}
		}
		System.out.print(sb.toString());
	}
} Main public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] strs = br.readLine().split(" ");
		int n = Integer.parseInt(strs[0]);
		int q = Integer.parseInt(strs[1]);
		Queue queue = new Queue(n);
		StringBuilder sb = new StringBuilder();
		int sumTime = 0;
		for (int i = 0; i < n; i++) {
			strs = br.readLine().split(" ");
			int time = Integer.parseInt(strs[1]);
			if (time <= q) {
				sumTime += time;
				sb.append(strs[0] + " " + sumTime + "\n");
			} else {
				sumTime += q;
				queue.enqueue(strs[0], time - q);
			}
		}
		while (!queue.isEmpty()) {
			int entryIdx = queue.dequeue();
			String name = queue.getName(entryIdx);
			int time = queue.getTime(entryIdx);
			if (time <= q) {
				sumTime += time;
				sb.append(name + " " + sumTime + "\n");
			} else {
				sumTime += 	q;
				queue.enqueue(name, time - q);
			}
		}
		System.out.print(sb.toString());
	} main {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] strs = br.readLine().split(" ");
		int n = Integer.parseInt(strs[0]);
		int q = Integer.parseInt(strs[1]);
		Queue queue = new Queue(n);
		StringBuilder sb = new StringBuilder();
		int sumTime = 0;
		for (int i = 0; i < n; i++) {
			strs = br.readLine().split(" ");
			int time = Integer.parseInt(strs[1]);
			if (time <= q) {
				sumTime += time;
				sb.append(strs[0] + " " + sumTime + "\n");
			} else {
				sumTime += q;
				queue.enqueue(strs[0], time - q);
			}
		}
		while (!queue.isEmpty()) {
			int entryIdx = queue.dequeue();
			String name = queue.getName(entryIdx);
			int time = queue.getTime(entryIdx);
			if (time <= q) {
				sumTime += time;
				sb.append(name + " " + sumTime + "\n");
			} else {
				sumTime += 	q;
				queue.enqueue(name, time - q);
			}
		}
		System.out.print(sb.toString());
	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) String[] strs = br.readLine().split(" "); strs br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " int n = Integer.parseInt(strs[0]); n Integer.parseInt(strs[0]) Integer.parseInt Integer strs[0] strs 0 int q = Integer.parseInt(strs[1]); q Integer.parseInt(strs[1]) Integer.parseInt Integer strs[1] strs 1 Queue queue = new Queue(n); queue new Queue(n) StringBuilder sb = new StringBuilder(); sb new StringBuilder() int sumTime = 0; sumTime 0 for (int i = 0; i < n; i++) {
			strs = br.readLine().split(" ");
			int time = Integer.parseInt(strs[1]);
			if (time <= q) {
				sumTime += time;
				sb.append(strs[0] + " " + sumTime + "\n");
			} else {
				sumTime += q;
				queue.enqueue(strs[0], time - q);
			}
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			strs = br.readLine().split(" ");
			int time = Integer.parseInt(strs[1]);
			if (time <= q) {
				sumTime += time;
				sb.append(strs[0] + " " + sumTime + "\n");
			} else {
				sumTime += q;
				queue.enqueue(strs[0], time - q);
			}
		} {
			strs = br.readLine().split(" ");
			int time = Integer.parseInt(strs[1]);
			if (time <= q) {
				sumTime += time;
				sb.append(strs[0] + " " + sumTime + "\n");
			} else {
				sumTime += q;
				queue.enqueue(strs[0], time - q);
			}
		} strs = br.readLine().split(" ") strs br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " int time = Integer.parseInt(strs[1]); time Integer.parseInt(strs[1]) Integer.parseInt Integer strs[1] strs 1 if (time <= q) {
				sumTime += time;
				sb.append(strs[0] + " " + sumTime + "\n");
			} else {
				sumTime += q;
				queue.enqueue(strs[0], time - q);
			} time <= q time q {
				sumTime += time;
				sb.append(strs[0] + " " + sumTime + "\n");
			} sumTime += time sumTime time sb.append(strs[0] + " " + sumTime + "\n") sb.append sb strs[0] + " " + sumTime + "\n" sumTime strs[0] + " " + sumTime + "\n" strs[0] strs 0 " " sumTime "\n" {
				sumTime += q;
				queue.enqueue(strs[0], time - q);
			} sumTime += q sumTime q queue.enqueue(strs[0], time - q) queue.enqueue queue strs[0] strs 0 time - q time q while (!queue.isEmpty()) {
			int entryIdx = queue.dequeue();
			String name = queue.getName(entryIdx);
			int time = queue.getTime(entryIdx);
			if (time <= q) {
				sumTime += time;
				sb.append(name + " " + sumTime + "\n");
			} else {
				sumTime += 	q;
				queue.enqueue(name, time - q);
			}
		} !queue.isEmpty() queue.isEmpty() queue.isEmpty queue {
			int entryIdx = queue.dequeue();
			String name = queue.getName(entryIdx);
			int time = queue.getTime(entryIdx);
			if (time <= q) {
				sumTime += time;
				sb.append(name + " " + sumTime + "\n");
			} else {
				sumTime += 	q;
				queue.enqueue(name, time - q);
			}
		} int entryIdx = queue.dequeue(); entryIdx queue.dequeue() queue.dequeue queue String name = queue.getName(entryIdx); name queue.getName(entryIdx) queue.getName queue entryIdx int time = queue.getTime(entryIdx); time queue.getTime(entryIdx) queue.getTime queue entryIdx if (time <= q) {
				sumTime += time;
				sb.append(name + " " + sumTime + "\n");
			} else {
				sumTime += 	q;
				queue.enqueue(name, time - q);
			} time <= q time q {
				sumTime += time;
				sb.append(name + " " + sumTime + "\n");
			} sumTime += time sumTime time sb.append(name + " " + sumTime + "\n") sb.append sb name + " " + sumTime + "\n" sumTime name + " " + sumTime + "\n" name " " sumTime "\n" {
				sumTime += 	q;
				queue.enqueue(name, time - q);
			} sumTime += 	q sumTime q queue.enqueue(name, time - q) queue.enqueue queue name time - q time q 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));
		String[] strs = br.readLine().split(" ");
		int n = Integer.parseInt(strs[0]);
		int q = Integer.parseInt(strs[1]);
		Queue queue = new Queue(n);
		StringBuilder sb = new StringBuilder();
		int sumTime = 0;
		for (int i = 0; i < n; i++) {
			strs = br.readLine().split(" ");
			int time = Integer.parseInt(strs[1]);
			if (time <= q) {
				sumTime += time;
				sb.append(strs[0] + " " + sumTime + "\n");
			} else {
				sumTime += q;
				queue.enqueue(strs[0], time - q);
			}
		}
		while (!queue.isEmpty()) {
			int entryIdx = queue.dequeue();
			String name = queue.getName(entryIdx);
			int time = queue.getTime(entryIdx);
			if (time <= q) {
				sumTime += time;
				sb.append(name + " " + sumTime + "\n");
			} else {
				sumTime += 	q;
				queue.enqueue(name, time - q);
			}
		}
		System.out.print(sb.toString());
	}
} public class Main {

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] strs = br.readLine().split(" ");
		int n = Integer.parseInt(strs[0]);
		int q = Integer.parseInt(strs[1]);
		Queue queue = new Queue(n);
		StringBuilder sb = new StringBuilder();
		int sumTime = 0;
		for (int i = 0; i < n; i++) {
			strs = br.readLine().split(" ");
			int time = Integer.parseInt(strs[1]);
			if (time <= q) {
				sumTime += time;
				sb.append(strs[0] + " " + sumTime + "\n");
			} else {
				sumTime += q;
				queue.enqueue(strs[0], time - q);
			}
		}
		while (!queue.isEmpty()) {
			int entryIdx = queue.dequeue();
			String name = queue.getName(entryIdx);
			int time = queue.getTime(entryIdx);
			if (time <= q) {
				sumTime += time;
				sb.append(name + " " + sumTime + "\n");
			} else {
				sumTime += 	q;
				queue.enqueue(name, time - q);
			}
		}
		System.out.print(sb.toString());
	}
} Main
import java.io.BufferedReader;
import java.io.InputStreamReader;

class Queue {

	private String[] names;
	private int[] times;
	private int head;
	private int tail;
	public Queue(int size) {
		names = new String[size + 1];
		times = new int[size + 1];
	}

	public void enqueue(String name, int time) {
		names[tail] = name;
		times[tail] = time;
		if (tail++ == names.length - 1) {
			tail = 0;
		}
	}

	public int dequeue() {
		if (head == names.length - 1) {
			head = 0;
			return names.length - 1;
		}
		return head++;
	}

	public boolean isEmpty() {
		return head == tail;
	}

	public String getName(int index) {
		return names[index];
	}

	public int getTime(int index) {
		return times[index];
	}
}

public class Main {

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] strs = br.readLine().split(" ");
		int n = Integer.parseInt(strs[0]);
		int q = Integer.parseInt(strs[1]);
		Queue queue = new Queue(n);
		StringBuilder sb = new StringBuilder();
		int sumTime = 0;
		for (int i = 0; i < n; i++) {
			strs = br.readLine().split(" ");
			int time = Integer.parseInt(strs[1]);
			if (time <= q) {
				sumTime += time;
				sb.append(strs[0] + " " + sumTime + "\n");
			} else {
				sumTime += q;
				queue.enqueue(strs[0], time - q);
			}
		}
		while (!queue.isEmpty()) {
			int entryIdx = queue.dequeue();
			String name = queue.getName(entryIdx);
			int time = queue.getTime(entryIdx);
			if (time <= q) {
				sumTime += time;
				sb.append(name + " " + sumTime + "\n");
			} else {
				sumTime += 	q;
				queue.enqueue(name, time - q);
			}
		}
		System.out.print(sb.toString());
	}
}