

import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String[] in = sc.nextLine().split(" ");

		int cut = Integer.parseInt(in[1]);
		Queue<Integer> qu = new LinkedList<Integer>();
		Queue<String> quname = new LinkedList<String>();
		for (int n = 0; n <Integer.parseInt(in[0]); n++) {
			String[] in2 = sc.nextLine().split(" ");
			quname.offer(in2[0]);
			qu.offer(Integer.parseInt(in2[1]));
			
		}
		
		int time = 0;
		while (!qu.isEmpty()) {
			String name=quname.poll();
			int n = qu.poll();
			if (n-cut > 0) {
				quname.offer(name);
				qu.offer(n-cut);
				
				time += cut;
			} else {				
				time += n;
				System.out.println(name+" "+time);
			}
		}
	}

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

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String[] in = sc.nextLine().split(" ");

		int cut = Integer.parseInt(in[1]);
		Queue<Integer> qu = new LinkedList<Integer>();
		Queue<String> quname = new LinkedList<String>();
		for (int n = 0; n <Integer.parseInt(in[0]); n++) {
			String[] in2 = sc.nextLine().split(" ");
			quname.offer(in2[0]);
			qu.offer(Integer.parseInt(in2[1]));
			
		}
		
		int time = 0;
		while (!qu.isEmpty()) {
			String name=quname.poll();
			int n = qu.poll();
			if (n-cut > 0) {
				quname.offer(name);
				qu.offer(n-cut);
				
				time += cut;
			} else {				
				time += n;
				System.out.println(name+" "+time);
			}
		}
	}

} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String[] in = sc.nextLine().split(" ");

		int cut = Integer.parseInt(in[1]);
		Queue<Integer> qu = new LinkedList<Integer>();
		Queue<String> quname = new LinkedList<String>();
		for (int n = 0; n <Integer.parseInt(in[0]); n++) {
			String[] in2 = sc.nextLine().split(" ");
			quname.offer(in2[0]);
			qu.offer(Integer.parseInt(in2[1]));
			
		}
		
		int time = 0;
		while (!qu.isEmpty()) {
			String name=quname.poll();
			int n = qu.poll();
			if (n-cut > 0) {
				quname.offer(name);
				qu.offer(n-cut);
				
				time += cut;
			} else {				
				time += n;
				System.out.println(name+" "+time);
			}
		}
	} main {
		Scanner sc = new Scanner(System.in);
		String[] in = sc.nextLine().split(" ");

		int cut = Integer.parseInt(in[1]);
		Queue<Integer> qu = new LinkedList<Integer>();
		Queue<String> quname = new LinkedList<String>();
		for (int n = 0; n <Integer.parseInt(in[0]); n++) {
			String[] in2 = sc.nextLine().split(" ");
			quname.offer(in2[0]);
			qu.offer(Integer.parseInt(in2[1]));
			
		}
		
		int time = 0;
		while (!qu.isEmpty()) {
			String name=quname.poll();
			int n = qu.poll();
			if (n-cut > 0) {
				quname.offer(name);
				qu.offer(n-cut);
				
				time += cut;
			} else {				
				time += n;
				System.out.println(name+" "+time);
			}
		}
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String[] in = sc.nextLine().split(" "); in sc.nextLine().split(" ") sc.nextLine().split sc.nextLine() sc.nextLine sc " " int cut = Integer.parseInt(in[1]); cut Integer.parseInt(in[1]) Integer.parseInt Integer in[1] in 1 Queue<Integer> qu = new LinkedList<Integer>(); qu new LinkedList<Integer>() Queue<String> quname = new LinkedList<String>(); quname new LinkedList<String>() for (int n = 0; n <Integer.parseInt(in[0]); n++) {
			String[] in2 = sc.nextLine().split(" ");
			quname.offer(in2[0]);
			qu.offer(Integer.parseInt(in2[1]));
			
		} int n = 0; int n = 0; n 0 n <Integer.parseInt(in[0]) n Integer.parseInt(in[0]) Integer.parseInt Integer in[0] in 0 n++ n++ n {
			String[] in2 = sc.nextLine().split(" ");
			quname.offer(in2[0]);
			qu.offer(Integer.parseInt(in2[1]));
			
		} {
			String[] in2 = sc.nextLine().split(" ");
			quname.offer(in2[0]);
			qu.offer(Integer.parseInt(in2[1]));
			
		} String[] in2 = sc.nextLine().split(" "); in2 sc.nextLine().split(" ") sc.nextLine().split sc.nextLine() sc.nextLine sc " " quname.offer(in2[0]) quname.offer quname in2[0] in2 0 qu.offer(Integer.parseInt(in2[1])) qu.offer qu Integer.parseInt(in2[1]) Integer.parseInt Integer in2[1] in2 1 int time = 0; time 0 while (!qu.isEmpty()) {
			String name=quname.poll();
			int n = qu.poll();
			if (n-cut > 0) {
				quname.offer(name);
				qu.offer(n-cut);
				
				time += cut;
			} else {				
				time += n;
				System.out.println(name+" "+time);
			}
		} !qu.isEmpty() qu.isEmpty() qu.isEmpty qu {
			String name=quname.poll();
			int n = qu.poll();
			if (n-cut > 0) {
				quname.offer(name);
				qu.offer(n-cut);
				
				time += cut;
			} else {				
				time += n;
				System.out.println(name+" "+time);
			}
		} String name=quname.poll(); name quname.poll() quname.poll quname int n = qu.poll(); n qu.poll() qu.poll qu if (n-cut > 0) {
				quname.offer(name);
				qu.offer(n-cut);
				
				time += cut;
			} else {				
				time += n;
				System.out.println(name+" "+time);
			} n-cut > 0 n-cut n cut 0 {
				quname.offer(name);
				qu.offer(n-cut);
				
				time += cut;
			} quname.offer(name) quname.offer quname name qu.offer(n-cut) qu.offer qu n-cut n cut time += cut time cut {				
				time += n;
				System.out.println(name+" "+time);
			} time += n time n System.out.println(name+" "+time) System.out.println System.out System System.out name+" "+time name+" "+time name " " time String[] args args public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String[] in = sc.nextLine().split(" ");

		int cut = Integer.parseInt(in[1]);
		Queue<Integer> qu = new LinkedList<Integer>();
		Queue<String> quname = new LinkedList<String>();
		for (int n = 0; n <Integer.parseInt(in[0]); n++) {
			String[] in2 = sc.nextLine().split(" ");
			quname.offer(in2[0]);
			qu.offer(Integer.parseInt(in2[1]));
			
		}
		
		int time = 0;
		while (!qu.isEmpty()) {
			String name=quname.poll();
			int n = qu.poll();
			if (n-cut > 0) {
				quname.offer(name);
				qu.offer(n-cut);
				
				time += cut;
			} else {				
				time += n;
				System.out.println(name+" "+time);
			}
		}
	}

} public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String[] in = sc.nextLine().split(" ");

		int cut = Integer.parseInt(in[1]);
		Queue<Integer> qu = new LinkedList<Integer>();
		Queue<String> quname = new LinkedList<String>();
		for (int n = 0; n <Integer.parseInt(in[0]); n++) {
			String[] in2 = sc.nextLine().split(" ");
			quname.offer(in2[0]);
			qu.offer(Integer.parseInt(in2[1]));
			
		}
		
		int time = 0;
		while (!qu.isEmpty()) {
			String name=quname.poll();
			int n = qu.poll();
			if (n-cut > 0) {
				quname.offer(name);
				qu.offer(n-cut);
				
				time += cut;
			} else {				
				time += n;
				System.out.println(name+" "+time);
			}
		}
	}

} Main


import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String[] in = sc.nextLine().split(" ");

		int cut = Integer.parseInt(in[1]);
		Queue<Integer> qu = new LinkedList<Integer>();
		Queue<String> quname = new LinkedList<String>();
		for (int n = 0; n <Integer.parseInt(in[0]); n++) {
			String[] in2 = sc.nextLine().split(" ");
			quname.offer(in2[0]);
			qu.offer(Integer.parseInt(in2[1]));
			
		}
		
		int time = 0;
		while (!qu.isEmpty()) {
			String name=quname.poll();
			int n = qu.poll();
			if (n-cut > 0) {
				quname.offer(name);
				qu.offer(n-cut);
				
				time += cut;
			} else {				
				time += n;
				System.out.println(name+" "+time);
			}
		}
	}

}

