import java.util.AbstractMap;
import java.util.ArrayDeque;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int q = sc.nextInt();
		sc.nextLine();

		String[] p = new String[n];
		int[] t = new int[n];
//		LinkedHashMap<String, Integer> hmi = new LinkedHashMap<>();
//		LinkedHashMap[] hm = new LinkedHashMap[n];
		ArrayDeque<AbstractMap.SimpleEntry<String, Integer>> ad =
				new ArrayDeque<>();
		for (int i = 0; i < n; i++) {
			p[i] = sc.next();
			t[i] = sc.nextInt();
//			hmi.put(p[i], t[i]);
//			( (LinkedHashMap<String, Integer>) hm[i] ).put(p[i], t[i]);
			AbstractMap.SimpleEntry<String, Integer> pair =
					new AbstractMap.SimpleEntry<>(p[i], t[i]);
			ad.add(pair);
		}

//		System.out.println(Arrays.toString(p));
//		System.out.println(Arrays.toString(t));
//		System.out.println(ad.poll());

		int time = 0;
		while (!ad.isEmpty()) {
			AbstractMap.SimpleEntry<String, Integer> pair = ad.poll();
			// pt: pair time
			int pt = pair.getValue() - q;
			// pp : pair name
			String pn = pair.getKey();

			if (pt > 0) {
				pair.setValue(pt);
				ad.add(pair);
				time += q;
			} else {
				time += pair.getValue();
				System.out.println(pn + " " + time);
			}
		}
	}
} import java.util.AbstractMap; AbstractMap java.util import java.util.ArrayDeque; ArrayDeque java.util import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int q = sc.nextInt();
		sc.nextLine();

		String[] p = new String[n];
		int[] t = new int[n];
//		LinkedHashMap<String, Integer> hmi = new LinkedHashMap<>();
//		LinkedHashMap[] hm = new LinkedHashMap[n];
		ArrayDeque<AbstractMap.SimpleEntry<String, Integer>> ad =
				new ArrayDeque<>();
		for (int i = 0; i < n; i++) {
			p[i] = sc.next();
			t[i] = sc.nextInt();
//			hmi.put(p[i], t[i]);
//			( (LinkedHashMap<String, Integer>) hm[i] ).put(p[i], t[i]);
			AbstractMap.SimpleEntry<String, Integer> pair =
					new AbstractMap.SimpleEntry<>(p[i], t[i]);
			ad.add(pair);
		}

//		System.out.println(Arrays.toString(p));
//		System.out.println(Arrays.toString(t));
//		System.out.println(ad.poll());

		int time = 0;
		while (!ad.isEmpty()) {
			AbstractMap.SimpleEntry<String, Integer> pair = ad.poll();
			// pt: pair time
			int pt = pair.getValue() - q;
			// pp : pair name
			String pn = pair.getKey();

			if (pt > 0) {
				pair.setValue(pt);
				ad.add(pair);
				time += q;
			} else {
				time += pair.getValue();
				System.out.println(pn + " " + time);
			}
		}
	}
} Main public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int q = sc.nextInt();
		sc.nextLine();

		String[] p = new String[n];
		int[] t = new int[n];
//		LinkedHashMap<String, Integer> hmi = new LinkedHashMap<>();
//		LinkedHashMap[] hm = new LinkedHashMap[n];
		ArrayDeque<AbstractMap.SimpleEntry<String, Integer>> ad =
				new ArrayDeque<>();
		for (int i = 0; i < n; i++) {
			p[i] = sc.next();
			t[i] = sc.nextInt();
//			hmi.put(p[i], t[i]);
//			( (LinkedHashMap<String, Integer>) hm[i] ).put(p[i], t[i]);
			AbstractMap.SimpleEntry<String, Integer> pair =
					new AbstractMap.SimpleEntry<>(p[i], t[i]);
			ad.add(pair);
		}

