import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		final int t = scan.nextInt();
		int totalTime = 0;

		Deque<String> queueName = new ArrayDeque<String>();
		Deque<Integer> queueTime = new ArrayDeque<Integer>();

		for(int i = 0; i < n; i++) {
			queueName.addLast(scan.next());
			queueTime.addLast(scan.nextInt());
		}

		while(!queueName.isEmpty()) {
			String procName = queueName.pollFirst();
			int procTime = queueTime.pollFirst();
			if(procTime <= t) {
				System.out.println(procName + " " + (procTime + totalTime));
				totalTime += procTime;
			} else {
				queueName.addLast(procName);
				queueTime.addLast(procTime - t);
				totalTime += t;
			}
		}
		scan.close();
	}
} import java.util.ArrayDeque; ArrayDeque java.util import java.util.Deque; Deque java.util import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		final int t = scan.nextInt();
		int totalTime = 0;

		Deque<String> queueName = new ArrayDeque<String>();
		Deque<Integer> queueTime = new ArrayDeque<Integer>();

		for(int i = 0; i < n; i++) {
			queueName.addLast(scan.next());
			queueTime.addLast(scan.nextInt());
		}

		while(!queueName.isEmpty()) {
			String procName = queueName.pollFirst();
			int procTime = queueTime.pollFirst();
			if(procTime <= t) {
				System.out.println(procName + " " + (procTime + totalTime));
				totalTime += procTime;
			} else {
				queueName.addLast(procName);
				queueTime.addLast(procTime - t);
				totalTime += t;
			}
		}
		scan.close();
	}
} Main public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		final int t = scan.nextInt();
		int totalTime = 0;

		Deque<String> queueName = new ArrayDeque<String>();
		Deque<Integer> queueTime = new ArrayDeque<Integer>();

		for(int i = 0; i < n; i++) {
			queueName.addLast(scan.next());
			queueTime.addLast(scan.nextInt());
		}

		while(!queueName.isEmpty()) {
			String procName = queueName.pollFirst();
			int procTime = queueTime.pollFirst();
			if(procTime <= t) {
				System.out.println(procName + " " + (procTime + totalTime));
				totalTime += procTime;
			} else {
				queueName.addLast(procName);
				queueTime.addLast(procTime - t);
				totalTime += t;
			}
		}
		scan.close();
	} main {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		final int t = scan.nextInt();
		int totalTime = 0;

		Deque<String> queueName = new ArrayDeque<String>();
		Deque<Integer> queueTime = new ArrayDeque<Integer>();

		for(int i = 0; i < n; i++) {
			queueName.addLast(scan.next());
			queueTime.addLast(scan.nextInt());
		}

		while(!queueName.isEmpty()) {
			String procName = queueName.pollFirst();
			int procTime = queueTime.pollFirst();
			if(procTime <= t) {
				System.out.println(procName + " " + (procTime + totalTime));
				totalTime += procTime;
			} else {
				queueName.addLast(procName);
				queueTime.addLast(procTime - t);
				totalTime += t;
			}
		}
		scan.close();
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int n = scan.nextInt(); n scan.nextInt() scan.nextInt scan final int t = scan.nextInt(); t scan.nextInt() scan.nextInt scan int totalTime = 0; totalTime 0 Deque<String> queueName = new ArrayDeque<String>(); queueName new ArrayDeque<String>() Deque<Integer> queueTime = new ArrayDeque<Integer>(); queueTime new ArrayDeque<Integer>() for(int i = 0; i < n; i++) {
			queueName.addLast(scan.next());
			queueTime.addLast(scan.nextInt());
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			queueName.addLast(scan.next());
			queueTime.addLast(scan.nextInt());
		} {
			queueName.addLast(scan.next());
			queueTime.addLast(scan.nextInt());
		} queueName.addLast(scan.next()) queueName.addLast queueName scan.next() scan.next scan queueTime.addLast(scan.nextInt()) queueTime.addLast queueTime scan.nextInt() scan.nextInt scan while(!queueName.isEmpty()) {
			String procName = queueName.pollFirst();
			int procTime = queueTime.pollFirst();
			if(procTime <= t) {
				System.out.println(procName + " " + (procTime + totalTime));
				totalTime += procTime;
			} else {
				queueName.addLast(procName);
				queueTime.addLast(procTime - t);
				totalTime += t;
			}
		} !queueName.isEmpty() queueName.isEmpty() queueName.isEmpty queueName {
			String procName = queueName.pollFirst();
			int procTime = queueTime.pollFirst();
			if(procTime <= t) {
				System.out.println(procName + " " + (procTime + totalTime));
				totalTime += procTime;
			} else {
				queueName.addLast(procName);
				queueTime.addLast(procTime - t);
				totalTime += t;
			}
		} String procName = queueName.pollFirst(); procName queueName.pollFirst() queueName.pollFirst queueName int procTime = queueTime.pollFirst(); procTime queueTime.pollFirst() queueTime.pollFirst queueTime if(procTime <= t) {
				System.out.println(procName + " " + (procTime + totalTime));
				totalTime += procTime;
			} else {
				queueName.addLast(procName);
				queueTime.addLast(procTime - t);
				totalTime += t;
			} procTime <= t procTime t {
				System.out.println(procName + " " + (procTime + totalTime));
				totalTime += procTime;
			} System.out.println(procName + " " + (procTime + totalTime)) System.out.println System.out System System.out procName + " " + (procTime + totalTime) procName + " " + (procTime + totalTime) procName " " (procTime + totalTime) procTime totalTime totalTime += procTime totalTime procTime {
				queueName.addLast(procName);
				queueTime.addLast(procTime - t);
				totalTime += t;
			} queueName.addLast(procName) queueName.addLast queueName procName queueTime.addLast(procTime - t) queueTime.addLast queueTime procTime - t procTime t totalTime += t totalTime t scan.close() scan.close scan String[] args args public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		final int t = scan.nextInt();
		int totalTime = 0;

		Deque<String> queueName = new ArrayDeque<String>();
		Deque<Integer> queueTime = new ArrayDeque<Integer>();

		for(int i = 0; i < n; i++) {
			queueName.addLast(scan.next());
			queueTime.addLast(scan.nextInt());
		}

		while(!queueName.isEmpty()) {
			String procName = queueName.pollFirst();
			int procTime = queueTime.pollFirst();
			if(procTime <= t) {
				System.out.println(procName + " " + (procTime + totalTime));
				totalTime += procTime;
			} else {
				queueName.addLast(procName);
				queueTime.addLast(procTime - t);
				totalTime += t;
			}
		}
		scan.close();
	}
} public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		final int t = scan.nextInt();
		int totalTime = 0;

		Deque<String> queueName = new ArrayDeque<String>();
		Deque<Integer> queueTime = new ArrayDeque<Integer>();

		for(int i = 0; i < n; i++) {
			queueName.addLast(scan.next());
			queueTime.addLast(scan.nextInt());
		}

		while(!queueName.isEmpty()) {
			String procName = queueName.pollFirst();
			int procTime = queueTime.pollFirst();
			if(procTime <= t) {
				System.out.println(procName + " " + (procTime + totalTime));
				totalTime += procTime;
			} else {
				queueName.addLast(procName);
				queueTime.addLast(procTime - t);
				totalTime += t;
			}
		}
		scan.close();
	}
} Main
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		final int t = scan.nextInt();
		int totalTime = 0;

		Deque<String> queueName = new ArrayDeque<String>();
		Deque<Integer> queueTime = new ArrayDeque<Integer>();

		for(int i = 0; i < n; i++) {
			queueName.addLast(scan.next());
			queueTime.addLast(scan.nextInt());
		}

		while(!queueName.isEmpty()) {
			String procName = queueName.pollFirst();
			int procTime = queueTime.pollFirst();
			if(procTime <= t) {
				System.out.println(procName + " " + (procTime + totalTime));
				totalTime += procTime;
			} else {
				queueName.addLast(procName);
				queueTime.addLast(procTime - t);
				totalTime += t;
			}
		}
		scan.close();
	}
}
