import java.util.Scanner;

public class Main {

	static class Node<E> {
		public E value;
		public Node<E> next;		
		public Node(E value) {
			this.value = value;
			this.next = null;
		}
	}

	static class SimpleQueue<E> {
		
		private Node<E> head;
		private Node<E> tail;
		int size;
		
		public SimpleQueue() {
			size = 0;
			head = null;
			tail = null;
		}
		
		public int getSize() {
			return size;
		}
		
		public boolean isEmpty() {
			return size == 0;
		}
		
		public void enqueue(E element) {
			Node<E> node = new Node<E>(element);
			if (head == null && tail == null) {
				head = tail = node;
			} else {
				tail.next = node;
				tail = node;
			}
			size++;
		}
		
		public E dequeue() {			
			if (isEmpty()) {
				return null;
			}
			E element = head.value;
			head = head.next;
			if (head == null) {
				tail = null;
			}
			size--;
			return element;			
		}
		
		public String toString() {
			StringBuilder sb = new StringBuilder();
			sb.append("[");
			Node<E> current = head;
			while (current != null) {
				sb.append(current.value);
				current = current.next;
				if (current != null) {
					sb.append(", ");
				}
			}			
			sb.append("](");
			if (tail != null) {
				sb.append(tail.value);
			}
			sb.append(")");
			return sb.toString();
		}		
	}
	
	static class Process {		
		public String name;
		public int time;		
		public Process(String name, int time) {
			this.name = name;
			this.time = time;
		}		
	}
	
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int q = sc.nextInt();
		
		SimpleQueue<Process> queue = new SimpleQueue<Process>();
		for (int i = 0; i < n; i++) {
			String name = sc.next();
			int time = sc.nextInt();
			queue.enqueue(new Process(name, time));
		}
		sc.close();