//		System.out.println(Arrays.toString(p));
//		System.out.println(Arrays.toString(t));
//		System.out.println(ad.poll());

		int time = 0;
		while (!ad.isEmpty()) {
			AbstractMap.SimpleEntry<String, Integer> pair = ad.poll();
			// pt: pair time
			int pt = pair.getValue() - q;
			// pp : pair name
			String pn = pair.getKey();

			if (pt > 0) {
				pair.setValue(pt);
				ad.add(pair);
				time += q;
			} else {
				time += pair.getValue();
				System.out.println(pn + " " + time);
			}
		}
	} main {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int q = sc.nextInt();
		sc.nextLine();

		String[] p = new String[n];
		int[] t = new int[n];
//		LinkedHashMap<String, Integer> hmi = new LinkedHashMap<>();
//		LinkedHashMap[] hm = new LinkedHashMap[n];
		ArrayDeque<AbstractMap.SimpleEntry<String, Integer>> ad =
				new ArrayDeque<>();
		for (int i = 0; i < n; i++) {
			p[i] = sc.next();
			t[i] = sc.nextInt();
//			hmi.put(p[i], t[i]);
//			( (LinkedHashMap<String, Integer>) hm[i] ).put(p[i], t[i]);
			AbstractMap.SimpleEntry<String, Integer> pair =
					new AbstractMap.SimpleEntry<>(p[i], t[i]);
			ad.add(pair);
		}

//		System.out.println(Arrays.toString(p));
//		System.out.println(Arrays.toString(t));
//		System.out.println(ad.poll());

		int time = 0;
		while (!ad.isEmpty()) {
			AbstractMap.SimpleEntry<String, Integer> pair = ad.poll();
			// pt: pair time
			int pt = pair.getValue() - q;
			// pp : pair name
			String pn = pair.getKey();

			if (pt > 0) {
				pair.setValue(pt);
				ad.add(pair);
				time += q;
			} else {
				time += pair.getValue();
				System.out.println(pn + " " + time);
			}
		}
	} 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 sc.nextLine() sc.nextLine sc String[] p = new String[n]; p new String[n] n int[] t = new int[n]; t new int[n] n ArrayDeque<AbstractMap.SimpleEntry<String, Integer>> ad =
				new ArrayDeque<>(); ad new ArrayDeque<>() for (int i = 0; i < n; i++) {
			p[i] = sc.next();
			t[i] = sc.nextInt();
//			hmi.put(p[i], t[i]);
//			( (LinkedHashMap<String, Integer>) hm[i] ).put(p[i], t[i]);
			AbstractMap.SimpleEntry<String, Integer> pair =
					new AbstractMap.SimpleEntry<>(p[i], t[i]);
			ad.add(pair);
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			p[i] = sc.next();
			t[i] = sc.nextInt();
//			hmi.put(p[i], t[i]);
//			( (LinkedHashMap<String, Integer>) hm[i] ).put(p[i], t[i]);
			AbstractMap.SimpleEntry<String, Integer> pair =
					new AbstractMap.SimpleEntry<>(p[i], t[i]);
			ad.add(pair);
		} {
			p[i] = sc.next();
			t[i] = sc.nextInt();
//			hmi.put(p[i], t[i]);
//			( (LinkedHashMap<String, Integer>) hm[i] ).put(p[i], t[i]);
			AbstractMap.SimpleEntry<String, Integer> pair =
					new AbstractMap.SimpleEntry<>(p[i], t[i]);
			ad.add(pair);
		} p[i] = sc.next() p[i] p i sc.next() sc.next sc t[i] = sc.nextInt() t[i] t i sc.nextInt() sc.nextInt sc AbstractMap.SimpleEntry<String, Integer> pair =
					new AbstractMap.SimpleEntry<>(p[i], t[i]); pair new AbstractMap.SimpleEntry<>(p[i], t[i]) ad.add(pair) ad.add ad pair int time = 0; time 0 while (!ad.isEmpty()) {
			AbstractMap.SimpleEntry<String, Integer> pair = ad.poll();
			// pt: pair time
			int pt = pair.getValue() - q;
			// pp : pair name
			String pn = pair.getKey();

			if (pt > 0) {
				pair.setValue(pt);
				ad.add(pair);
				time += q;
			} else {
				time += pair.getValue();
				System.out.println(pn + " " + time);
			}
		} !ad.isEmpty() ad.isEmpty() ad.isEmpty ad {
			AbstractMap.SimpleEntry<String, Integer> pair = ad.poll();
			// pt: pair time
			int pt = pair.getValue() - q;
			// pp : pair name
			String pn = pair.getKey();

			if (pt > 0) {
				pair.setValue(pt);
				ad.add(pair);
				time += q;
			} else {
				time += pair.getValue();
				System.out.println(pn + " " + time);
			}
		} AbstractMap.SimpleEntry<String, Integer> pair = ad.poll(); pair ad.poll() ad.poll ad int pt = pair.getValue() - q; pt pair.getValue() - q pair.getValue() pair.getValue pair q String pn = pair.getKey(); pn pair.getKey() pair.getKey pair if (pt > 0) {
				pair.setValue(pt);
				ad.add(pair);
				time += q;
			} else {
				time += pair.getValue();
				System.out.println(pn + " " + time);
			} pt > 0 pt 0 {
				pair.setValue(pt);
				ad.add(pair);
				time += q;
			} pair.setValue(pt) pair.setValue pair pt ad.add(pair) ad.add ad pair time += q time q {
				time += pair.getValue();
				System.out.println(pn + " " + time);
			} time += pair.getValue() time pair.getValue() pair.getValue pair System.out.println(pn + " " + time) System.out.println System.out System System.out pn + " " + time pn + " " + time pn " " time String[] args args public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int q = sc.nextInt();
		sc.nextLine();

		String[] p = new String[n];
		int[] t = new int[n];
