import java.util.Scanner;
import java.util.Arrays;
import java.util.Deque;
import java.util.ArrayDeque;
import java.io.BufferedReader;
import java.io.InputStreamReader;


class Main{
	public static void main(String[] args)throws Exception{
		Scanner scanner = new Scanner(System.in);
		Deque<String> name_stack = new ArrayDeque<>();
		Deque<Integer> time_stack = new ArrayDeque<>();
		int n = scanner.nextInt();
		int q = scanner.nextInt();
		String nothing = scanner.nextLine();
		int all_time = 0;

		for(int i = 0; i < n-1; i++){
			name_stack.offer(scanner.next());
			time_stack.offer(scanner.nextInt());
			nothing = scanner.nextLine();
		}
		
		name_stack.offer(scanner.next());
		time_stack.offer(scanner.nextInt());

		while(!(name_stack.isEmpty())){
			String name = name_stack.poll();
			int time = time_stack.poll();

			if(time <= q){
				all_time += time;
				System.out.println(name + " " + all_time);
			}else{
				all_time += q;
				time -= q;
				name_stack.offer(name);
				time_stack.offer(time);
			}
		}

	}
} import java.util.Scanner; Scanner java.util import java.util.Arrays; Arrays java.util import java.util.Deque; Deque java.util import java.util.ArrayDeque; ArrayDeque java.util import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io class Main{
	public static void main(String[] args)throws Exception{
		Scanner scanner = new Scanner(System.in);
		Deque<String> name_stack = new ArrayDeque<>();
		Deque<Integer> time_stack = new ArrayDeque<>();
		int n = scanner.nextInt();
		int q = scanner.nextInt();
		String nothing = scanner.nextLine();
		int all_time = 0;

		for(int i = 0; i < n-1; i++){
			name_stack.offer(scanner.next());
			time_stack.offer(scanner.nextInt());
			nothing = scanner.nextLine();
		}
		
		name_stack.offer(scanner.next());
		time_stack.offer(scanner.nextInt());

		while(!(name_stack.isEmpty())){
			String name = name_stack.poll();
			int time = time_stack.poll();

			if(time <= q){
				all_time += time;
				System.out.println(name + " " + all_time);
			}else{
				all_time += q;
				time -= q;
				name_stack.offer(name);
				time_stack.offer(time);
			}
		}

	}
} Main public static void main(String[] args)throws Exception{
		Scanner scanner = new Scanner(System.in);
		Deque<String> name_stack = new ArrayDeque<>();
		Deque<Integer> time_stack = new ArrayDeque<>();
		int n = scanner.nextInt();
		int q = scanner.nextInt();
		String nothing = scanner.nextLine();
		int all_time = 0;

		for(int i = 0; i < n-1; i++){
			name_stack.offer(scanner.next());
			time_stack.offer(scanner.nextInt());
			nothing = scanner.nextLine();
		}
		
		name_stack.offer(scanner.next());
		time_stack.offer(scanner.nextInt());

		while(!(name_stack.isEmpty())){
			String name = name_stack.poll();
			int time = time_stack.poll();

			if(time <= q){
				all_time += time;
				System.out.println(name + " " + all_time);
			}else{
				all_time += q;
				time -= q;
				name_stack.offer(name);
				time_stack.offer(time);
			}
		}

	} main {
		Scanner scanner = new Scanner(System.in);
		Deque<String> name_stack = new ArrayDeque<>();
		Deque<Integer> time_stack = new ArrayDeque<>();
		int n = scanner.nextInt();
		int q = scanner.nextInt();
		String nothing = scanner.nextLine();
		int all_time = 0;

		for(int i = 0; i < n-1; i++){
			name_stack.offer(scanner.next());
			time_stack.offer(scanner.nextInt());
			nothing = scanner.nextLine();
		}
		
		name_stack.offer(scanner.next());
		time_stack.offer(scanner.nextInt());

		while(!(name_stack.isEmpty())){
			String name = name_stack.poll();
			int time = time_stack.poll();

			if(time <= q){
				all_time += time;
				System.out.println(name + " " + all_time);
			}else{
				all_time += q;
				time -= q;
				name_stack.offer(name);
				time_stack.offer(time);
			}
		}

	} Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) Deque<String> name_stack = new ArrayDeque<>(); name_stack new ArrayDeque<>() Deque<Integer> time_stack = new ArrayDeque<>(); time_stack new ArrayDeque<>() int n = scanner.nextInt(); n scanner.nextInt() scanner.nextInt scanner int q = scanner.nextInt(); q scanner.nextInt() scanner.nextInt scanner String nothing = scanner.nextLine(); nothing scanner.nextLine() scanner.nextLine scanner int all_time = 0; all_time 0 for(int i = 0; i < n-1; i++){
			name_stack.offer(scanner.next());
			time_stack.offer(scanner.nextInt());
			nothing = scanner.nextLine();
		} int i = 0; int i = 0; i 0 i < n-1 i n-1 n 1 i++ i++ i {
			name_stack.offer(scanner.next());
			time_stack.offer(scanner.nextInt());
			nothing = scanner.nextLine();
		} {
			name_stack.offer(scanner.next());
			time_stack.offer(scanner.nextInt());
			nothing = scanner.nextLine();
		} name_stack.offer(scanner.next()) name_stack.offer name_stack scanner.next() scanner.next scanner time_stack.offer(scanner.nextInt()) time_stack.offer time_stack scanner.nextInt() scanner.nextInt scanner nothing = scanner.nextLine() nothing scanner.nextLine() scanner.nextLine scanner name_stack.offer(scanner.next()) name_stack.offer name_stack scanner.next() scanner.next scanner time_stack.offer(scanner.nextInt()) time_stack.offer time_stack scanner.nextInt() scanner.nextInt scanner while(!(name_stack.isEmpty())){
			String name = name_stack.poll();
			int time = time_stack.poll();

			if(time <= q){
				all_time += time;
				System.out.println(name + " " + all_time);
			}else{
				all_time += q;
				time -= q;
				name_stack.offer(name);
				time_stack.offer(time);
			}
		} !(name_stack.isEmpty()) (name_stack.isEmpty()) name_stack.isEmpty name_stack {
			String name = name_stack.poll();
			int time = time_stack.poll();

			if(time <= q){
				all_time += time;
				System.out.println(name + " " + all_time);
			}else{
				all_time += q;
				time -= q;
				name_stack.offer(name);
				time_stack.offer(time);
			}
		} String name = name_stack.poll(); name name_stack.poll() name_stack.poll name_stack int time = time_stack.poll(); time time_stack.poll() time_stack.poll time_stack if(time <= q){
				all_time += time;
				System.out.println(name + " " + all_time);
			}else{
				all_time += q;
				time -= q;
				name_stack.offer(name);
				time_stack.offer(time);
			} time <= q time q {
				all_time += time;
				System.out.println(name + " " + all_time);
			} all_time += time all_time time System.out.println(name + " " + all_time) System.out.println System.out System System.out name + " " + all_time name + " " + all_time name " " all_time {
				all_time += q;
				time -= q;
				name_stack.offer(name);
				time_stack.offer(time);
			} all_time += q all_time q time -= q time q name_stack.offer(name) name_stack.offer name_stack name time_stack.offer(time) time_stack.offer time_stack time String[] args args
import java.util.Scanner;
import java.util.Arrays;
import java.util.Deque;
import java.util.ArrayDeque;
import java.io.BufferedReader;
import java.io.InputStreamReader;


class Main{
	public static void main(String[] args)throws Exception{
		Scanner scanner = new Scanner(System.in);
		Deque<String> name_stack = new ArrayDeque<>();
		Deque<Integer> time_stack = new ArrayDeque<>();
		int n = scanner.nextInt();
		int q = scanner.nextInt();
		String nothing = scanner.nextLine();
		int all_time = 0;

		for(int i = 0; i < n-1; i++){
			name_stack.offer(scanner.next());
			time_stack.offer(scanner.nextInt());
			nothing = scanner.nextLine();
		}
		
		name_stack.offer(scanner.next());
		time_stack.offer(scanner.nextInt());

		while(!(name_stack.isEmpty())){
			String name = name_stack.poll();
			int time = time_stack.poll();

			if(time <= q){
				all_time += time;
				System.out.println(name + " " + all_time);
			}else{
				all_time += q;
				time -= q;
				name_stack.offer(name);
				time_stack.offer(time);
			}
		}

	}
}