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

class Processees {
	private String name;
	private int time;

	public String getName() {
		return name;
	}

	public int getTime() {
		return time;
	};

	public void setTime(int time) {
		this.time = time;
	}

	public Processees(String name, int time) {
		this.name = name;
		this.time = time;
	}

}


public class Main {

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int p = scanner.nextInt();

		Deque<Processees> Processeeses = new ArrayDeque<Processees>(n);
		for (int i = 0; i < n; i++) {
			Processeeses.add(new Processees(scanner.next(), scanner.nextInt()));
		}
		int totalTime =0;
		int tempTime;
		while(Processeeses.size()!=0){
			if(Processeeses.element().getTime()<=p){
				totalTime+=Processeeses.element().getTime();
				System.out.println(Processeeses.element().getName()
						+ " "+totalTime);
				Processeeses.poll();
			}
			else{
				tempTime = Processeeses.element().getTime()-p;
				Processeeses.element().setTime(tempTime);
				Processeeses.add(Processeeses.element());
				Processeeses.poll();
				totalTime+=p;
			}
		}

	}
} import java.util.ArrayDeque; ArrayDeque java.util import java.util.Deque; Deque java.util import java.util.Scanner; Scanner java.util class Processees {
	private String name;
	private int time;

	public String getName() {
		return name;
	}

	public int getTime() {
		return time;
	};

	public void setTime(int time) {
		this.time = time;
	}

	public Processees(String name, int time) {
		this.name = name;
		this.time = time;
	}

} Processees private String name; name private int time; time public String getName() {
		return name;
	} getName {
		return name;
	} return name; name public int getTime() {
		return time;
	} getTime {
		return time;
	} return time; time public void setTime(int time) {
		this.time = time;
	} setTime {
		this.time = time;
	} this.time = time this.time this this.time time int time time public Processees(String name, int time) {
		this.name = name;
		this.time = time;
	} Processees {
		this.name = name;
		this.time = time;
	} this.name = name this.name this this.name name this.time = time this.time this this.time time String name name int time time public class Main {

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int p = scanner.nextInt();

		Deque<Processees> Processeeses = new ArrayDeque<Processees>(n);
		for (int i = 0; i < n; i++) {
			Processeeses.add(new Processees(scanner.next(), scanner.nextInt()));
		}
		int totalTime =0;
		int tempTime;
		while(Processeeses.size()!=0){
			if(Processeeses.element().getTime()<=p){
				totalTime+=Processeeses.element().getTime();
				System.out.println(Processeeses.element().getName()
						+ " "+totalTime);
				Processeeses.poll();
			}
			else{
				tempTime = Processeeses.element().getTime()-p;
				Processeeses.element().setTime(tempTime);
				Processeeses.add(Processeeses.element());
				Processeeses.poll();
				totalTime+=p;
			}
		}

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

		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int p = scanner.nextInt();

		Deque<Processees> Processeeses = new ArrayDeque<Processees>(n);
		for (int i = 0; i < n; i++) {
			Processeeses.add(new Processees(scanner.next(), scanner.nextInt()));
		}
		int totalTime =0;
		int tempTime;
		while(Processeeses.size()!=0){
			if(Processeeses.element().getTime()<=p){
				totalTime+=Processeeses.element().getTime();
				System.out.println(Processeeses.element().getName()
						+ " "+totalTime);
				Processeeses.poll();
			}
			else{
				tempTime = Processeeses.element().getTime()-p;
				Processeeses.element().setTime(tempTime);
				Processeeses.add(Processeeses.element());
				Processeeses.poll();
				totalTime+=p;
			}
		}

	} main {

		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int p = scanner.nextInt();

		Deque<Processees> Processeeses = new ArrayDeque<Processees>(n);
		for (int i = 0; i < n; i++) {
			Processeeses.add(new Processees(scanner.next(), scanner.nextInt()));
		}
		int totalTime =0;
		int tempTime;
		while(Processeeses.size()!=0){
			if(Processeeses.element().getTime()<=p){
				totalTime+=Processeeses.element().getTime();
				System.out.println(Processeeses.element().getName()
						+ " "+totalTime);
				Processeeses.poll();
			}
			else{
				tempTime = Processeeses.element().getTime()-p;
				Processeeses.element().setTime(tempTime);
				Processeeses.add(Processeeses.element());
				Processeeses.poll();
				totalTime+=p;
			}
		}

	} Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int n = scanner.nextInt(); n scanner.nextInt() scanner.nextInt scanner int p = scanner.nextInt(); p scanner.nextInt() scanner.nextInt scanner Deque<Processees> Processeeses = new ArrayDeque<Processees>(n); Processeeses new ArrayDeque<Processees>(n) for (int i = 0; i < n; i++) {
			Processeeses.add(new Processees(scanner.next(), scanner.nextInt()));
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			Processeeses.add(new Processees(scanner.next(), scanner.nextInt()));
		} {
			Processeeses.add(new Processees(scanner.next(), scanner.nextInt()));
		} Processeeses.add(new Processees(scanner.next(), scanner.nextInt())) Processeeses.add Processeeses new Processees(scanner.next(), scanner.nextInt()) int totalTime =0; totalTime 0 int tempTime; tempTime while(Processeeses.size()!=0){
			if(Processeeses.element().getTime()<=p){
				totalTime+=Processeeses.element().getTime();
				System.out.println(Processeeses.element().getName()
						+ " "+totalTime);
				Processeeses.poll();
			}
			else{
				tempTime = Processeeses.element().getTime()-p;
				Processeeses.element().setTime(tempTime);
				Processeeses.add(Processeeses.element());
				Processeeses.poll();
				totalTime+=p;
			}
		} Processeeses.size()!=0 Processeeses.size() Processeeses.size Processeeses 0 {
			if(Processeeses.element().getTime()<=p){
				totalTime+=Processeeses.element().getTime();
				System.out.println(Processeeses.element().getName()
						+ " "+totalTime);
				Processeeses.poll();
			}
			else{
				tempTime = Processeeses.element().getTime()-p;
				Processeeses.element().setTime(tempTime);
				Processeeses.add(Processeeses.element());
				Processeeses.poll();
				totalTime+=p;
			}
		} if(Processeeses.element().getTime()<=p){
				totalTime+=Processeeses.element().getTime();
				System.out.println(Processeeses.element().getName()
						+ " "+totalTime);
				Processeeses.poll();
			}
			else{
				tempTime = Processeeses.element().getTime()-p;
				Processeeses.element().setTime(tempTime);
				Processeeses.add(Processeeses.element());
				Processeeses.poll();
				totalTime+=p;
			} Processeeses.element().getTime()<=p Processeeses.element().getTime() Processeeses.element().getTime Processeeses.element() Processeeses.element Processeeses p {
				totalTime+=Processeeses.element().getTime();
				System.out.println(Processeeses.element().getName()
						+ " "+totalTime);
				Processeeses.poll();
			} totalTime+=Processeeses.element().getTime() totalTime Processeeses.element().getTime() Processeeses.element().getTime Processeeses.element() Processeeses.element Processeeses System.out.println(Processeeses.element().getName()
						+ " "+totalTime) System.out.println System.out System System.out Processeeses.element().getName()
						+ " "+totalTime Processeeses.element().getName()
						+ " "+totalTime Processeeses.element().getName() Processeeses.element().getName Processeeses.element() Processeeses.element Processeeses " " totalTime Processeeses.poll() Processeeses.poll Processeeses {
				tempTime = Processeeses.element().getTime()-p;
				Processeeses.element().setTime(tempTime);
				Processeeses.add(Processeeses.element());
				Processeeses.poll();
				totalTime+=p;
			} tempTime = Processeeses.element().getTime()-p tempTime Processeeses.element().getTime()-p Processeeses.element().getTime() Processeeses.element().getTime Processeeses.element() Processeeses.element Processeeses p Processeeses.element().setTime(tempTime) Processeeses.element().setTime Processeeses.element() Processeeses.element Processeeses tempTime Processeeses.add(Processeeses.element()) Processeeses.add Processeeses Processeeses.element() Processeeses.element Processeeses Processeeses.poll() Processeeses.poll Processeeses totalTime+=p totalTime p String[] args args public class Main {

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int p = scanner.nextInt();

		Deque<Processees> Processeeses = new ArrayDeque<Processees>(n);
		for (int i = 0; i < n; i++) {
			Processeeses.add(new Processees(scanner.next(), scanner.nextInt()));
		}
		int totalTime =0;
		int tempTime;
		while(Processeeses.size()!=0){
			if(Processeeses.element().getTime()<=p){
				totalTime+=Processeeses.element().getTime();
				System.out.println(Processeeses.element().getName()
						+ " "+totalTime);
				Processeeses.poll();
			}
			else{
				tempTime = Processeeses.element().getTime()-p;
				Processeeses.element().setTime(tempTime);
				Processeeses.add(Processeeses.element());
				Processeeses.poll();
				totalTime+=p;
			}
		}

	}
} public class Main {

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int p = scanner.nextInt();

		Deque<Processees> Processeeses = new ArrayDeque<Processees>(n);
		for (int i = 0; i < n; i++) {
			Processeeses.add(new Processees(scanner.next(), scanner.nextInt()));
		}
		int totalTime =0;
		int tempTime;
		while(Processeeses.size()!=0){
			if(Processeeses.element().getTime()<=p){
				totalTime+=Processeeses.element().getTime();
				System.out.println(Processeeses.element().getName()
						+ " "+totalTime);
				Processeeses.poll();
			}
			else{
				tempTime = Processeeses.element().getTime()-p;
				Processeeses.element().setTime(tempTime);
				Processeeses.add(Processeeses.element());
				Processeeses.poll();
				totalTime+=p;
			}
		}

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

class Processees {
	private String name;
	private int time;

	public String getName() {
		return name;
	}

	public int getTime() {
		return time;
	};

	public void setTime(int time) {
		this.time = time;
	}

	public Processees(String name, int time) {
		this.name = name;
		this.time = time;
	}

}


public class Main {

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int p = scanner.nextInt();

		Deque<Processees> Processeeses = new ArrayDeque<Processees>(n);
		for (int i = 0; i < n; i++) {
			Processeeses.add(new Processees(scanner.next(), scanner.nextInt()));
		}
		int totalTime =0;
		int tempTime;
		while(Processeeses.size()!=0){
			if(Processeeses.element().getTime()<=p){
				totalTime+=Processeeses.element().getTime();
				System.out.println(Processeeses.element().getName()
						+ " "+totalTime);
				Processeeses.poll();
			}
			else{
				tempTime = Processeeses.element().getTime()-p;
				Processeeses.element().setTime(tempTime);
				Processeeses.add(Processeeses.element());
				Processeeses.poll();
				totalTime+=p;
			}
		}

	}
}