		int total = 0;
		while (!queue.isEmpty()) {
			
			Process process = queue.dequeue();
			if (process.time > q) {
				process.time = process.time - q;
				total += q;
				queue.enqueue(process);
			} else {
				total += process.time;
				System.out.println(process.name + " " + total);
			}			
		}
	}
}

 import java.util.Scanner; Scanner java.util public class Main {

	static class Node<E> {
		public E value;
		public Node<E> next;		
		public Node(E value) {
			this.value = value;
			this.next = null;
		}
	}

	static class SimpleQueue<E> {
		
		private Node<E> head;
		private Node<E> tail;
		int size;
		
		public SimpleQueue() {
			size = 0;
			head = null;
			tail = null;
		}
		
		public int getSize() {
			return size;
		}
		
		public boolean isEmpty() {
			return size == 0;
		}
		
		public void enqueue(E element) {
			Node<E> node = new Node<E>(element);
			if (head == null && tail == null) {
				head = tail = node;
			} else {
				tail.next = node;
				tail = node;
			}
			size++;
		}
		
		public E dequeue() {			
			if (isEmpty()) {
				return null;
			}
			E element = head.value;
			head = head.next;
			if (head == null) {
				tail = null;
			}
			size--;
			return element;			
		}
		
		public String toString() {
			StringBuilder sb = new StringBuilder();
			sb.append("[");
			Node<E> current = head;
			while (current != null) {
				sb.append(current.value);
				current = current.next;
				if (current != null) {
					sb.append(", ");
				}
			}			
			sb.append("](");
			if (tail != null) {
				sb.append(tail.value);
			}
			sb.append(")");
			return sb.toString();
		}		
	}
	
	static class Process {		
		public String name;
		public int time;		
		public Process(String name, int time) {
			this.name = name;
			this.time = time;
		}		
	}
	
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int q = sc.nextInt();
		
		SimpleQueue<Process> queue = new SimpleQueue<Process>();
		for (int i = 0; i < n; i++) {
			String name = sc.next();
			int time = sc.nextInt();
			queue.enqueue(new Process(name, time));
		}
		sc.close();

		int total = 0;
		while (!queue.isEmpty()) {
			
			Process process = queue.dequeue();
			if (process.time > q) {
				process.time = process.time - q;
				total += q;
				queue.enqueue(process);
			} else {
				total += process.time;
				System.out.println(process.name + " " + total);
			}			
		}
	}
} Main public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int q = sc.nextInt();
		
		SimpleQueue<Process> queue = new SimpleQueue<Process>();
		for (int i = 0; i < n; i++) {
			String name = sc.next();
			int time = sc.nextInt();
			queue.enqueue(new Process(name, time));
		}
		sc.close();

		int total = 0;
		while (!queue.isEmpty()) {
			
			Process process = queue.dequeue();
			if (process.time > q) {
				process.time = process.time - q;
				total += q;
				queue.enqueue(process);
			} else {
				total += process.time;
				System.out.println(process.name + " " + total);
			}			
		}
	} main {
		
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int q = sc.nextInt();
		
		SimpleQueue<Process> queue = new SimpleQueue<Process>();
		for (int i = 0; i < n; i++) {
			String name = sc.next();
			int time = sc.nextInt();
			queue.enqueue(new Process(name, time));
		}
		sc.close();

		int total = 0;
		while (!queue.isEmpty()) {
			
			Process process = queue.dequeue();
			if (process.time > q) {
				process.time = process.time - q;
				total += q;
				queue.enqueue(process);
			} else {
				total += process.time;
				System.out.println(process.name + " " + total);
			}			
		}
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int q = sc.nextInt(); q sc.nextInt() sc.nextInt sc SimpleQueue<Process> queue = new SimpleQueue<Process>(); queue new SimpleQueue<Process>() for (int i = 0; i < n; i++) {
			String name = sc.next();
			int time = sc.nextInt();
			queue.enqueue(new Process(name, time));
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			String name = sc.next();
			int time = sc.nextInt();
			queue.enqueue(new Process(name, time));
		} {
			String name = sc.next();
			int time = sc.nextInt();
			queue.enqueue(new Process(name, time));
		} String name = sc.next(); name sc.next() sc.next sc int time = sc.nextInt(); time sc.nextInt() sc.nextInt sc queue.enqueue(new Process(name, time)) queue.enqueue queue new Process(name, time) sc.close() sc.close sc int total = 0; total 0 while (!queue.isEmpty()) {
			
			Process process = queue.dequeue();
			if (process.time > q) {
				process.time = process.time - q;
				total += q;
				queue.enqueue(process);
			} else {
				total += process.time;
				System.out.println(process.name + " " + total);
			}			
		} !queue.isEmpty() queue.isEmpty() queue.isEmpty queue {
			
			Process process = queue.dequeue();
			if (process.time > q) {
				process.time = process.time - q;
				total += q;
				queue.enqueue(process);
			} else {
				total += process.time;
				System.out.println(process.name + " " + total);
			}			
		} Process process = queue.dequeue(); process queue.dequeue() queue.dequeue queue if (process.time > q) {
				process.time = process.time - q;
				total += q;
				queue.enqueue(process);
			} else {
				total += process.time;
				System.out.println(process.name + " " + total);
			} process.time > q process.time process process.time q {
				process.time = process.time - q;
				total += q;
				queue.enqueue(process);
			} process.time = process.time - q process.time process process.time process.time - q process.time process process.time q total += q total q queue.enqueue(process) queue.enqueue queue process {
				total += process.time;
				System.out.println(process.name + " " + total);
			} total += process.time total process.time process process.time System.out.println(process.name + " " + total) System.out.println System.out System System.out process.name + " " + total process.name + " " + total process.name process process.name " " total String[] args args static class Node<E> {
		public E value;
		public Node<E> next;		
		public Node(E value) {
			this.value = value;
			this.next = null;
		}
	} Node public E value; value public Node<E> next; next public Node(E value) {
			this.value = value;
			this.next = null;
		} Node {
			this.value = value;
			this.next = null;
		} this.value = value this.value this this.value value this.next = null this.next this this.next null E value value static class SimpleQueue<E> {
		
		private Node<E> head;
		private Node<E> tail;
		int size;
		
		public SimpleQueue() {
			size = 0;
			head = null;
			tail = null;
		}
		
		public int getSize() {
			return size;
		}
		
		public boolean isEmpty() {
			return size == 0;
		}
		
		public void enqueue(E element) {
			Node<E> node = new Node<E>(element);
			if (head == null && tail == null) {
				head = tail = node;
			} else {
				tail.next = node;
				tail = node;
			}
			size++;
		}
		
		public E dequeue() {			
			if (isEmpty()) {
				return null;
			}
			E element = head.value;
			head = head.next;
			if (head == null) {
				tail = null;
			}
			size--;
			return element;			
		}
		
		public String toString() {
			StringBuilder sb = new StringBuilder();
			sb.append("[");
			Node<E> current = head;
			while (current != null) {
				sb.append(current.value);
				current = current.next;
				if (current != null) {
					sb.append(", ");
				}
			}			
			sb.append("](");
			if (tail != null) {
				sb.append(tail.value);
			}
			sb.append(")");
			return sb.toString();
		}		
	} SimpleQueue private Node<E> head; head private Node<E> tail; tail int size; size public SimpleQueue() {
			size = 0;
			head = null;
			tail = null;
		} SimpleQueue {
			size = 0;
			head = null;
			tail = null;
		} size = 0 size 0 head = null head null tail = null tail null public int getSize() {
			return size;
		} getSize {
			return size;
		} return size; size public boolean isEmpty() {
			return size == 0;
		} isEmpty {
			return size == 0;
		} return size == 0; size == 0 size 0 public void enqueue(E element) {
			Node<E> node = new Node<E>(element);
			if (head == null && tail == null) {
				head = tail = node;
			} else {
				tail.next = node;
				tail = node;
			}
			size++;
		} enqueue {
			Node<E> node = new Node<E>(element);
			if (head == null && tail == null) {
				head = tail = node;
			} else {
				tail.next = node;
				tail = node;
			}
			size++;
		} Node<E> node = new Node<E>(element); node new Node<E>(element) if (head == null && tail == null) {
				head = tail = node;
			} else {
				tail.next = node;
				tail = node;
			} head == null && tail == null head == null head null tail == null tail null {
				head = tail = node;
			} head = tail = node head tail = node tail node {
				tail.next = node;
				tail = node;
			} tail.next = node tail.next tail tail.next node tail = node tail node size++ size E element element public E dequeue() {			
			if (isEmpty()) {
				return null;
			}
			E element = head.value;
			head = head.next;
			if (head == null) {
				tail = null;
			}
			size--;
			return element;			
		} dequeue {			
			if (isEmpty()) {
				return null;
			}
			E element = head.value;
			head = head.next;
			if (head == null) {
				tail = null;
			}
			size--;
			return element;			
		} if (isEmpty()) {
				return null;
			} isEmpty() isEmpty {
				return null;
			} return null; null E element = head.value; element head.value head head.value head = head.next head head.next head head.next if (head == null) {
				tail = null;
			} head == null head null {
				tail = null;
			} tail = null tail null size-- size return element; element public String toString() {
			StringBuilder sb = new StringBuilder();
			sb.append("[");
			Node<E> current = head;
			while (current != null) {
				sb.append(current.value);
				current = current.next;
				if (current != null) {
					sb.append(", ");
				}
			}			
			sb.append("](");
			if (tail != null) {
				sb.append(tail.value);
			}
			sb.append(")");
			return sb.toString();
		} toString {
			StringBuilder sb = new StringBuilder();
			sb.append("[");
			Node<E> current = head;
			while (current != null) {
				sb.append(current.value);
				current = current.next;
				if (current != null) {
					sb.append(", ");
				}
			}			
			sb.append("](");
			if (tail != null) {
				sb.append(tail.value);
			}
			sb.append(")");
			return sb.toString();
		} StringBuilder sb = new StringBuilder(); sb new StringBuilder() sb.append("[") sb.append sb "[" Node<E> current = head; current head while (current != null) {
				sb.append(current.value);
				current = current.next;
				if (current != null) {
					sb.append(", ");
				}
			} current != null current null {
				sb.append(current.value);
				current = current.next;
				if (current != null) {
					sb.append(", ");
				}
			} sb.append(current.value) sb.append sb current.value current current.value current = current.next current current.next current current.next if (current != null) {
					sb.append(", ");
				} current != null current null {
					sb.append(", ");
				} sb.append(", ") sb.append sb ", " sb.append("](") sb.append sb "](" if (tail != null) {
				sb.append(tail.value);
			} tail != null tail null {
				sb.append(tail.value);
			} sb.append(tail.value) sb.append sb tail.value tail tail.value sb.append(")") sb.append sb ")" return sb.toString(); sb.toString() sb.toString sb static class Process {		
		public String name;
		public int time;		
		public Process(String name, int time) {
			this.name = name;
			this.time = time;
		}		
	} Process public String name; name public 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 {

	static class Node<E> {
		public E value;
		public Node<E> next;		
		public Node(E value) {
			this.value = value;
			this.next = null;
		}
	}

	static class SimpleQueue<E> {
		
		private Node<E> head;
		private Node<E> tail;
		int size;
		
		public SimpleQueue() {
			size = 0;
			head = null;
			tail = null;
		}
		
		public int getSize() {
			return size;
		}
		
		public boolean isEmpty() {
			return size == 0;
		}
		
		public void enqueue(E element) {
			Node<E> node = new Node<E>(element);
			if (head == null && tail == null) {
				head = tail = node;
			} else {
				tail.next = node;
				tail = node;
			}
			size++;
		}
		
		public E dequeue() {			
			if (isEmpty()) {
				return null;
			}
			E element = head.value;
			head = head.next;
			if (head == null) {
				tail = null;
			}
			size--;
			return element;			
		}
		
		public String toString() {
			StringBuilder sb = new StringBuilder();
			sb.append("[");
			Node<E> current = head;
			while (current != null) {
				sb.append(current.value);
				current = current.next;
				if (current != null) {
					sb.append(", ");
				}
			}			
			sb.append("](");
			if (tail != null) {
				sb.append(tail.value);
			}
			sb.append(")");
			return sb.toString();
		}		
	}
	
	static class Process {		
		public String name;
		public int time;		
		public Process(String name, int time) {
			this.name = name;
			this.time = time;
		}		
	}
	
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int q = sc.nextInt();
		
		SimpleQueue<Process> queue = new SimpleQueue<Process>();
		for (int i = 0; i < n; i++) {
			String name = sc.next();
			int time = sc.nextInt();
			queue.enqueue(new Process(name, time));
		}
		sc.close();

		int total = 0;
		while (!queue.isEmpty()) {
			
			Process process = queue.dequeue();
			if (process.time > q) {
				process.time = process.time - q;
				total += q;
				queue.enqueue(process);
			} else {
				total += process.time;
				System.out.println(process.name + " " + total);
			}			
		}
	}
} public class Main {

	static class Node<E> {
		public E value;
		public Node<E> next;		
		public Node(E value) {
			this.value = value;
			this.next = null;
		}
	}

	static class SimpleQueue<E> {
		
		private Node<E> head;
		private Node<E> tail;
		int size;
		
		public SimpleQueue() {
			size = 0;
			head = null;
			tail = null;
		}
		
		public int getSize() {
			return size;
		}
		
		public boolean isEmpty() {
			return size == 0;
		}
		
		public void enqueue(E element) {
			Node<E> node = new Node<E>(element);
			if (head == null && tail == null) {
				head = tail = node;
			} else {
				tail.next = node;
				tail = node;
			}
			size++;
		}
		
		public E dequeue() {			
			if (isEmpty()) {
				return null;
			}
			E element = head.value;
			head = head.next;
			if (head == null) {
				tail = null;
			}
			size--;
			return element;			
		}
		
		public String toString() {
			StringBuilder sb = new StringBuilder();
			sb.append("[");
			Node<E> current = head;
			while (current != null) {
				sb.append(current.value);
				current = current.next;
				if (current != null) {
					sb.append(", ");
				}
			}			
			sb.append("](");
			if (tail != null) {
				sb.append(tail.value);
			}
			sb.append(")");
			return sb.toString();
		}		
	}
	
	static class Process {		
		public String name;
		public int time;		
		public Process(String name, int time) {
			this.name = name;
			this.time = time;
		}		
	}
	
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int q = sc.nextInt();
		
		SimpleQueue<Process> queue = new SimpleQueue<Process>();
		for (int i = 0; i < n; i++) {
			String name = sc.next();
			int time = sc.nextInt();
			queue.enqueue(new Process(name, time));
		}
		sc.close();

		int total = 0;
		while (!queue.isEmpty()) {
			
			Process process = queue.dequeue();
			if (process.time > q) {
				process.time = process.time - q;
				total += q;
				queue.enqueue(process);
			} else {
				total += process.time;
				System.out.println(process.name + " " + total);
			}			
		}
	}
} Main
import java.util.Scanner;

