import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Queue;

public class Main {

	public static final int BIG_NUM  = 2000000000;
	public static final int MOD  = 1000000007;

	public static void main(String[] args) {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		try {
			String first_input[] = br.readLine().split("\\s+");

			int N = Integer.parseInt(first_input[0]);
			int quantum = Integer.parseInt(first_input[1]);

			Queue<Process> Q = new ArrayDeque<Process>();

			for(int loop = 0; loop < N; loop++){
				String input[] = br.readLine().split("\\s+");
				Q.add(new Process(input[0],Integer.parseInt(input[1])));
			}

			StringBuilder ans = new StringBuilder();
			Process tmp = new Process();

			int current_time = 0;

			while(!Q.isEmpty()){
				tmp = Q.peek();
				Q.poll();

				if(tmp.getTime() <= quantum){
					current_time += tmp.getTime();
					ans.append(tmp.getName()).append(" ").append(Integer.toString(current_time)).append("\n");
				}else{
					current_time += quantum;
					Q.add(new Process(tmp.getName(),tmp.getTime()-quantum));
				}
			}

			System.out.printf("%s",ans.toString());

		}catch (IOException e) {
			e.printStackTrace();
		}
	}
}

class Process{

	private String name;
	private int time;

	Process(){
		//Do nothing
	}