//		LinkedHashMap<String, Integer> hmi = new LinkedHashMap<>();
//		LinkedHashMap[] hm = new LinkedHashMap[n];
		ArrayDeque<AbstractMap.SimpleEntry<String, Integer>> ad =
				new ArrayDeque<>();
		for (int i = 0; i < n; i++) {
			p[i] = sc.next();
			t[i] = sc.nextInt();
//			hmi.put(p[i], t[i]);
//			( (LinkedHashMap<String, Integer>) hm[i] ).put(p[i], t[i]);
			AbstractMap.SimpleEntry<String, Integer> pair =
					new AbstractMap.SimpleEntry<>(p[i], t[i]);
			ad.add(pair);
		}

//		System.out.println(Arrays.toString(p));
//		System.out.println(Arrays.toString(t));
//		System.out.println(ad.poll());

		int time = 0;
		while (!ad.isEmpty()) {
			AbstractMap.SimpleEntry<String, Integer> pair = ad.poll();
			// pt: pair time
			int pt = pair.getValue() - q;
			// pp : pair name
			String pn = pair.getKey();

			if (pt > 0) {
				pair.setValue(pt);
				ad.add(pair);
				time += q;
			} else {
				time += pair.getValue();
				System.out.println(pn + " " + time);
			}
		}
	}
} public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int q = sc.nextInt();
		sc.nextLine();

		String[] p = new String[n];
		int[] t = new int[n];
//		LinkedHashMap<String, Integer> hmi = new LinkedHashMap<>();
//		LinkedHashMap[] hm = new LinkedHashMap[n];
		ArrayDeque<AbstractMap.SimpleEntry<String, Integer>> ad =
				new ArrayDeque<>();
		for (int i = 0; i < n; i++) {
			p[i] = sc.next();
			t[i] = sc.nextInt();
//			hmi.put(p[i], t[i]);
//			( (LinkedHashMap<String, Integer>) hm[i] ).put(p[i], t[i]);
			AbstractMap.SimpleEntry<String, Integer> pair =
					new AbstractMap.SimpleEntry<>(p[i], t[i]);
			ad.add(pair);
		}

//		System.out.println(Arrays.toString(p));
//		System.out.println(Arrays.toString(t));
//		System.out.println(ad.poll());

		int time = 0;
		while (!ad.isEmpty()) {
			AbstractMap.SimpleEntry<String, Integer> pair = ad.poll();
			// pt: pair time
			int pt = pair.getValue() - q;
			// pp : pair name
			String pn = pair.getKey();

			if (pt > 0) {
				pair.setValue(pt);
				ad.add(pair);
				time += q;
			} else {
				time += pair.getValue();
				System.out.println(pn + " " + time);
			}
		}
	}
} Main
import java.util.AbstractMap;
import java.util.ArrayDeque;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int q = sc.nextInt();
		sc.nextLine();

		String[] p = new String[n];
		int[] t = new int[n];
//		LinkedHashMap<String, Integer> hmi = new LinkedHashMap<>();
//		LinkedHashMap[] hm = new LinkedHashMap[n];
		ArrayDeque<AbstractMap.SimpleEntry<String, Integer>> ad =
				new ArrayDeque<>();
		for (int i = 0; i < n; i++) {
			p[i] = sc.next();
			t[i] = sc.nextInt();
//			hmi.put(p[i], t[i]);
//			( (LinkedHashMap<String, Integer>) hm[i] ).put(p[i], t[i]);
			AbstractMap.SimpleEntry<String, Integer> pair =
					new AbstractMap.SimpleEntry<>(p[i], t[i]);
			ad.add(pair);
		}

//		System.out.println(Arrays.toString(p));
//		System.out.println(Arrays.toString(t));
//		System.out.println(ad.poll());

		int time = 0;
		while (!ad.isEmpty()) {
			AbstractMap.SimpleEntry<String, Integer> pair = ad.poll();
			// pt: pair time
			int pt = pair.getValue() - q;
			// pp : pair name
			String pn = pair.getKey();

			if (pt > 0) {
				pair.setValue(pt);
				ad.add(pair);
				time += q;
			} else {
				time += pair.getValue();
				System.out.println(pn + " " + time);
			}
		}
	}
}