public class Main {

	static class Node<E> {
		public E value;
		public Node<E> next;		
		public Node(E value) {
			this.value = value;
			this.next = null;
		}
	}

	static class SimpleQueue<E> {
		
		private Node<E> head;
		private Node<E> tail;
		int size;
		
		public SimpleQueue() {
			size = 0;
			head = null;
			tail = null;
		}
		
		public int getSize() {
			return size;
		}
		
		public boolean isEmpty() {
			return size == 0;
		}
		
		public void enqueue(E element) {
			Node<E> node = new Node<E>(element);
			if (head == null && tail == null) {
				head = tail = node;
			} else {
				tail.next = node;
				tail = node;
			}
			size++;
		}
		
		public E dequeue() {			
			if (isEmpty()) {
				return null;
			}
			E element = head.value;
			head = head.next;
			if (head == null) {
				tail = null;
			}
			size--;
			return element;			
		}
		
		public String toString() {
			StringBuilder sb = new StringBuilder();
			sb.append("[");
			Node<E> current = head;
			while (current != null) {
				sb.append(current.value);
				current = current.next;
				if (current != null) {
					sb.append(", ");
				}
			}			
			sb.append("](");
			if (tail != null) {
				sb.append(tail.value);
			}
			sb.append(")");
			return sb.toString();
		}		
	}
	
	static class Process {		
		public String name;
		public int time;		
		public Process(String name, int time) {
			this.name = name;
			this.time = time;
		}		
	}
	
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int q = sc.nextInt();
		
		SimpleQueue<Process> queue = new SimpleQueue<Process>();
		for (int i = 0; i < n; i++) {
			String name = sc.next();
			int time = sc.nextInt();
			queue.enqueue(new Process(name, time));
		}
		sc.close();

		int total = 0;
		while (!queue.isEmpty()) {
			
			Process process = queue.dequeue();
			if (process.time > q) {
				process.time = process.time - q;
				total += q;
				queue.enqueue(process);
			} else {
				total += process.time;
				System.out.println(process.name + " " + total);
			}			
		}
	}
}