	Process(String arg_name,int arg_time){
		name = arg_name;
		time = arg_time;
	}

	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public int getTime() {
		return time;
	}
	public void setTime(int time) {
		this.time = time;
	}
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io import java.util.ArrayDeque; ArrayDeque java.util import java.util.Queue; Queue java.util public class Main {

	public static final int BIG_NUM  = 2000000000;
	public static final int MOD  = 1000000007;

	public static void main(String[] args) {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		try {
			String first_input[] = br.readLine().split("\\s+");

			int N = Integer.parseInt(first_input[0]);
			int quantum = Integer.parseInt(first_input[1]);

			Queue<Process> Q = new ArrayDeque<Process>();

			for(int loop = 0; loop < N; loop++){
				String input[] = br.readLine().split("\\s+");
				Q.add(new Process(input[0],Integer.parseInt(input[1])));
			}

			StringBuilder ans = new StringBuilder();
			Process tmp = new Process();

			int current_time = 0;

			while(!Q.isEmpty()){
				tmp = Q.peek();
				Q.poll();

				if(tmp.getTime() <= quantum){
					current_time += tmp.getTime();
					ans.append(tmp.getName()).append(" ").append(Integer.toString(current_time)).append("\n");
				}else{
					current_time += quantum;
					Q.add(new Process(tmp.getName(),tmp.getTime()-quantum));
				}
			}

			System.out.printf("%s",ans.toString());

		}catch (IOException e) {
			e.printStackTrace();
		}
	}
} Main public static final int BIG_NUM  = 2000000000; BIG_NUM 2000000000 public static final int MOD  = 1000000007; MOD 1000000007 public static void main(String[] args) {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		try {
			String first_input[] = br.readLine().split("\\s+");

			int N = Integer.parseInt(first_input[0]);
			int quantum = Integer.parseInt(first_input[1]);

			Queue<Process> Q = new ArrayDeque<Process>();

			for(int loop = 0; loop < N; loop++){
				String input[] = br.readLine().split("\\s+");
				Q.add(new Process(input[0],Integer.parseInt(input[1])));
			}

			StringBuilder ans = new StringBuilder();
			Process tmp = new Process();

			int current_time = 0;

			while(!Q.isEmpty()){
				tmp = Q.peek();
				Q.poll();

				if(tmp.getTime() <= quantum){
					current_time += tmp.getTime();
					ans.append(tmp.getName()).append(" ").append(Integer.toString(current_time)).append("\n");
				}else{
					current_time += quantum;
					Q.add(new Process(tmp.getName(),tmp.getTime()-quantum));
				}
			}

			System.out.printf("%s",ans.toString());

		}catch (IOException e) {
			e.printStackTrace();
		}
	} main {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		try {
			String first_input[] = br.readLine().split("\\s+");

			int N = Integer.parseInt(first_input[0]);
			int quantum = Integer.parseInt(first_input[1]);

			Queue<Process> Q = new ArrayDeque<Process>();

			for(int loop = 0; loop < N; loop++){
				String input[] = br.readLine().split("\\s+");
				Q.add(new Process(input[0],Integer.parseInt(input[1])));
			}

			StringBuilder ans = new StringBuilder();
			Process tmp = new Process();

			int current_time = 0;

			while(!Q.isEmpty()){
				tmp = Q.peek();
				Q.poll();

				if(tmp.getTime() <= quantum){
					current_time += tmp.getTime();
					ans.append(tmp.getName()).append(" ").append(Integer.toString(current_time)).append("\n");
				}else{
					current_time += quantum;
					Q.add(new Process(tmp.getName(),tmp.getTime()-quantum));
				}
			}

			System.out.printf("%s",ans.toString());

		}catch (IOException e) {
			e.printStackTrace();
		}
	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) try {
			String first_input[] = br.readLine().split("\\s+");

			int N = Integer.parseInt(first_input[0]);
			int quantum = Integer.parseInt(first_input[1]);

			Queue<Process> Q = new ArrayDeque<Process>();

			for(int loop = 0; loop < N; loop++){
				String input[] = br.readLine().split("\\s+");
				Q.add(new Process(input[0],Integer.parseInt(input[1])));
			}

			StringBuilder ans = new StringBuilder();
			Process tmp = new Process();

			int current_time = 0;

			while(!Q.isEmpty()){
				tmp = Q.peek();
				Q.poll();

				if(tmp.getTime() <= quantum){
					current_time += tmp.getTime();
					ans.append(tmp.getName()).append(" ").append(Integer.toString(current_time)).append("\n");
				}else{
					current_time += quantum;
					Q.add(new Process(tmp.getName(),tmp.getTime()-quantum));
				}
			}

			System.out.printf("%s",ans.toString());

		}catch (IOException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} IOException e {
			e.printStackTrace();
		} e.printStackTrace() e.printStackTrace e {
			String first_input[] = br.readLine().split("\\s+");

			int N = Integer.parseInt(first_input[0]);
			int quantum = Integer.parseInt(first_input[1]);

			Queue<Process> Q = new ArrayDeque<Process>();

			for(int loop = 0; loop < N; loop++){
				String input[] = br.readLine().split("\\s+");
				Q.add(new Process(input[0],Integer.parseInt(input[1])));
			}

			StringBuilder ans = new StringBuilder();
			Process tmp = new Process();

			int current_time = 0;

			while(!Q.isEmpty()){
				tmp = Q.peek();
				Q.poll();

				if(tmp.getTime() <= quantum){
					current_time += tmp.getTime();
					ans.append(tmp.getName()).append(" ").append(Integer.toString(current_time)).append("\n");
				}else{
					current_time += quantum;
					Q.add(new Process(tmp.getName(),tmp.getTime()-quantum));
				}
			}

			System.out.printf("%s",ans.toString());

		} String first_input[] = br.readLine().split("\\s+"); first_input br.readLine().split("\\s+") br.readLine().split br.readLine() br.readLine br "\\s+" int N = Integer.parseInt(first_input[0]); N Integer.parseInt(first_input[0]) Integer.parseInt Integer first_input[0] first_input 0 int quantum = Integer.parseInt(first_input[1]); quantum Integer.parseInt(first_input[1]) Integer.parseInt Integer first_input[1] first_input 1 Queue<Process> Q = new ArrayDeque<Process>(); Q new ArrayDeque<Process>() for(int loop = 0; loop < N; loop++){
				String input[] = br.readLine().split("\\s+");
				Q.add(new Process(input[0],Integer.parseInt(input[1])));
			} int loop = 0; int loop = 0; loop 0 loop < N loop N loop++ loop++ loop {
				String input[] = br.readLine().split("\\s+");
				Q.add(new Process(input[0],Integer.parseInt(input[1])));
			} {
				String input[] = br.readLine().split("\\s+");
				Q.add(new Process(input[0],Integer.parseInt(input[1])));
			} String input[] = br.readLine().split("\\s+"); input br.readLine().split("\\s+") br.readLine().split br.readLine() br.readLine br "\\s+" Q.add(new Process(input[0],Integer.parseInt(input[1]))) Q.add Q new Process(input[0],Integer.parseInt(input[1])) StringBuilder ans = new StringBuilder(); ans new StringBuilder() Process tmp = new Process(); tmp new Process() int current_time = 0; current_time 0 while(!Q.isEmpty()){
				tmp = Q.peek();
				Q.poll();

				if(tmp.getTime() <= quantum){
					current_time += tmp.getTime();
					ans.append(tmp.getName()).append(" ").append(Integer.toString(current_time)).append("\n");
				}else{
					current_time += quantum;
					Q.add(new Process(tmp.getName(),tmp.getTime()-quantum));
				}
			} !Q.isEmpty() Q.isEmpty() Q.isEmpty Q {
				tmp = Q.peek();
				Q.poll();

				if(tmp.getTime() <= quantum){
					current_time += tmp.getTime();
					ans.append(tmp.getName()).append(" ").append(Integer.toString(current_time)).append("\n");
				}else{
					current_time += quantum;
					Q.add(new Process(tmp.getName(),tmp.getTime()-quantum));
				}
			} tmp = Q.peek() tmp Q.peek() Q.peek Q Q.poll() Q.poll Q if(tmp.getTime() <= quantum){
					current_time += tmp.getTime();
					ans.append(tmp.getName()).append(" ").append(Integer.toString(current_time)).append("\n");
				}else{
					current_time += quantum;
					Q.add(new Process(tmp.getName(),tmp.getTime()-quantum));
				} tmp.getTime() <= quantum tmp.getTime() tmp.getTime tmp quantum {
					current_time += tmp.getTime();
					ans.append(tmp.getName()).append(" ").append(Integer.toString(current_time)).append("\n");
				} current_time += tmp.getTime() current_time tmp.getTime() tmp.getTime tmp ans.append(tmp.getName()).append(" ").append(Integer.toString(current_time)).append("\n") ans.append(tmp.getName()).append(" ").append(Integer.toString(current_time)).append ans.append(tmp.getName()).append(" ").append(Integer.toString(current_time)) ans.append(tmp.getName()).append(" ").append ans.append(tmp.getName()).append(" ") ans.append(tmp.getName()).append ans.append(tmp.getName()) ans.append ans tmp.getName() tmp.getName tmp " " Integer.toString(current_time) Integer.toString Integer current_time "\n" {
					current_time += quantum;
					Q.add(new Process(tmp.getName(),tmp.getTime()-quantum));
				} current_time += quantum current_time quantum Q.add(new Process(tmp.getName(),tmp.getTime()-quantum)) Q.add Q new Process(tmp.getName(),tmp.getTime()-quantum) System.out.printf("%s",ans.toString()) System.out.printf System.out System System.out "%s" ans.toString() ans.toString ans String[] args args class Process{

	private String name;
	private int time;

	Process(){
		//Do nothing
	}

	Process(String arg_name,int arg_time){
		name = arg_name;
		time = arg_time;
	}

	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public int getTime() {
		return time;
	}
	public void setTime(int time) {
		this.time = time;
	}
} Process private String name; name private int time; time Process(){
		//Do nothing
	} Process {
		//Do nothing
	} Process(String arg_name,int arg_time){
		name = arg_name;
		time = arg_time;
	} Process {
		name = arg_name;
		time = arg_time;
	} name = arg_name name arg_name time = arg_time time arg_time String arg_name arg_name int arg_time arg_time public String getName() {
		return name;
	} getName {
		return name;
	} return name; name public void setName(String name) {
		this.name = name;
	} setName {
		this.name = name;
	} this.name = name this.name this this.name name String 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 class Main {

	public static final int BIG_NUM  = 2000000000;
	public static final int MOD  = 1000000007;

	public static void main(String[] args) {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		try {
			String first_input[] = br.readLine().split("\\s+");

			int N = Integer.parseInt(first_input[0]);
			int quantum = Integer.parseInt(first_input[1]);

			Queue<Process> Q = new ArrayDeque<Process>();

			for(int loop = 0; loop < N; loop++){
				String input[] = br.readLine().split("\\s+");
				Q.add(new Process(input[0],Integer.parseInt(input[1])));
			}

			StringBuilder ans = new StringBuilder();
			Process tmp = new Process();

			int current_time = 0;

			while(!Q.isEmpty()){
				tmp = Q.peek();
				Q.poll();

				if(tmp.getTime() <= quantum){
					current_time += tmp.getTime();
					ans.append(tmp.getName()).append(" ").append(Integer.toString(current_time)).append("\n");
				}else{
					current_time += quantum;
					Q.add(new Process(tmp.getName(),tmp.getTime()-quantum));
				}
			}

			System.out.printf("%s",ans.toString());

		}catch (IOException e) {
			e.printStackTrace();
		}
	}
} public class Main {

	public static final int BIG_NUM  = 2000000000;
	public static final int MOD  = 1000000007;

	public static void main(String[] args) {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		try {
			String first_input[] = br.readLine().split("\\s+");

			int N = Integer.parseInt(first_input[0]);
			int quantum = Integer.parseInt(first_input[1]);

			Queue<Process> Q = new ArrayDeque<Process>();

			for(int loop = 0; loop < N; loop++){
				String input[] = br.readLine().split("\\s+");
				Q.add(new Process(input[0],Integer.parseInt(input[1])));
			}

			StringBuilder ans = new StringBuilder();
			Process tmp = new Process();

			int current_time = 0;

			while(!Q.isEmpty()){
				tmp = Q.peek();
				Q.poll();

				if(tmp.getTime() <= quantum){
					current_time += tmp.getTime();
					ans.append(tmp.getName()).append(" ").append(Integer.toString(current_time)).append("\n");
				}else{
					current_time += quantum;
					Q.add(new Process(tmp.getName(),tmp.getTime()-quantum));
				}
			}

			System.out.printf("%s",ans.toString());

		}catch (IOException e) {
			e.printStackTrace();
		}
	}
} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Queue;

public class Main {

