import java.util.Deque;
import java.util.LinkedList;
import java.util.List;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

class Main {

	public static void main(String[] args) {
		int n,q;
		int time = 0;

		Input stdIn = new Input();
		List<Integer> firstline = stdIn.getLineInteger();
		n = firstline.get(0);
		q = firstline.get(1);

		Deque<Process> queue = new LinkedList<>();

		for(int i = 0; i < n; i++) {
			List<String> line = stdIn.getLineString();
			String name = line.get(0);
			int t = Integer.parseInt(line.get(1));
			queue.add(Process.createProcess(name, t));
		}

		while(queue.size() > 0) {
			Process temp = queue.pop();
			if(temp.time <= q) {
				time += temp.time;
				System.out.println(temp.name + " " + time);
			} else {
				time += q;
				temp.decTime(q);
				queue.add(temp);
			}
		}
	}
}

class Process {
	String name;
	int time;
	public Process(String name, int time) {
		this.name = name;
		this.time = time;
	}
	public static Process createProcess(String name, int time) {
		Process p = new Process(name, time);
		return p;
	}
	public void decTime(int q) {
		this.time -= q;
	}
}
class Input {

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

	Input() {
		super();
	}

	public Integer getLineValue() {
		try {
			String[] s = br.readLine().trim().split(" ");
			return Integer.parseInt(s[0]);
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}

	public List<Integer> getLineInteger() {
		List<Integer> values = new ArrayList<>();
		try {
			String[] s = br.readLine().trim().split(" ");
			for(int i = 0; i < s.length; i++) {
				values.add(Integer.parseInt(s[i]));
			}
			return values;
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}
	public List<String> getLineString() {
		try {
			String[] s = br.readLine().trim().split(" ");
			List<String> values = Arrays.asList(s);
			return values;
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}
} import java.util.Deque; Deque java.util import java.util.LinkedList; LinkedList java.util import java.util.List; List java.util import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io import java.util.ArrayList; ArrayList java.util import java.util.Arrays; Arrays java.util import java.util.List; List java.util class Main {

	public static void main(String[] args) {
		int n,q;
		int time = 0;

		Input stdIn = new Input();
		List<Integer> firstline = stdIn.getLineInteger();
		n = firstline.get(0);
		q = firstline.get(1);

		Deque<Process> queue = new LinkedList<>();

		for(int i = 0; i < n; i++) {
			List<String> line = stdIn.getLineString();
			String name = line.get(0);
			int t = Integer.parseInt(line.get(1));
			queue.add(Process.createProcess(name, t));
		}

		while(queue.size() > 0) {
			Process temp = queue.pop();
			if(temp.time <= q) {
				time += temp.time;
				System.out.println(temp.name + " " + time);
			} else {
				time += q;
				temp.decTime(q);
				queue.add(temp);
			}
		}
	}
} Main public static void main(String[] args) {
		int n,q;
		int time = 0;

		Input stdIn = new Input();
		List<Integer> firstline = stdIn.getLineInteger();
		n = firstline.get(0);
		q = firstline.get(1);

		Deque<Process> queue = new LinkedList<>();

		for(int i = 0; i < n; i++) {
			List<String> line = stdIn.getLineString();
			String name = line.get(0);
			int t = Integer.parseInt(line.get(1));
			queue.add(Process.createProcess(name, t));
		}

		while(queue.size() > 0) {
			Process temp = queue.pop();
			if(temp.time <= q) {
				time += temp.time;
				System.out.println(temp.name + " " + time);
			} else {
				time += q;
				temp.decTime(q);
				queue.add(temp);
			}
		}
	} main {
		int n,q;
		int time = 0;

		Input stdIn = new Input();
		List<Integer> firstline = stdIn.getLineInteger();
		n = firstline.get(0);
		q = firstline.get(1);

		Deque<Process> queue = new LinkedList<>();

		for(int i = 0; i < n; i++) {
			List<String> line = stdIn.getLineString();
			String name = line.get(0);
			int t = Integer.parseInt(line.get(1));
			queue.add(Process.createProcess(name, t));
		}

		while(queue.size() > 0) {
			Process temp = queue.pop();
			if(temp.time <= q) {
				time += temp.time;
				System.out.println(temp.name + " " + time);
			} else {
				time += q;
				temp.decTime(q);
				queue.add(temp);
			}
		}
	} int n n q; q int time = 0; time 0 Input stdIn = new Input(); stdIn new Input() List<Integer> firstline = stdIn.getLineInteger(); firstline stdIn.getLineInteger() stdIn.getLineInteger stdIn n = firstline.get(0) n firstline.get(0) firstline.get firstline 0 q = firstline.get(1) q firstline.get(1) firstline.get firstline 1 Deque<Process> queue = new LinkedList<>(); queue new LinkedList<>() for(int i = 0; i < n; i++) {
			List<String> line = stdIn.getLineString();
			String name = line.get(0);
			int t = Integer.parseInt(line.get(1));
			queue.add(Process.createProcess(name, t));
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			List<String> line = stdIn.getLineString();
			String name = line.get(0);
			int t = Integer.parseInt(line.get(1));
			queue.add(Process.createProcess(name, t));
		} {
			List<String> line = stdIn.getLineString();
			String name = line.get(0);
			int t = Integer.parseInt(line.get(1));
			queue.add(Process.createProcess(name, t));
		} List<String> line = stdIn.getLineString(); line stdIn.getLineString() stdIn.getLineString stdIn String name = line.get(0); name line.get(0) line.get line 0 int t = Integer.parseInt(line.get(1)); t Integer.parseInt(line.get(1)) Integer.parseInt Integer line.get(1) line.get line 1 queue.add(Process.createProcess(name, t)) queue.add queue Process.createProcess(name, t) Process.createProcess Process name t while(queue.size() > 0) {
			Process temp = queue.pop();
			if(temp.time <= q) {
				time += temp.time;
				System.out.println(temp.name + " " + time);
			} else {
				time += q;
				temp.decTime(q);
				queue.add(temp);
			}
		} queue.size() > 0 queue.size() queue.size queue 0 {
			Process temp = queue.pop();
			if(temp.time <= q) {
				time += temp.time;
				System.out.println(temp.name + " " + time);
			} else {
				time += q;
				temp.decTime(q);
				queue.add(temp);
			}
		} Process temp = queue.pop(); temp queue.pop() queue.pop queue if(temp.time <= q) {
				time += temp.time;
				System.out.println(temp.name + " " + time);
			} else {
				time += q;
				temp.decTime(q);
				queue.add(temp);
			} temp.time <= q temp.time temp temp.time q {
				time += temp.time;
				System.out.println(temp.name + " " + time);
			} time += temp.time time temp.time temp temp.time System.out.println(temp.name + " " + time) System.out.println System.out System System.out temp.name + " " + time temp.name + " " + time temp.name temp temp.name " " time {
				time += q;
				temp.decTime(q);
				queue.add(temp);
			} time += q time q temp.decTime(q) temp.decTime temp q queue.add(temp) queue.add queue temp String[] args args class Process {
	String name;
	int time;
	public Process(String name, int time) {
		this.name = name;
		this.time = time;
	}
	public static Process createProcess(String name, int time) {
		Process p = new Process(name, time);
		return p;
	}
	public void decTime(int q) {
		this.time -= q;
	}
} Process String name; name int time; time public Process(String name, int time) {
		this.name = name;
		this.time = time;
	} Process {
		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 static Process createProcess(String name, int time) {
		Process p = new Process(name, time);
		return p;
	} createProcess {
		Process p = new Process(name, time);
		return p;
	} Process p = new Process(name, time); p new Process(name, time) return p; p String name name int time time public void decTime(int q) {
		this.time -= q;
	} decTime {
		this.time -= q;
	} this.time -= q this.time this this.time q int q q class Input {

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

	Input() {
		super();
	}

	public Integer getLineValue() {
		try {
			String[] s = br.readLine().trim().split(" ");
			return Integer.parseInt(s[0]);
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}

	public List<Integer> getLineInteger() {
		List<Integer> values = new ArrayList<>();
		try {
			String[] s = br.readLine().trim().split(" ");
			for(int i = 0; i < s.length; i++) {
				values.add(Integer.parseInt(s[i]));
			}
			return values;
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}
	public List<String> getLineString() {
		try {
			String[] s = br.readLine().trim().split(" ");
			List<String> values = Arrays.asList(s);
			return values;
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}
} Input BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) Input() {
		super();
	} Input {
		super();
	} super() super public Integer getLineValue() {
		try {
			String[] s = br.readLine().trim().split(" ");
			return Integer.parseInt(s[0]);
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	} getLineValue {
		try {
			String[] s = br.readLine().trim().split(" ");
			return Integer.parseInt(s[0]);
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	} try {
			String[] s = br.readLine().trim().split(" ");
			return Integer.parseInt(s[0]);
		} catch (IOException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} IOException e {
			e.printStackTrace();
		} e.printStackTrace() e.printStackTrace e {
			String[] s = br.readLine().trim().split(" ");
			return Integer.parseInt(s[0]);
		} String[] s = br.readLine().trim().split(" "); s br.readLine().trim().split(" ") br.readLine().trim().split br.readLine().trim() br.readLine().trim br.readLine() br.readLine br " " return Integer.parseInt(s[0]); Integer.parseInt(s[0]) Integer.parseInt Integer s[0] s 0 return null; null public List<Integer> getLineInteger() {
		List<Integer> values = new ArrayList<>();
		try {
			String[] s = br.readLine().trim().split(" ");
			for(int i = 0; i < s.length; i++) {
				values.add(Integer.parseInt(s[i]));
			}
			return values;
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	} getLineInteger {
		List<Integer> values = new ArrayList<>();
		try {
			String[] s = br.readLine().trim().split(" ");
			for(int i = 0; i < s.length; i++) {
				values.add(Integer.parseInt(s[i]));
			}
			return values;
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	} List<Integer> values = new ArrayList<>(); values new ArrayList<>() try {
			String[] s = br.readLine().trim().split(" ");
			for(int i = 0; i < s.length; i++) {
				values.add(Integer.parseInt(s[i]));
			}
			return values;
		} catch (IOException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} IOException e {
			e.printStackTrace();
		} e.printStackTrace() e.printStackTrace e {
			String[] s = br.readLine().trim().split(" ");
			for(int i = 0; i < s.length; i++) {
				values.add(Integer.parseInt(s[i]));
			}
			return values;
		} String[] s = br.readLine().trim().split(" "); s br.readLine().trim().split(" ") br.readLine().trim().split br.readLine().trim() br.readLine().trim br.readLine() br.readLine br " " for(int i = 0; i < s.length; i++) {
				values.add(Integer.parseInt(s[i]));
			} int i = 0; int i = 0; i 0 i < s.length i s.length s s.length i++ i++ i {
				values.add(Integer.parseInt(s[i]));
			} {
				values.add(Integer.parseInt(s[i]));
			} values.add(Integer.parseInt(s[i])) values.add values Integer.parseInt(s[i]) Integer.parseInt Integer s[i] s i return values; values return null; null public List<String> getLineString() {
		try {
			String[] s = br.readLine().trim().split(" ");
			List<String> values = Arrays.asList(s);
			return values;
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	} getLineString {
		try {
			String[] s = br.readLine().trim().split(" ");
			List<String> values = Arrays.asList(s);
			return values;
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	} try {
			String[] s = br.readLine().trim().split(" ");
			List<String> values = Arrays.asList(s);
			return values;
		} catch (IOException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} IOException e {
			e.printStackTrace();
		} e.printStackTrace() e.printStackTrace e {
			String[] s = br.readLine().trim().split(" ");
			List<String> values = Arrays.asList(s);
			return values;
		} String[] s = br.readLine().trim().split(" "); s br.readLine().trim().split(" ") br.readLine().trim().split br.readLine().trim() br.readLine().trim br.readLine() br.readLine br " " List<String> values = Arrays.asList(s); values Arrays.asList(s) Arrays.asList Arrays s return values; values return null; null
import java.util.Deque;
import java.util.LinkedList;
import java.util.List;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

class Main {

	public static void main(String[] args) {
		int n,q;
		int time = 0;

		Input stdIn = new Input();
		List<Integer> firstline = stdIn.getLineInteger();
		n = firstline.get(0);
		q = firstline.get(1);

		Deque<Process> queue = new LinkedList<>();

		for(int i = 0; i < n; i++) {
			List<String> line = stdIn.getLineString();
			String name = line.get(0);
			int t = Integer.parseInt(line.get(1));
			queue.add(Process.createProcess(name, t));
		}

		while(queue.size() > 0) {
			Process temp = queue.pop();
			if(temp.time <= q) {
				time += temp.time;
				System.out.println(temp.name + " " + time);
			} else {
				time += q;
				temp.decTime(q);
				queue.add(temp);
			}
		}
	}
}

class Process {
	String name;
	int time;
	public Process(String name, int time) {
		this.name = name;
		this.time = time;
	}
	public static Process createProcess(String name, int time) {
		Process p = new Process(name, time);
		return p;
	}
	public void decTime(int q) {
		this.time -= q;
	}
}
class Input {

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

	Input() {
		super();
	}

	public Integer getLineValue() {
		try {
			String[] s = br.readLine().trim().split(" ");
			return Integer.parseInt(s[0]);
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}

	public List<Integer> getLineInteger() {
		List<Integer> values = new ArrayList<>();
		try {
			String[] s = br.readLine().trim().split(" ");
			for(int i = 0; i < s.length; i++) {
				values.add(Integer.parseInt(s[i]));
			}
			return values;
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}
	public List<String> getLineString() {
		try {
			String[] s = br.readLine().trim().split(" ");
			List<String> values = Arrays.asList(s);
			return values;
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}
}