import java.util.Scanner;

public class Main {
	public static int head1 = 0;
	public static int head2 = 0;
	public static int tail = 0;
	public static String[] queue1 = new String[1000000];
	public static int[] queue2 = new int[1000000];
	
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		int n = stdIn.nextInt();
		int q = stdIn.nextInt();
		
		for (int i = 0; i < n; i++) {
			String a = stdIn.next();
			int b = stdIn.nextInt();
			enqueue(a, b);
		}
		
		int time = 0;
		while (head1 != tail) {
			String a = strDequeue();
			int b = intDequeue();
			if (b <= q) {
				time += b;
				System.out.println(a +" "+ time);
			}
			else {
				time += q;
				b -= q;
				enqueue(a, b);
			}
		}
	}
	
	public static void enqueue(String x, int y) {
		queue1[tail] = x;
		queue2[tail] = y;
		tail++;
	}
	
	public static String strDequeue() {
		return queue1[head1++];
	}
	
	public static int intDequeue() {
		return queue2[head2++];
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static int head1 = 0;
	public static int head2 = 0;
	public static int tail = 0;
	public static String[] queue1 = new String[1000000];
	public static int[] queue2 = new int[1000000];
	
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		int n = stdIn.nextInt();
		int q = stdIn.nextInt();
		
		for (int i = 0; i < n; i++) {
			String a = stdIn.next();
			int b = stdIn.nextInt();
			enqueue(a, b);
		}
		
		int time = 0;
		while (head1 != tail) {
			String a = strDequeue();
			int b = intDequeue();
			if (b <= q) {
				time += b;
				System.out.println(a +" "+ time);
			}
			else {
				time += q;
				b -= q;
				enqueue(a, b);
			}
		}
	}
	
	public static void enqueue(String x, int y) {
		queue1[tail] = x;
		queue2[tail] = y;
		tail++;
	}
	
	public static String strDequeue() {
		return queue1[head1++];
	}
	
	public static int intDequeue() {
		return queue2[head2++];
	}
} Main public static int head1 = 0; head1 0 public static int head2 = 0; head2 0 public static int tail = 0; tail 0 public static String[] queue1 = new String[1000000]; queue1 new String[1000000] 1000000 public static int[] queue2 = new int[1000000]; queue2 new int[1000000] 1000000 public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		int n = stdIn.nextInt();
		int q = stdIn.nextInt();
		
		for (int i = 0; i < n; i++) {
			String a = stdIn.next();
			int b = stdIn.nextInt();
			enqueue(a, b);
		}
		
		int time = 0;
		while (head1 != tail) {
			String a = strDequeue();
			int b = intDequeue();
			if (b <= q) {
				time += b;
				System.out.println(a +" "+ time);
			}
			else {
				time += q;
				b -= q;
				enqueue(a, b);
			}
		}
	} main {
		Scanner stdIn = new Scanner(System.in);
		
		int n = stdIn.nextInt();
		int q = stdIn.nextInt();
		
		for (int i = 0; i < n; i++) {
			String a = stdIn.next();
			int b = stdIn.nextInt();
			enqueue(a, b);
		}
		
		int time = 0;
		while (head1 != tail) {
			String a = strDequeue();
			int b = intDequeue();
			if (b <= q) {
				time += b;
				System.out.println(a +" "+ time);
			}
			else {
				time += q;
				b -= q;
				enqueue(a, b);
			}
		}
	} Scanner stdIn = new Scanner(System.in); stdIn new Scanner(System.in) int n = stdIn.nextInt(); n stdIn.nextInt() stdIn.nextInt stdIn int q = stdIn.nextInt(); q stdIn.nextInt() stdIn.nextInt stdIn for (int i = 0; i < n; i++) {
			String a = stdIn.next();
			int b = stdIn.nextInt();
			enqueue(a, b);
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			String a = stdIn.next();
			int b = stdIn.nextInt();
			enqueue(a, b);
		} {
			String a = stdIn.next();
			int b = stdIn.nextInt();
			enqueue(a, b);
		} String a = stdIn.next(); a stdIn.next() stdIn.next stdIn int b = stdIn.nextInt(); b stdIn.nextInt() stdIn.nextInt stdIn enqueue(a, b) enqueue a b int time = 0; time 0 while (head1 != tail) {
			String a = strDequeue();
			int b = intDequeue();
			if (b <= q) {
				time += b;
				System.out.println(a +" "+ time);
			}
			else {
				time += q;
				b -= q;
				enqueue(a, b);
			}
		} head1 != tail head1 tail {
			String a = strDequeue();
			int b = intDequeue();
			if (b <= q) {
				time += b;
				System.out.println(a +" "+ time);
			}
			else {
				time += q;
				b -= q;
				enqueue(a, b);
			}
		} String a = strDequeue(); a strDequeue() strDequeue int b = intDequeue(); b intDequeue() intDequeue if (b <= q) {
				time += b;
				System.out.println(a +" "+ time);
			}
			else {
				time += q;
				b -= q;
				enqueue(a, b);
			} b <= q b q {
				time += b;
				System.out.println(a +" "+ time);
			} time += b time b System.out.println(a +" "+ time) System.out.println System.out System System.out a +" "+ time a +" "+ time a " " time {
				time += q;
				b -= q;
				enqueue(a, b);
			} time += q time q b -= q b q enqueue(a, b) enqueue a b String[] args args public static void enqueue(String x, int y) {
		queue1[tail] = x;
		queue2[tail] = y;
		tail++;
	} enqueue {
		queue1[tail] = x;
		queue2[tail] = y;
		tail++;
	} queue1[tail] = x queue1[tail] queue1 tail x queue2[tail] = y queue2[tail] queue2 tail y tail++ tail String x x int y y public static String strDequeue() {
		return queue1[head1++];
	} strDequeue {
		return queue1[head1++];
	} return queue1[head1++]; queue1[head1++] queue1 head1++ head1 public static int intDequeue() {
		return queue2[head2++];
	} intDequeue {
		return queue2[head2++];
	} return queue2[head2++]; queue2[head2++] queue2 head2++ head2 public class Main {
	public static int head1 = 0;
	public static int head2 = 0;
	public static int tail = 0;
	public static String[] queue1 = new String[1000000];
	public static int[] queue2 = new int[1000000];
	
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		int n = stdIn.nextInt();
		int q = stdIn.nextInt();
		
		for (int i = 0; i < n; i++) {
			String a = stdIn.next();
			int b = stdIn.nextInt();
			enqueue(a, b);
		}
		
		int time = 0;
		while (head1 != tail) {
			String a = strDequeue();
			int b = intDequeue();
			if (b <= q) {
				time += b;
				System.out.println(a +" "+ time);
			}
			else {
				time += q;
				b -= q;
				enqueue(a, b);
			}
		}
	}
	
	public static void enqueue(String x, int y) {
		queue1[tail] = x;
		queue2[tail] = y;
		tail++;
	}
	
	public static String strDequeue() {
		return queue1[head1++];
	}
	
	public static int intDequeue() {
		return queue2[head2++];
	}
} public class Main {
	public static int head1 = 0;
	public static int head2 = 0;
	public static int tail = 0;
	public static String[] queue1 = new String[1000000];
	public static int[] queue2 = new int[1000000];
	
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		int n = stdIn.nextInt();
		int q = stdIn.nextInt();
		
		for (int i = 0; i < n; i++) {
			String a = stdIn.next();
			int b = stdIn.nextInt();
			enqueue(a, b);
		}
		
		int time = 0;
		while (head1 != tail) {
			String a = strDequeue();
			int b = intDequeue();
			if (b <= q) {
				time += b;
				System.out.println(a +" "+ time);
			}
			else {
				time += q;
				b -= q;
				enqueue(a, b);
			}
		}
	}
	
	public static void enqueue(String x, int y) {
		queue1[tail] = x;
		queue2[tail] = y;
		tail++;
	}
	
	public static String strDequeue() {
		return queue1[head1++];
	}
	
	public static int intDequeue() {
		return queue2[head2++];
	}
} Main
import java.util.Scanner;

public class Main {
	public static int head1 = 0;
	public static int head2 = 0;
	public static int tail = 0;
	public static String[] queue1 = new String[1000000];
	public static int[] queue2 = new int[1000000];
	
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		int n = stdIn.nextInt();
		int q = stdIn.nextInt();
		
		for (int i = 0; i < n; i++) {
			String a = stdIn.next();
			int b = stdIn.nextInt();
			enqueue(a, b);
		}
		
		int time = 0;
		while (head1 != tail) {
			String a = strDequeue();
			int b = intDequeue();
			if (b <= q) {
				time += b;
				System.out.println(a +" "+ time);
			}
			else {
				time += q;
				b -= q;
				enqueue(a, b);
			}
		}
	}
	
	public static void enqueue(String x, int y) {
		queue1[tail] = x;
		queue2[tail] = y;
		tail++;
	}
	
	public static String strDequeue() {
		return queue1[head1++];
	}
	
	public static int intDequeue() {
		return queue2[head2++];
	}
}