	public static final int BIG_NUM  = 2000000000;
	public static final int MOD  = 1000000007;

	public static void main(String[] args) {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		try {
			String first_input[] = br.readLine().split("\\s+");

			int N = Integer.parseInt(first_input[0]);
			int quantum = Integer.parseInt(first_input[1]);

			Queue<Process> Q = new ArrayDeque<Process>();

			for(int loop = 0; loop < N; loop++){
				String input[] = br.readLine().split("\\s+");
				Q.add(new Process(input[0],Integer.parseInt(input[1])));
			}

			StringBuilder ans = new StringBuilder();
			Process tmp = new Process();

			int current_time = 0;

			while(!Q.isEmpty()){
				tmp = Q.peek();
				Q.poll();

				if(tmp.getTime() <= quantum){
					current_time += tmp.getTime();
					ans.append(tmp.getName()).append(" ").append(Integer.toString(current_time)).append("\n");
				}else{
					current_time += quantum;
					Q.add(new Process(tmp.getName(),tmp.getTime()-quantum));
				}
			}

			System.out.printf("%s",ans.toString());

		}catch (IOException e) {
			e.printStackTrace();
		}
	}
}

class Process{

	private String name;
	private int time;

	Process(){
		//Do nothing
	}

	Process(String arg_name,int arg_time){
		name = arg_name;
		time = arg_time;
	}

	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public int getTime() {
		return time;
	}
	public void setTime(int time) {
		this.time = time;
	}
}
