import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {

		Scanner sc = new Scanner(System.in);
		int count = sc.nextInt();
		int q = sc.nextInt();

		int totalTime = 0;
		String[] queue = new String[200000];
		int[] restTime = new int[200000];

		for(int i = 0; i < count; i++) {
			String name = sc.next();
			int time = sc.nextInt();

			queue[i] = name;
			restTime[i] = time;
		}

		int qhead = 0;
		int qtail = count;

		while(qhead != qtail) {
			if(restTime[qhead] <= q) {
				totalTime += restTime[qhead];
				System.out.println(queue[qhead] + " " + totalTime);
				qhead++;
			} else {
				queue[qtail] = queue[qhead];
				restTime[qtail] = restTime[qhead] - q;
				totalTime += q;
				qhead++;
				qtail++;
			}
		}

	}

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

	public static void main(String[] args) throws Exception {

		Scanner sc = new Scanner(System.in);
		int count = sc.nextInt();
		int q = sc.nextInt();

		int totalTime = 0;
		String[] queue = new String[200000];
		int[] restTime = new int[200000];

		for(int i = 0; i < count; i++) {
			String name = sc.next();
			int time = sc.nextInt();

			queue[i] = name;
			restTime[i] = time;
		}

		int qhead = 0;
		int qtail = count;

		while(qhead != qtail) {
			if(restTime[qhead] <= q) {
				totalTime += restTime[qhead];
				System.out.println(queue[qhead] + " " + totalTime);
				qhead++;
			} else {
				queue[qtail] = queue[qhead];
				restTime[qtail] = restTime[qhead] - q;
				totalTime += q;
				qhead++;
				qtail++;
			}
		}

	}

} Main public static void main(String[] args) throws Exception {

		Scanner sc = new Scanner(System.in);
		int count = sc.nextInt();
		int q = sc.nextInt();

		int totalTime = 0;
		String[] queue = new String[200000];
		int[] restTime = new int[200000];

		for(int i = 0; i < count; i++) {
			String name = sc.next();
			int time = sc.nextInt();

			queue[i] = name;
			restTime[i] = time;
		}

		int qhead = 0;
		int qtail = count;

		while(qhead != qtail) {
			if(restTime[qhead] <= q) {
				totalTime += restTime[qhead];
				System.out.println(queue[qhead] + " " + totalTime);
				qhead++;
			} else {
				queue[qtail] = queue[qhead];
				restTime[qtail] = restTime[qhead] - q;
				totalTime += q;
				qhead++;
				qtail++;
			}
		}

	} main {

		Scanner sc = new Scanner(System.in);
		int count = sc.nextInt();
		int q = sc.nextInt();

		int totalTime = 0;
		String[] queue = new String[200000];
		int[] restTime = new int[200000];

		for(int i = 0; i < count; i++) {
			String name = sc.next();
			int time = sc.nextInt();

			queue[i] = name;
			restTime[i] = time;
		}

		int qhead = 0;
		int qtail = count;

		while(qhead != qtail) {
			if(restTime[qhead] <= q) {
				totalTime += restTime[qhead];
				System.out.println(queue[qhead] + " " + totalTime);
				qhead++;
			} else {
				queue[qtail] = queue[qhead];
				restTime[qtail] = restTime[qhead] - q;
				totalTime += q;
				qhead++;
				qtail++;
			}
		}

	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int count = sc.nextInt(); count sc.nextInt() sc.nextInt sc int q = sc.nextInt(); q sc.nextInt() sc.nextInt sc int totalTime = 0; totalTime 0 String[] queue = new String[200000]; queue new String[200000] 200000 int[] restTime = new int[200000]; restTime new int[200000] 200000 for(int i = 0; i < count; i++) {
			String name = sc.next();
			int time = sc.nextInt();

			queue[i] = name;
			restTime[i] = time;
		} int i = 0; int i = 0; i 0 i < count i count i++ i++ i {
			String name = sc.next();
			int time = sc.nextInt();

			queue[i] = name;
			restTime[i] = time;
		} {
			String name = sc.next();
			int time = sc.nextInt();

			queue[i] = name;
			restTime[i] = time;
		} String name = sc.next(); name sc.next() sc.next sc int time = sc.nextInt(); time sc.nextInt() sc.nextInt sc queue[i] = name queue[i] queue i name restTime[i] = time restTime[i] restTime i time int qhead = 0; qhead 0 int qtail = count; qtail count while(qhead != qtail) {
			if(restTime[qhead] <= q) {
				totalTime += restTime[qhead];
				System.out.println(queue[qhead] + " " + totalTime);
				qhead++;
			} else {
				queue[qtail] = queue[qhead];
				restTime[qtail] = restTime[qhead] - q;
				totalTime += q;
				qhead++;
				qtail++;
			}
		} qhead != qtail qhead qtail {
			if(restTime[qhead] <= q) {
				totalTime += restTime[qhead];
				System.out.println(queue[qhead] + " " + totalTime);
				qhead++;
			} else {
				queue[qtail] = queue[qhead];
				restTime[qtail] = restTime[qhead] - q;
				totalTime += q;
				qhead++;
				qtail++;
			}
		} if(restTime[qhead] <= q) {
				totalTime += restTime[qhead];
				System.out.println(queue[qhead] + " " + totalTime);
				qhead++;
			} else {
				queue[qtail] = queue[qhead];
				restTime[qtail] = restTime[qhead] - q;
				totalTime += q;
				qhead++;
				qtail++;
			} restTime[qhead] <= q restTime[qhead] restTime qhead q {
				totalTime += restTime[qhead];
				System.out.println(queue[qhead] + " " + totalTime);
				qhead++;
			} totalTime += restTime[qhead] totalTime restTime[qhead] restTime qhead System.out.println(queue[qhead] + " " + totalTime) System.out.println System.out System System.out queue[qhead] + " " + totalTime queue[qhead] + " " + totalTime queue[qhead] queue qhead " " totalTime qhead++ qhead {
				queue[qtail] = queue[qhead];
				restTime[qtail] = restTime[qhead] - q;
				totalTime += q;
				qhead++;
				qtail++;
			} queue[qtail] = queue[qhead] queue[qtail] queue qtail queue[qhead] queue qhead restTime[qtail] = restTime[qhead] - q restTime[qtail] restTime qtail restTime[qhead] - q restTime[qhead] restTime qhead q totalTime += q totalTime q qhead++ qhead qtail++ qtail String[] args args public class Main {

	public static void main(String[] args) throws Exception {

		Scanner sc = new Scanner(System.in);
		int count = sc.nextInt();
		int q = sc.nextInt();

		int totalTime = 0;
		String[] queue = new String[200000];
		int[] restTime = new int[200000];

		for(int i = 0; i < count; i++) {
			String name = sc.next();
			int time = sc.nextInt();

			queue[i] = name;
			restTime[i] = time;
		}

		int qhead = 0;
		int qtail = count;

		while(qhead != qtail) {
			if(restTime[qhead] <= q) {
				totalTime += restTime[qhead];
				System.out.println(queue[qhead] + " " + totalTime);
				qhead++;
			} else {
				queue[qtail] = queue[qhead];
				restTime[qtail] = restTime[qhead] - q;
				totalTime += q;
				qhead++;
				qtail++;
			}
		}

	}

} public class Main {

	public static void main(String[] args) throws Exception {

		Scanner sc = new Scanner(System.in);
		int count = sc.nextInt();
		int q = sc.nextInt();

		int totalTime = 0;
		String[] queue = new String[200000];
		int[] restTime = new int[200000];

		for(int i = 0; i < count; i++) {
			String name = sc.next();
			int time = sc.nextInt();

			queue[i] = name;
			restTime[i] = time;
		}

		int qhead = 0;
		int qtail = count;

		while(qhead != qtail) {
			if(restTime[qhead] <= q) {
				totalTime += restTime[qhead];
				System.out.println(queue[qhead] + " " + totalTime);
				qhead++;
			} else {
				queue[qtail] = queue[qhead];
				restTime[qtail] = restTime[qhead] - q;
				totalTime += q;
				qhead++;
				qtail++;
			}
		}

	}

} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {

		Scanner sc = new Scanner(System.in);
		int count = sc.nextInt();
		int q = sc.nextInt();

		int totalTime = 0;
		String[] queue = new String[200000];
		int[] restTime = new int[200000];

		for(int i = 0; i < count; i++) {
			String name = sc.next();
			int time = sc.nextInt();

			queue[i] = name;
			restTime[i] = time;
		}

		int qhead = 0;
		int qtail = count;

		while(qhead != qtail) {
			if(restTime[qhead] <= q) {
				totalTime += restTime[qhead];
				System.out.println(queue[qhead] + " " + totalTime);
				qhead++;
			} else {
				queue[qtail] = queue[qhead];
				restTime[qtail] = restTime[qhead] - q;
				totalTime += q;
				qhead++;
				qtail++;
			}
		}

	}

}
