import java.util.Scanner;

public class Main {

	static int max;
	static int Q[];
	static String P[];
	static int head;
	static int tail;

	static void initialize() {
		head = 0;
		tail = 0;
	}

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

	static boolean isFull() {
		return head == (tail+1)%max;
	}

	static void enqueue1(int x) {
		if(!isFull()) {
			Q[tail] = x;
			if(tail+1 ==max) {
				tail = 0;
			}else {
				tail++;
			}
		}
	}

	static void enqueue2(String s) {
		if(!isFull()) {
			P[tail] = s;
		}
	}

	static int dequeue1() {
		if(!isEmpty()) {
			int x = Q[head];
			if(head+1 == max) {
				head = 0;
			}else {
				head++;
			}
			return x;
		}else {
			return -1;
		}
	}

	static String  dequeue2() {
		if(!isEmpty()) {
			String s = P[head];
			return s;
		}else {
			return "";
		}
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		max = n + 1;
		P = new String[max];
		Q = new int[max];
		int q = sc.nextInt();
		initialize();
		
		for(int i=0;i<n;i++) {
			enqueue2(sc.next());
			enqueue1(sc.nextInt());
		}
		int time = 0;
		while(!isEmpty()) {
			String s = dequeue2();
			int x = dequeue1();
			if(x <= q) {
				time += x;
				System.out.println(s + " " + time);
			}else {
				x -= q;
				enqueue2(s);
				enqueue1(x);
				time += q;
			}
		}

	 }
}

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

	static int max;
	static int Q[];
	static String P[];
	static int head;
	static int tail;

	static void initialize() {
		head = 0;
		tail = 0;
	}

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

	static boolean isFull() {
		return head == (tail+1)%max;
	}

	static void enqueue1(int x) {
		if(!isFull()) {
			Q[tail] = x;
			if(tail+1 ==max) {
				tail = 0;
			}else {
				tail++;
			}
		}
	}

	static void enqueue2(String s) {
		if(!isFull()) {
			P[tail] = s;
		}
	}

	static int dequeue1() {
		if(!isEmpty()) {
			int x = Q[head];
			if(head+1 == max) {
				head = 0;
			}else {
				head++;
			}
			return x;
		}else {
			return -1;
		}
	}

	static String  dequeue2() {
		if(!isEmpty()) {
			String s = P[head];
			return s;
		}else {
			return "";
		}
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		max = n + 1;
		P = new String[max];
		Q = new int[max];
		int q = sc.nextInt();
		initialize();
		
		for(int i=0;i<n;i++) {
			enqueue2(sc.next());
			enqueue1(sc.nextInt());
		}
		int time = 0;
		while(!isEmpty()) {
			String s = dequeue2();
			int x = dequeue1();
			if(x <= q) {
				time += x;
				System.out.println(s + " " + time);
			}else {
				x -= q;
				enqueue2(s);
				enqueue1(x);
				time += q;
			}
		}

	 }
} Main static int max; max static int Q[]; Q static String P[]; P static int head; head static int tail; tail static void initialize() {
		head = 0;
		tail = 0;
	} initialize {
		head = 0;
		tail = 0;
	} head = 0 head 0 tail = 0 tail 0 static boolean isEmpty() {
		return head == tail;
	} isEmpty {
		return head == tail;
	} return head == tail; head == tail head tail static boolean isFull() {
		return head == (tail+1)%max;
	} isFull {
		return head == (tail+1)%max;
	} return head == (tail+1)%max; head == (tail+1)%max head (tail+1)%max (tail+1) tail 1 max static void enqueue1(int x) {
		if(!isFull()) {
			Q[tail] = x;
			if(tail+1 ==max) {
				tail = 0;
			}else {
				tail++;
			}
		}
	} enqueue1 {
		if(!isFull()) {
			Q[tail] = x;
			if(tail+1 ==max) {
				tail = 0;
			}else {
				tail++;
			}
		}
	} if(!isFull()) {
			Q[tail] = x;
			if(tail+1 ==max) {
				tail = 0;
			}else {
				tail++;
			}
		} !isFull() isFull() isFull {
			Q[tail] = x;
			if(tail+1 ==max) {
				tail = 0;
			}else {
				tail++;
			}
		} Q[tail] = x Q[tail] Q tail x if(tail+1 ==max) {
				tail = 0;
			}else {
				tail++;
			} tail+1 ==max tail+1 tail 1 max {
				tail = 0;
			} tail = 0 tail 0 {
				tail++;
			} tail++ tail int x x static void enqueue2(String s) {
		if(!isFull()) {
			P[tail] = s;
		}
	} enqueue2 {
		if(!isFull()) {
			P[tail] = s;
		}
	} if(!isFull()) {
			P[tail] = s;
		} !isFull() isFull() isFull {
			P[tail] = s;
		} P[tail] = s P[tail] P tail s String s s static int dequeue1() {
		if(!isEmpty()) {
			int x = Q[head];
			if(head+1 == max) {
				head = 0;
			}else {
				head++;
			}
			return x;
		}else {
			return -1;
		}
	} dequeue1 {
		if(!isEmpty()) {
			int x = Q[head];
			if(head+1 == max) {
				head = 0;
			}else {
				head++;
			}
			return x;
		}else {
			return -1;
		}
	} if(!isEmpty()) {
			int x = Q[head];
			if(head+1 == max) {
				head = 0;
			}else {
				head++;
			}
			return x;
		}else {
			return -1;
		} !isEmpty() isEmpty() isEmpty {
			int x = Q[head];
			if(head+1 == max) {
				head = 0;
			}else {
				head++;
			}
			return x;
		} int x = Q[head]; x Q[head] Q head if(head+1 == max) {
				head = 0;
			}else {
				head++;
			} head+1 == max head+1 head 1 max {
				head = 0;
			} head = 0 head 0 {
				head++;
			} head++ head return x; x {
			return -1;
		} return -1; -1 1 static String  dequeue2() {
		if(!isEmpty()) {
			String s = P[head];
			return s;
		}else {
			return "";
		}
	} dequeue2 {
		if(!isEmpty()) {
			String s = P[head];
			return s;
		}else {
			return "";
		}
	} if(!isEmpty()) {
			String s = P[head];
			return s;
		}else {
			return "";
		} !isEmpty() isEmpty() isEmpty {
			String s = P[head];
			return s;
		} String s = P[head]; s P[head] P head return s; s {
			return "";
		} return ""; "" public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		max = n + 1;
		P = new String[max];
		Q = new int[max];
		int q = sc.nextInt();
		initialize();
		
		for(int i=0;i<n;i++) {
			enqueue2(sc.next());
			enqueue1(sc.nextInt());
		}
		int time = 0;
		while(!isEmpty()) {
			String s = dequeue2();
			int x = dequeue1();
			if(x <= q) {
				time += x;
				System.out.println(s + " " + time);
			}else {
				x -= q;
				enqueue2(s);
				enqueue1(x);
				time += q;
			}
		}

	 } main {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		max = n + 1;
		P = new String[max];
		Q = new int[max];
		int q = sc.nextInt();
		initialize();
		
		for(int i=0;i<n;i++) {
			enqueue2(sc.next());
			enqueue1(sc.nextInt());
		}
		int time = 0;
		while(!isEmpty()) {
			String s = dequeue2();
			int x = dequeue1();
			if(x <= q) {
				time += x;
				System.out.println(s + " " + time);
			}else {
				x -= q;
				enqueue2(s);
				enqueue1(x);
				time += q;
			}
		}

	 } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc max = n + 1 max n + 1 n 1 P = new String[max] P new String[max] max Q = new int[max] Q new int[max] max int q = sc.nextInt(); q sc.nextInt() sc.nextInt sc initialize() initialize for(int i=0;i<n;i++) {
			enqueue2(sc.next());
			enqueue1(sc.nextInt());
		} int i=0; int i=0; i 0 i<n i n i++ i++ i {
			enqueue2(sc.next());
			enqueue1(sc.nextInt());
		} {
			enqueue2(sc.next());
			enqueue1(sc.nextInt());
		} enqueue2(sc.next()) enqueue2 sc.next() sc.next sc enqueue1(sc.nextInt()) enqueue1 sc.nextInt() sc.nextInt sc int time = 0; time 0 while(!isEmpty()) {
			String s = dequeue2();
			int x = dequeue1();
			if(x <= q) {
				time += x;
				System.out.println(s + " " + time);
			}else {
				x -= q;
				enqueue2(s);
				enqueue1(x);
				time += q;
			}
		} !isEmpty() isEmpty() isEmpty {
			String s = dequeue2();
			int x = dequeue1();
			if(x <= q) {
				time += x;
				System.out.println(s + " " + time);
			}else {
				x -= q;
				enqueue2(s);
				enqueue1(x);
				time += q;
			}
		} String s = dequeue2(); s dequeue2() dequeue2 int x = dequeue1(); x dequeue1() dequeue1 if(x <= q) {
				time += x;
				System.out.println(s + " " + time);
			}else {
				x -= q;
				enqueue2(s);
				enqueue1(x);
				time += q;
			} x <= q x q {
				time += x;
				System.out.println(s + " " + time);
			} time += x time x System.out.println(s + " " + time) System.out.println System.out System System.out s + " " + time s + " " + time s " " time {
				x -= q;
				enqueue2(s);
				enqueue1(x);
				time += q;
			} x -= q x q enqueue2(s) enqueue2 s enqueue1(x) enqueue1 x time += q time q String[] args args public class Main {

	static int max;
	static int Q[];
	static String P[];
	static int head;
	static int tail;

	static void initialize() {
		head = 0;
		tail = 0;
	}

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

	static boolean isFull() {
		return head == (tail+1)%max;
	}

	static void enqueue1(int x) {
		if(!isFull()) {
			Q[tail] = x;
			if(tail+1 ==max) {
				tail = 0;
			}else {
				tail++;
			}
		}
	}

	static void enqueue2(String s) {
		if(!isFull()) {
			P[tail] = s;
		}
	}

	static int dequeue1() {
		if(!isEmpty()) {
			int x = Q[head];
			if(head+1 == max) {
				head = 0;
			}else {
				head++;
			}
			return x;
		}else {
			return -1;
		}
	}

	static String  dequeue2() {
		if(!isEmpty()) {
			String s = P[head];
			return s;
		}else {
			return "";
		}
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		max = n + 1;
		P = new String[max];
		Q = new int[max];
		int q = sc.nextInt();
		initialize();
		
		for(int i=0;i<n;i++) {
			enqueue2(sc.next());
			enqueue1(sc.nextInt());
		}
		int time = 0;
		while(!isEmpty()) {
			String s = dequeue2();
			int x = dequeue1();
			if(x <= q) {
				time += x;
				System.out.println(s + " " + time);
			}else {
				x -= q;
				enqueue2(s);
				enqueue1(x);
				time += q;
			}
		}

	 }
} public class Main {

	static int max;
	static int Q[];
	static String P[];
	static int head;
	static int tail;

	static void initialize() {
		head = 0;
		tail = 0;
	}

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

	static boolean isFull() {
		return head == (tail+1)%max;
	}

	static void enqueue1(int x) {
		if(!isFull()) {
			Q[tail] = x;
			if(tail+1 ==max) {
				tail = 0;
			}else {
				tail++;
			}
		}
	}

	static void enqueue2(String s) {
		if(!isFull()) {
			P[tail] = s;
		}
	}

	static int dequeue1() {
		if(!isEmpty()) {
			int x = Q[head];
			if(head+1 == max) {
				head = 0;
			}else {
				head++;
			}
			return x;
		}else {
			return -1;
		}
	}

	static String  dequeue2() {
		if(!isEmpty()) {
			String s = P[head];
			return s;
		}else {
			return "";
		}
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		max = n + 1;
		P = new String[max];
		Q = new int[max];
		int q = sc.nextInt();
		initialize();
		
		for(int i=0;i<n;i++) {
			enqueue2(sc.next());
			enqueue1(sc.nextInt());
		}
		int time = 0;
		while(!isEmpty()) {
			String s = dequeue2();
			int x = dequeue1();
			if(x <= q) {
				time += x;
				System.out.println(s + " " + time);
			}else {
				x -= q;
				enqueue2(s);
				enqueue1(x);
				time += q;
			}
		}

	 }
} Main
import java.util.Scanner;

