import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		int n, q, time_cost = 0;
		Task temp = new Task();
		Queue costQueue = new Queue(), endQueue = new Queue();
		n = cin.nextInt();
		q = cin.nextInt();
		while (cin.hasNext()) {
			temp.name = cin.next();
			temp.costTime = cin.nextInt();
			costQueue.insert(temp);
		}
		while (!costQueue.empty()) {
			temp = costQueue.remove();
			if (temp.costTime <= q) {
				time_cost += temp.costTime;
				temp.endTime = time_cost;
				endQueue.insert(temp);
				continue;
			}
			time_cost += q;
			temp.costTime -= q;
			costQueue.insert(temp);
		}
		while (!endQueue.empty()) {
			temp = endQueue.remove();
			System.out.println(temp.name + " " + temp.endTime);
		}
	}
}

class Task {
	String name;
	int costTime;
	int endTime;
}

class Queue {
	int MAX = 100002;
	Task[] entry = new Task[MAX];
	int front;
	int rear;
	int count;
	public Queue() {
		for (int i = 0; i < MAX; i++) {
			entry[i] = new Task();
		}
		front = 0;
		rear = -1;
		count = 0;
	}
	public void insert(Task t) {
		rear = (rear + 1) % MAX;
		count++;
		entry[rear].name = t.name;
		entry[rear].costTime = t.costTime;
		entry[rear].endTime = t.endTime;
	}
	public Task remove() {
		Task temp = entry[front];
		front = (front + 1) % MAX;
		count--;
		return temp;
	}
	public boolean empty() {
		return (count == 0);
	}
} import java.util.*; util.* java public class Main {
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		int n, q, time_cost = 0;
		Task temp = new Task();
		Queue costQueue = new Queue(), endQueue = new Queue();
		n = cin.nextInt();
		q = cin.nextInt();
		while (cin.hasNext()) {
			temp.name = cin.next();
			temp.costTime = cin.nextInt();
			costQueue.insert(temp);
		}
		while (!costQueue.empty()) {
			temp = costQueue.remove();
			if (temp.costTime <= q) {
				time_cost += temp.costTime;
				temp.endTime = time_cost;
				endQueue.insert(temp);
				continue;
			}
			time_cost += q;
			temp.costTime -= q;
			costQueue.insert(temp);
		}
		while (!endQueue.empty()) {
			temp = endQueue.remove();
			System.out.println(temp.name + " " + temp.endTime);
		}
	}
} Main public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		int n, q, time_cost = 0;
		Task temp = new Task();
		Queue costQueue = new Queue(), endQueue = new Queue();
		n = cin.nextInt();
		q = cin.nextInt();
		while (cin.hasNext()) {
			temp.name = cin.next();
			temp.costTime = cin.nextInt();
			costQueue.insert(temp);
		}
		while (!costQueue.empty()) {
			temp = costQueue.remove();
			if (temp.costTime <= q) {
				time_cost += temp.costTime;
				temp.endTime = time_cost;
				endQueue.insert(temp);
				continue;
			}
			time_cost += q;
			temp.costTime -= q;
			costQueue.insert(temp);
		}
		while (!endQueue.empty()) {
			temp = endQueue.remove();
			System.out.println(temp.name + " " + temp.endTime);
		}
	} main {
		Scanner cin = new Scanner(System.in);
		int n, q, time_cost = 0;
		Task temp = new Task();
		Queue costQueue = new Queue(), endQueue = new Queue();
		n = cin.nextInt();
		q = cin.nextInt();
		while (cin.hasNext()) {
			temp.name = cin.next();
			temp.costTime = cin.nextInt();
			costQueue.insert(temp);
		}
		while (!costQueue.empty()) {
			temp = costQueue.remove();
			if (temp.costTime <= q) {
				time_cost += temp.costTime;
				temp.endTime = time_cost;
				endQueue.insert(temp);
				continue;
			}
			time_cost += q;
			temp.costTime -= q;
			costQueue.insert(temp);
		}
		while (!endQueue.empty()) {
			temp = endQueue.remove();
			System.out.println(temp.name + " " + temp.endTime);
		}
	} Scanner cin = new Scanner(System.in); cin new Scanner(System.in) int n n q q time_cost = 0; time_cost 0 Task temp = new Task(); temp new Task() Queue costQueue = new Queue() costQueue new Queue() endQueue = new Queue(); endQueue new Queue() n = cin.nextInt() n cin.nextInt() cin.nextInt cin q = cin.nextInt() q cin.nextInt() cin.nextInt cin while (cin.hasNext()) {
			temp.name = cin.next();
			temp.costTime = cin.nextInt();
			costQueue.insert(temp);
		} cin.hasNext() cin.hasNext cin {
			temp.name = cin.next();
			temp.costTime = cin.nextInt();
			costQueue.insert(temp);
		} temp.name = cin.next() temp.name temp temp.name cin.next() cin.next cin temp.costTime = cin.nextInt() temp.costTime temp temp.costTime cin.nextInt() cin.nextInt cin costQueue.insert(temp) costQueue.insert costQueue temp while (!costQueue.empty()) {
			temp = costQueue.remove();
			if (temp.costTime <= q) {
				time_cost += temp.costTime;
				temp.endTime = time_cost;
				endQueue.insert(temp);
				continue;
			}
			time_cost += q;
			temp.costTime -= q;
			costQueue.insert(temp);
		} !costQueue.empty() costQueue.empty() costQueue.empty costQueue {
			temp = costQueue.remove();
			if (temp.costTime <= q) {
				time_cost += temp.costTime;
				temp.endTime = time_cost;
				endQueue.insert(temp);
				continue;
			}
			time_cost += q;
			temp.costTime -= q;
			costQueue.insert(temp);
		} temp = costQueue.remove() temp costQueue.remove() costQueue.remove costQueue if (temp.costTime <= q) {
				time_cost += temp.costTime;
				temp.endTime = time_cost;
				endQueue.insert(temp);
				continue;
			} temp.costTime <= q temp.costTime temp temp.costTime q {
				time_cost += temp.costTime;
				temp.endTime = time_cost;
				endQueue.insert(temp);
				continue;
			} time_cost += temp.costTime time_cost temp.costTime temp temp.costTime temp.endTime = time_cost temp.endTime temp temp.endTime time_cost endQueue.insert(temp) endQueue.insert endQueue temp continue; time_cost += q time_cost q temp.costTime -= q temp.costTime temp temp.costTime q costQueue.insert(temp) costQueue.insert costQueue temp while (!endQueue.empty()) {
			temp = endQueue.remove();
			System.out.println(temp.name + " " + temp.endTime);
		} !endQueue.empty() endQueue.empty() endQueue.empty endQueue {
			temp = endQueue.remove();
			System.out.println(temp.name + " " + temp.endTime);
		} temp = endQueue.remove() temp endQueue.remove() endQueue.remove endQueue System.out.println(temp.name + " " + temp.endTime) System.out.println System.out System System.out temp.name + " " + temp.endTime temp.name + " " + temp.endTime temp.name temp temp.name " " temp.endTime temp temp.endTime String[] args args class Task {
	String name;
	int costTime;
	int endTime;
} Task String name; name int costTime; costTime int endTime; endTime class Queue {
	int MAX = 100002;
	Task[] entry = new Task[MAX];
	int front;
	int rear;
	int count;
	public Queue() {
		for (int i = 0; i < MAX; i++) {
			entry[i] = new Task();
		}
		front = 0;
		rear = -1;
		count = 0;
	}
	public void insert(Task t) {
		rear = (rear + 1) % MAX;
		count++;
		entry[rear].name = t.name;
		entry[rear].costTime = t.costTime;
		entry[rear].endTime = t.endTime;
	}
	public Task remove() {
		Task temp = entry[front];
		front = (front + 1) % MAX;
		count--;
		return temp;
	}
	public boolean empty() {
		return (count == 0);
	}
} Queue int MAX = 100002; MAX 100002 Task[] entry = new Task[MAX]; entry new Task[MAX] MAX int front; front int rear; rear int count; count public Queue() {
		for (int i = 0; i < MAX; i++) {
			entry[i] = new Task();
		}
		front = 0;
		rear = -1;
		count = 0;
	} Queue {
		for (int i = 0; i < MAX; i++) {
			entry[i] = new Task();
		}
		front = 0;
		rear = -1;
		count = 0;
	} for (int i = 0; i < MAX; i++) {
			entry[i] = new Task();
		} int i = 0; int i = 0; i 0 i < MAX i MAX i++ i++ i {
			entry[i] = new Task();
		} {
			entry[i] = new Task();
		} entry[i] = new Task() entry[i] entry i new Task() front = 0 front 0 rear = -1 rear -1 1 count = 0 count 0 public void insert(Task t) {
		rear = (rear + 1) % MAX;
		count++;
		entry[rear].name = t.name;
		entry[rear].costTime = t.costTime;
		entry[rear].endTime = t.endTime;
	} insert {
		rear = (rear + 1) % MAX;
		count++;
		entry[rear].name = t.name;
		entry[rear].costTime = t.costTime;
		entry[rear].endTime = t.endTime;
	} rear = (rear + 1) % MAX rear (rear + 1) % MAX (rear + 1) rear 1 MAX count++ count entry[rear].name = t.name entry[rear].name entry[rear] entry rear entry[rear].name t.name t t.name entry[rear].costTime = t.costTime entry[rear].costTime entry[rear] entry rear entry[rear].costTime t.costTime t t.costTime entry[rear].endTime = t.endTime entry[rear].endTime entry[rear] entry rear entry[rear].endTime t.endTime t t.endTime Task t t public Task remove() {
		Task temp = entry[front];
		front = (front + 1) % MAX;
		count--;
		return temp;
	} remove {
		Task temp = entry[front];
		front = (front + 1) % MAX;
		count--;
		return temp;
	} Task temp = entry[front]; temp entry[front] entry front front = (front + 1) % MAX front (front + 1) % MAX (front + 1) front 1 MAX count-- count return temp; temp public boolean empty() {
		return (count == 0);
	} empty {
		return (count == 0);
	} return (count == 0); (count == 0) count 0 public class Main {
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		int n, q, time_cost = 0;
		Task temp = new Task();
		Queue costQueue = new Queue(), endQueue = new Queue();
		n = cin.nextInt();
		q = cin.nextInt();
		while (cin.hasNext()) {
			temp.name = cin.next();
			temp.costTime = cin.nextInt();
			costQueue.insert(temp);
		}
		while (!costQueue.empty()) {
			temp = costQueue.remove();
			if (temp.costTime <= q) {
				time_cost += temp.costTime;
				temp.endTime = time_cost;
				endQueue.insert(temp);
				continue;
			}
			time_cost += q;
			temp.costTime -= q;
			costQueue.insert(temp);
		}
		while (!endQueue.empty()) {
			temp = endQueue.remove();
			System.out.println(temp.name + " " + temp.endTime);
		}
	}
} public class Main {
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		int n, q, time_cost = 0;
		Task temp = new Task();
		Queue costQueue = new Queue(), endQueue = new Queue();
		n = cin.nextInt();
		q = cin.nextInt();
		while (cin.hasNext()) {
			temp.name = cin.next();
			temp.costTime = cin.nextInt();
			costQueue.insert(temp);
		}
		while (!costQueue.empty()) {
			temp = costQueue.remove();
			if (temp.costTime <= q) {
				time_cost += temp.costTime;
				temp.endTime = time_cost;
				endQueue.insert(temp);
				continue;
			}
			time_cost += q;
			temp.costTime -= q;
			costQueue.insert(temp);
		}
		while (!endQueue.empty()) {
			temp = endQueue.remove();
			System.out.println(temp.name + " " + temp.endTime);
		}
	}
} Main
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		int n, q, time_cost = 0;
		Task temp = new Task();
		Queue costQueue = new Queue(), endQueue = new Queue();
		n = cin.nextInt();
		q = cin.nextInt();
		while (cin.hasNext()) {
			temp.name = cin.next();
			temp.costTime = cin.nextInt();
			costQueue.insert(temp);
		}
		while (!costQueue.empty()) {
			temp = costQueue.remove();
			if (temp.costTime <= q) {
				time_cost += temp.costTime;
				temp.endTime = time_cost;
				endQueue.insert(temp);
				continue;
			}
			time_cost += q;
			temp.costTime -= q;
			costQueue.insert(temp);
		}
		while (!endQueue.empty()) {
			temp = endQueue.remove();
			System.out.println(temp.name + " " + temp.endTime);
		}
	}
}

class Task {
	String name;
	int costTime;
	int endTime;
}

class Queue {
	int MAX = 100002;
	Task[] entry = new Task[MAX];
	int front;
	int rear;
	int count;
	public Queue() {
		for (int i = 0; i < MAX; i++) {
			entry[i] = new Task();
		}
		front = 0;
		rear = -1;
		count = 0;
	}
	public void insert(Task t) {
		rear = (rear + 1) % MAX;
		count++;
		entry[rear].name = t.name;
		entry[rear].costTime = t.costTime;
		entry[rear].endTime = t.endTime;
	}
	public Task remove() {
		Task temp = entry[front];
		front = (front + 1) % MAX;
		count--;
		return temp;
	}
	public boolean empty() {
		return (count == 0);
	}
}
