import java.util.Scanner;


public class Main{

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		String[] one = s.nextLine().split(" ");
		QueueImpl qqq = new Main().new QueueImpl();
		for(int i=0 ; i<new Integer(one[0]).intValue() ; i++){
			String[] two = s.nextLine().split(" ");
			Process p = new Main().new Process(two[0], new Integer(two[1]).intValue());
			qqq.enqueue(p);
		}

		int quon = new Integer(one[1]).intValue();
		int totalTime = 0;
		while(! qqq.isEmpty()) {
			Process p = qqq.dequeue();
			if(quon >= p.time) {
				totalTime += p.time;
				System.out.println(p.name + " " + totalTime);
			}else {
				p.time = p.time - quon;
				qqq.enqueue(p);
				totalTime += quon;
			}
		}
	}

	public class QueueImpl {
		Process[] array;
		int head;
		int tail;
		public QueueImpl() {
			array = new Process[100000];
			head = -1;
			tail = -1;
		}

		public void enqueue(Process obj) {
			if(tail == 99999)
				tail = -1;
			tail++;
			array[tail] = obj;
		}

		public Process dequeue() {
			if(head == 99999)
				head = -1;
			head++;
			Process tmp = array[head];
			array[head] = null;
			return tmp;
		}

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

	public class Process {
		String name;
		int time;
		public Process(String name, int time) {
			this.name = name;
			this.time = time;
		}
	}
} import java.util.Scanner; Scanner java.util public class Main{

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		String[] one = s.nextLine().split(" ");
		QueueImpl qqq = new Main().new QueueImpl();
		for(int i=0 ; i<new Integer(one[0]).intValue() ; i++){
			String[] two = s.nextLine().split(" ");
			Process p = new Main().new Process(two[0], new Integer(two[1]).intValue());
			qqq.enqueue(p);
		}

		int quon = new Integer(one[1]).intValue();
		int totalTime = 0;
		while(! qqq.isEmpty()) {
			Process p = qqq.dequeue();
			if(quon >= p.time) {
				totalTime += p.time;
				System.out.println(p.name + " " + totalTime);
			}else {
				p.time = p.time - quon;
				qqq.enqueue(p);
				totalTime += quon;
			}
		}
	}

	public class QueueImpl {
		Process[] array;
		int head;
		int tail;
		public QueueImpl() {
			array = new Process[100000];
			head = -1;
			tail = -1;
		}

		public void enqueue(Process obj) {
			if(tail == 99999)
				tail = -1;
			tail++;
			array[tail] = obj;
		}

		public Process dequeue() {
			if(head == 99999)
				head = -1;
			head++;
			Process tmp = array[head];
			array[head] = null;
			return tmp;
		}

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

	public class Process {
		String name;
		int time;
		public Process(String name, int time) {
			this.name = name;
			this.time = time;
		}
	}
} Main public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		String[] one = s.nextLine().split(" ");
		QueueImpl qqq = new Main().new QueueImpl();
		for(int i=0 ; i<new Integer(one[0]).intValue() ; i++){
			String[] two = s.nextLine().split(" ");
			Process p = new Main().new Process(two[0], new Integer(two[1]).intValue());
			qqq.enqueue(p);
		}

		int quon = new Integer(one[1]).intValue();
		int totalTime = 0;
		while(! qqq.isEmpty()) {
			Process p = qqq.dequeue();
			if(quon >= p.time) {
				totalTime += p.time;
				System.out.println(p.name + " " + totalTime);
			}else {
				p.time = p.time - quon;
				qqq.enqueue(p);
				totalTime += quon;
			}
		}
	} main {
		Scanner s = new Scanner(System.in);
		String[] one = s.nextLine().split(" ");
		QueueImpl qqq = new Main().new QueueImpl();
		for(int i=0 ; i<new Integer(one[0]).intValue() ; i++){
			String[] two = s.nextLine().split(" ");
			Process p = new Main().new Process(two[0], new Integer(two[1]).intValue());
			qqq.enqueue(p);
		}

		int quon = new Integer(one[1]).intValue();
		int totalTime = 0;
		while(! qqq.isEmpty()) {
			Process p = qqq.dequeue();
			if(quon >= p.time) {
				totalTime += p.time;
				System.out.println(p.name + " " + totalTime);
			}else {
				p.time = p.time - quon;
				qqq.enqueue(p);
				totalTime += quon;
			}
		}
	} Scanner s = new Scanner(System.in); s new Scanner(System.in) String[] one = s.nextLine().split(" "); one s.nextLine().split(" ") s.nextLine().split s.nextLine() s.nextLine s " " QueueImpl qqq = new Main().new QueueImpl(); qqq new Main().new QueueImpl() new Main() new Main() for(int i=0 ; i<new Integer(one[0]).intValue() ; i++){
			String[] two = s.nextLine().split(" ");
			Process p = new Main().new Process(two[0], new Integer(two[1]).intValue());
			qqq.enqueue(p);
		} int i=0 ; int i=0 ; i 0 i<new Integer(one[0]).intValue() i new Integer(one[0]).intValue() new Integer(one[0]).intValue new Integer(one[0]) i++ i++ i {
			String[] two = s.nextLine().split(" ");
			Process p = new Main().new Process(two[0], new Integer(two[1]).intValue());
			qqq.enqueue(p);
		} {
			String[] two = s.nextLine().split(" ");
			Process p = new Main().new Process(two[0], new Integer(two[1]).intValue());
			qqq.enqueue(p);
		} String[] two = s.nextLine().split(" "); two s.nextLine().split(" ") s.nextLine().split s.nextLine() s.nextLine s " " Process p = new Main().new Process(two[0], new Integer(two[1]).intValue()); p new Main().new Process(two[0], new Integer(two[1]).intValue()) new Main() new Main() qqq.enqueue(p) qqq.enqueue qqq p int quon = new Integer(one[1]).intValue(); quon new Integer(one[1]).intValue() new Integer(one[1]).intValue new Integer(one[1]) int totalTime = 0; totalTime 0 while(! qqq.isEmpty()) {
			Process p = qqq.dequeue();
			if(quon >= p.time) {
				totalTime += p.time;
				System.out.println(p.name + " " + totalTime);
			}else {
				p.time = p.time - quon;
				qqq.enqueue(p);
				totalTime += quon;
			}
		} ! qqq.isEmpty() qqq.isEmpty() qqq.isEmpty qqq {
			Process p = qqq.dequeue();
			if(quon >= p.time) {
				totalTime += p.time;
				System.out.println(p.name + " " + totalTime);
			}else {
				p.time = p.time - quon;
				qqq.enqueue(p);
				totalTime += quon;
			}
		} Process p = qqq.dequeue(); p qqq.dequeue() qqq.dequeue qqq if(quon >= p.time) {
				totalTime += p.time;
				System.out.println(p.name + " " + totalTime);
			}else {
				p.time = p.time - quon;
				qqq.enqueue(p);
				totalTime += quon;
			} quon >= p.time quon p.time p p.time {
				totalTime += p.time;
				System.out.println(p.name + " " + totalTime);
			} totalTime += p.time totalTime p.time p p.time System.out.println(p.name + " " + totalTime) System.out.println System.out System System.out p.name + " " + totalTime p.name + " " + totalTime p.name p p.name " " totalTime {
				p.time = p.time - quon;
				qqq.enqueue(p);
				totalTime += quon;
			} p.time = p.time - quon p.time p p.time p.time - quon p.time p p.time quon qqq.enqueue(p) qqq.enqueue qqq p totalTime += quon totalTime quon String[] args args public class QueueImpl {
		Process[] array;
		int head;
		int tail;
		public QueueImpl() {
			array = new Process[100000];
			head = -1;
			tail = -1;
		}

		public void enqueue(Process obj) {
			if(tail == 99999)
				tail = -1;
			tail++;
			array[tail] = obj;
		}

		public Process dequeue() {
			if(head == 99999)
				head = -1;
			head++;
			Process tmp = array[head];
			array[head] = null;
			return tmp;
		}

		public boolean isEmpty(){
			return this.head == this.tail;
		}
	} QueueImpl Process[] array; array int head; head int tail; tail public QueueImpl() {
			array = new Process[100000];
			head = -1;
			tail = -1;
		} QueueImpl {
			array = new Process[100000];
			head = -1;
			tail = -1;
		} array = new Process[100000] array new Process[100000] 100000 head = -1 head -1 1 tail = -1 tail -1 1 public void enqueue(Process obj) {
			if(tail == 99999)
				tail = -1;
			tail++;
			array[tail] = obj;
		} enqueue {
			if(tail == 99999)
				tail = -1;
			tail++;
			array[tail] = obj;
		} if(tail == 99999)
				tail = -1; tail == 99999 tail 99999 tail = -1 tail -1 1 tail++ tail array[tail] = obj array[tail] array tail obj Process obj obj public Process dequeue() {
			if(head == 99999)
				head = -1;
			head++;
			Process tmp = array[head];
			array[head] = null;
			return tmp;
		} dequeue {
			if(head == 99999)
				head = -1;
			head++;
			Process tmp = array[head];
			array[head] = null;
			return tmp;
		} if(head == 99999)
				head = -1; head == 99999 head 99999 head = -1 head -1 1 head++ head Process tmp = array[head]; tmp array[head] array head array[head] = null array[head] array head null return tmp; tmp public boolean isEmpty(){
			return this.head == this.tail;
		} isEmpty {
			return this.head == this.tail;
		} return this.head == this.tail; this.head == this.tail this.head this this.head this.tail this this.tail public class Process {
		String name;
		int time;
		public Process(String name, int time) {
			this.name = name;
			this.time = time;
		}
	} Process String name; name int time; time public 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) {
		Scanner s = new Scanner(System.in);
		String[] one = s.nextLine().split(" ");
		QueueImpl qqq = new Main().new QueueImpl();
		for(int i=0 ; i<new Integer(one[0]).intValue() ; i++){
			String[] two = s.nextLine().split(" ");
			Process p = new Main().new Process(two[0], new Integer(two[1]).intValue());
			qqq.enqueue(p);
		}

		int quon = new Integer(one[1]).intValue();
		int totalTime = 0;
		while(! qqq.isEmpty()) {
			Process p = qqq.dequeue();
			if(quon >= p.time) {
				totalTime += p.time;
				System.out.println(p.name + " " + totalTime);
			}else {
				p.time = p.time - quon;
				qqq.enqueue(p);
				totalTime += quon;
			}
		}
	}

	public class QueueImpl {
		Process[] array;
		int head;
		int tail;
		public QueueImpl() {
			array = new Process[100000];
			head = -1;
			tail = -1;
		}

		public void enqueue(Process obj) {
			if(tail == 99999)
				tail = -1;
			tail++;
			array[tail] = obj;
		}

		public Process dequeue() {
			if(head == 99999)
				head = -1;
			head++;
			Process tmp = array[head];
			array[head] = null;
			return tmp;
		}

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

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

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		String[] one = s.nextLine().split(" ");
		QueueImpl qqq = new Main().new QueueImpl();
		for(int i=0 ; i<new Integer(one[0]).intValue() ; i++){
			String[] two = s.nextLine().split(" ");
			Process p = new Main().new Process(two[0], new Integer(two[1]).intValue());
			qqq.enqueue(p);
		}

		int quon = new Integer(one[1]).intValue();
		int totalTime = 0;
		while(! qqq.isEmpty()) {
			Process p = qqq.dequeue();
			if(quon >= p.time) {
				totalTime += p.time;
				System.out.println(p.name + " " + totalTime);
			}else {
				p.time = p.time - quon;
				qqq.enqueue(p);
				totalTime += quon;
			}
		}
	}

	public class QueueImpl {
		Process[] array;
		int head;
		int tail;
		public QueueImpl() {
			array = new Process[100000];
			head = -1;
			tail = -1;
		}

		public void enqueue(Process obj) {
			if(tail == 99999)
				tail = -1;
			tail++;
			array[tail] = obj;
		}

		public Process dequeue() {
			if(head == 99999)
				head = -1;
			head++;
			Process tmp = array[head];
			array[head] = null;
			return tmp;
		}

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

	public class Process {
		String name;
		int time;
		public Process(String name, int time) {
			this.name = name;
			this.time = time;
		}
	}
} Main
import java.util.Scanner;


public class Main{

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		String[] one = s.nextLine().split(" ");
		QueueImpl qqq = new Main().new QueueImpl();
		for(int i=0 ; i<new Integer(one[0]).intValue() ; i++){
			String[] two = s.nextLine().split(" ");
			Process p = new Main().new Process(two[0], new Integer(two[1]).intValue());
			qqq.enqueue(p);
		}

		int quon = new Integer(one[1]).intValue();
		int totalTime = 0;
		while(! qqq.isEmpty()) {
			Process p = qqq.dequeue();
			if(quon >= p.time) {
				totalTime += p.time;
				System.out.println(p.name + " " + totalTime);
			}else {
				p.time = p.time - quon;
				qqq.enqueue(p);
				totalTime += quon;
			}
		}
	}

	public class QueueImpl {
		Process[] array;
		int head;
		int tail;
		public QueueImpl() {
			array = new Process[100000];
			head = -1;
			tail = -1;
		}

		public void enqueue(Process obj) {
			if(tail == 99999)
				tail = -1;
			tail++;
			array[tail] = obj;
		}

		public Process dequeue() {
			if(head == 99999)
				head = -1;
			head++;
			Process tmp = array[head];
			array[head] = null;
			return tmp;
		}

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

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