import java.util.*;

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

	public static void ALDS1_3_B() {

		class Pair{
			private String name;
			private int time;
			
			public Pair(String name, int time) {
				this.name = name;
				this.time = time;
			}

			String getName(){
				return this.name;
			}

			int getTime(){
				return this.time;
			}
		}

		Scanner sc = new Scanner(System.in);
		Queue<Pair> que = new LinkedList<Pair>();
		int n = sc.nextInt();
		int q = sc.nextInt();
		String[] name = new String[n];
		int[] time = new int[n];
		int[] timeAns = new int[n];
		int ans = 0;
		Arrays.fill(timeAns, 0);
		for(int i = 0; i < n; i++) {
			name[i] = sc.next();
			time[i] = sc.nextInt();
			Pair pair = new Pair(name[i], time[i]);
			que.add(pair);
		}

		Pair pair;
		while((pair = que.poll()) != null) {
			if(pair.getTime() - q > 0) {
				Pair tmp = new Pair(pair.getName(), pair.getTime() - q);
				que.add(tmp);
				ans += q;
			}else {
				System.out.println(pair.getName() + " " + (pair.getTime() + ans));
				ans += pair.getTime();
			}
		}
	}
	
}
 import java.util.*; util.* java public class Main {
	public static void main(String[] args) {
		ALDS1_3_B();
	}

	public static void ALDS1_3_B() {

		class Pair{
			private String name;
			private int time;
			
			public Pair(String name, int time) {
				this.name = name;
				this.time = time;
			}

			String getName(){
				return this.name;
			}

			int getTime(){
				return this.time;
			}
		}

		Scanner sc = new Scanner(System.in);
		Queue<Pair> que = new LinkedList<Pair>();
		int n = sc.nextInt();
		int q = sc.nextInt();
		String[] name = new String[n];
		int[] time = new int[n];
		int[] timeAns = new int[n];
		int ans = 0;
		Arrays.fill(timeAns, 0);
		for(int i = 0; i < n; i++) {
			name[i] = sc.next();
			time[i] = sc.nextInt();
			Pair pair = new Pair(name[i], time[i]);
			que.add(pair);
		}

		Pair pair;
		while((pair = que.poll()) != null) {
			if(pair.getTime() - q > 0) {
				Pair tmp = new Pair(pair.getName(), pair.getTime() - q);
				que.add(tmp);
				ans += q;
			}else {
				System.out.println(pair.getName() + " " + (pair.getTime() + ans));
				ans += pair.getTime();
			}
		}
	}
	
} Main public static void main(String[] args) {
		ALDS1_3_B();
	} main {
		ALDS1_3_B();
	} ALDS1_3_B() ALDS1_3_B String[] args args public static void ALDS1_3_B() {

		class Pair{
			private String name;
			private int time;
			
			public Pair(String name, int time) {
				this.name = name;
				this.time = time;
			}

			String getName(){
				return this.name;
			}

			int getTime(){
				return this.time;
			}
		}

		Scanner sc = new Scanner(System.in);
		Queue<Pair> que = new LinkedList<Pair>();
		int n = sc.nextInt();
		int q = sc.nextInt();
		String[] name = new String[n];
		int[] time = new int[n];
		int[] timeAns = new int[n];
		int ans = 0;
		Arrays.fill(timeAns, 0);
		for(int i = 0; i < n; i++) {
			name[i] = sc.next();
			time[i] = sc.nextInt();
			Pair pair = new Pair(name[i], time[i]);
			que.add(pair);
		}

		Pair pair;
		while((pair = que.poll()) != null) {
			if(pair.getTime() - q > 0) {
				Pair tmp = new Pair(pair.getName(), pair.getTime() - q);
				que.add(tmp);
				ans += q;
			}else {
				System.out.println(pair.getName() + " " + (pair.getTime() + ans));
				ans += pair.getTime();
			}
		}
	} ALDS1_3_B {

		class Pair{
			private String name;
			private int time;
			
			public Pair(String name, int time) {
				this.name = name;
				this.time = time;
			}

			String getName(){
				return this.name;
			}

			int getTime(){
				return this.time;
			}
		}

		Scanner sc = new Scanner(System.in);
		Queue<Pair> que = new LinkedList<Pair>();
		int n = sc.nextInt();
		int q = sc.nextInt();
		String[] name = new String[n];
		int[] time = new int[n];
		int[] timeAns = new int[n];
		int ans = 0;
		Arrays.fill(timeAns, 0);
		for(int i = 0; i < n; i++) {
			name[i] = sc.next();
			time[i] = sc.nextInt();
			Pair pair = new Pair(name[i], time[i]);
			que.add(pair);
		}

		Pair pair;
		while((pair = que.poll()) != null) {
			if(pair.getTime() - q > 0) {
				Pair tmp = new Pair(pair.getName(), pair.getTime() - q);
				que.add(tmp);
				ans += q;
			}else {
				System.out.println(pair.getName() + " " + (pair.getTime() + ans));
				ans += pair.getTime();
			}
		}
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) Queue<Pair> que = new LinkedList<Pair>(); que new LinkedList<Pair>() int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int q = sc.nextInt(); q sc.nextInt() sc.nextInt sc String[] name = new String[n]; name new String[n] n int[] time = new int[n]; time new int[n] n int[] timeAns = new int[n]; timeAns new int[n] n int ans = 0; ans 0 Arrays.fill(timeAns, 0) Arrays.fill Arrays timeAns 0 for(int i = 0; i < n; i++) {
			name[i] = sc.next();
			time[i] = sc.nextInt();
			Pair pair = new Pair(name[i], time[i]);
			que.add(pair);
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			name[i] = sc.next();
			time[i] = sc.nextInt();
			Pair pair = new Pair(name[i], time[i]);
			que.add(pair);
		} {
			name[i] = sc.next();
			time[i] = sc.nextInt();
			Pair pair = new Pair(name[i], time[i]);
			que.add(pair);
		} name[i] = sc.next() name[i] name i sc.next() sc.next sc time[i] = sc.nextInt() time[i] time i sc.nextInt() sc.nextInt sc Pair pair = new Pair(name[i], time[i]); pair new Pair(name[i], time[i]) que.add(pair) que.add que pair Pair pair; pair while((pair = que.poll()) != null) {
			if(pair.getTime() - q > 0) {
				Pair tmp = new Pair(pair.getName(), pair.getTime() - q);
				que.add(tmp);
				ans += q;
			}else {
				System.out.println(pair.getName() + " " + (pair.getTime() + ans));
				ans += pair.getTime();
			}
		} (pair = que.poll()) != null (pair = que.poll()) pair que.poll() que.poll que null {
			if(pair.getTime() - q > 0) {
				Pair tmp = new Pair(pair.getName(), pair.getTime() - q);
				que.add(tmp);
				ans += q;
			}else {
				System.out.println(pair.getName() + " " + (pair.getTime() + ans));
				ans += pair.getTime();
			}
		} if(pair.getTime() - q > 0) {
				Pair tmp = new Pair(pair.getName(), pair.getTime() - q);
				que.add(tmp);
				ans += q;
			}else {
				System.out.println(pair.getName() + " " + (pair.getTime() + ans));
				ans += pair.getTime();
			} pair.getTime() - q > 0 pair.getTime() - q pair.getTime() pair.getTime pair q 0 {
				Pair tmp = new Pair(pair.getName(), pair.getTime() - q);
				que.add(tmp);
				ans += q;
			} Pair tmp = new Pair(pair.getName(), pair.getTime() - q); tmp new Pair(pair.getName(), pair.getTime() - q) que.add(tmp) que.add que tmp ans += q ans q {
				System.out.println(pair.getName() + " " + (pair.getTime() + ans));
				ans += pair.getTime();
			} System.out.println(pair.getName() + " " + (pair.getTime() + ans)) System.out.println System.out System System.out pair.getName() + " " + (pair.getTime() + ans) pair.getName() + " " + (pair.getTime() + ans) pair.getName() pair.getName pair " " (pair.getTime() + ans) pair.getTime() pair.getTime pair ans ans += pair.getTime() ans pair.getTime() pair.getTime pair public class Main {
	public static void main(String[] args) {
		ALDS1_3_B();
	}

	public static void ALDS1_3_B() {

		class Pair{
			private String name;
			private int time;
			
			public Pair(String name, int time) {
				this.name = name;
				this.time = time;
			}

			String getName(){
				return this.name;
			}

			int getTime(){
				return this.time;
			}
		}

		Scanner sc = new Scanner(System.in);
		Queue<Pair> que = new LinkedList<Pair>();
		int n = sc.nextInt();
		int q = sc.nextInt();
		String[] name = new String[n];
		int[] time = new int[n];
		int[] timeAns = new int[n];
		int ans = 0;
		Arrays.fill(timeAns, 0);
		for(int i = 0; i < n; i++) {
			name[i] = sc.next();
			time[i] = sc.nextInt();
			Pair pair = new Pair(name[i], time[i]);
			que.add(pair);
		}

		Pair pair;
		while((pair = que.poll()) != null) {
			if(pair.getTime() - q > 0) {
				Pair tmp = new Pair(pair.getName(), pair.getTime() - q);
				que.add(tmp);
				ans += q;
			}else {
				System.out.println(pair.getName() + " " + (pair.getTime() + ans));
				ans += pair.getTime();
			}
		}
	}
	
} public class Main {
	public static void main(String[] args) {
		ALDS1_3_B();
	}

	public static void ALDS1_3_B() {

		class Pair{
			private String name;
			private int time;
			
			public Pair(String name, int time) {
				this.name = name;
				this.time = time;
			}

			String getName(){
				return this.name;
			}

			int getTime(){
				return this.time;
			}
		}

		Scanner sc = new Scanner(System.in);
		Queue<Pair> que = new LinkedList<Pair>();
		int n = sc.nextInt();
		int q = sc.nextInt();
		String[] name = new String[n];
		int[] time = new int[n];
		int[] timeAns = new int[n];
		int ans = 0;
		Arrays.fill(timeAns, 0);
		for(int i = 0; i < n; i++) {
			name[i] = sc.next();
			time[i] = sc.nextInt();
			Pair pair = new Pair(name[i], time[i]);
			que.add(pair);
		}

		Pair pair;
		while((pair = que.poll()) != null) {
			if(pair.getTime() - q > 0) {
				Pair tmp = new Pair(pair.getName(), pair.getTime() - q);
				que.add(tmp);
				ans += q;
			}else {
				System.out.println(pair.getName() + " " + (pair.getTime() + ans));
				ans += pair.getTime();
			}
		}
	}
	
} Main
import java.util.*;

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

	public static void ALDS1_3_B() {

		class Pair{
			private String name;
			private int time;
			
			public Pair(String name, int time) {
				this.name = name;
				this.time = time;
			}

			String getName(){
				return this.name;
			}

			int getTime(){
				return this.time;
			}
		}

		Scanner sc = new Scanner(System.in);
		Queue<Pair> que = new LinkedList<Pair>();
		int n = sc.nextInt();
		int q = sc.nextInt();
		String[] name = new String[n];
		int[] time = new int[n];
		int[] timeAns = new int[n];
		int ans = 0;
		Arrays.fill(timeAns, 0);
		for(int i = 0; i < n; i++) {
			name[i] = sc.next();
			time[i] = sc.nextInt();
			Pair pair = new Pair(name[i], time[i]);
			que.add(pair);
		}

		Pair pair;
		while((pair = que.poll()) != null) {
			if(pair.getTime() - q > 0) {
				Pair tmp = new Pair(pair.getName(), pair.getTime() - q);
				que.add(tmp);
				ans += q;
			}else {
				System.out.println(pair.getName() + " " + (pair.getTime() + ans));
				ans += pair.getTime();
			}
		}
	}
	
}