public class Main {

	static int max;
	static int Q[];
	static String P[];
	static int head;
	static int tail;

	static void initialize() {
		head = 0;
		tail = 0;
	}

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

	static boolean isFull() {
		return head == (tail+1)%max;
	}

	static void enqueue1(int x) {
		if(!isFull()) {
			Q[tail] = x;
			if(tail+1 ==max) {
				tail = 0;
			}else {
				tail++;
			}
		}
	}

	static void enqueue2(String s) {
		if(!isFull()) {
			P[tail] = s;
		}
	}

	static int dequeue1() {
		if(!isEmpty()) {
			int x = Q[head];
			if(head+1 == max) {
				head = 0;
			}else {
				head++;
			}
			return x;
		}else {
			return -1;
		}
	}

	static String  dequeue2() {
		if(!isEmpty()) {
			String s = P[head];
			return s;
		}else {
			return "";
		}
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		max = n + 1;
		P = new String[max];
		Q = new int[max];
		int q = sc.nextInt();
		initialize();
		
		for(int i=0;i<n;i++) {
			enqueue2(sc.next());
			enqueue1(sc.nextInt());
		}
		int time = 0;
		while(!isEmpty()) {
			String s = dequeue2();
			int x = dequeue1();
			if(x <= q) {
				time += x;
				System.out.println(s + " " + time);
			}else {
				x -= q;
				enqueue2(s);
				enqueue1(x);
				time += q;
			}
		}

	 }
}


