import java.io.*;

class Main{
	private Node first, last;

	public Main(){
		int n, limit = 0, timeSt = 0;
		String[] tmp;
		Node[] process;

		BufferedReader br = 
			new BufferedReader(new InputStreamReader(System.in), 1);
		try{
			tmp = br.readLine().split(" ");
			n = Integer.parseInt(tmp[0]);
			limit = Integer.parseInt(tmp[1]);
			process = new Node[n];

			for(int i=0; i < n; i++){
				tmp = br.readLine().split(" ");
				process[i] = 
					new Node(tmp[0], Integer.parseInt(tmp[1]));
				enqueue(process[i]);
			}

		}catch(IOException e){
			System.out.println(e);
		}
		Node node = null;
		while( (node = dequeue()) != null){
			if( node.getTime() <= limit){
				timeSt += node.getTime(); 
				System.out.println(node+" "+timeSt);
			}else{
				timeSt += limit;
				int t = node.getTime();
				node.setTime(t - limit);
				enqueue(node);
			}
		}
	}

	void enqueue(Node p){
		if(first == null){
			last = p;
			first = last; 
		} else{
			last.next = p;
			last = last.next;
		}
	}
	Node dequeue(){
		if(first != null){
			Node tmp = first;
			first = first.next;
			tmp.next = null;
			return tmp;
		}
		return null;
	}

	void printQueue(){
		Node n = first;
		while(n != null){
			System.out.println(n);
			n = n.next;
		}
	}
	
	public static void main(String[] args){
		new Main();
	}
}

class Node{
	private String name;
	private int time;
	Node next;

	Node(String name, int time){
		this.name = name;
		this.time = time;
	}
	int getTime(){
		return this.time;
	}
	void setTime(int time){
		this.time = time;
	}
	void setNext(Node n){
		next = n;
	}
	@Override
	public String toString(){
		return name;
	}
} import java.io.*; io.* java class Main{
	private Node first, last;

	public Main(){
		int n, limit = 0, timeSt = 0;
		String[] tmp;
		Node[] process;

		BufferedReader br = 
			new BufferedReader(new InputStreamReader(System.in), 1);
		try{
			tmp = br.readLine().split(" ");
			n = Integer.parseInt(tmp[0]);
			limit = Integer.parseInt(tmp[1]);
			process = new Node[n];

			for(int i=0; i < n; i++){
				tmp = br.readLine().split(" ");
				process[i] = 
					new Node(tmp[0], Integer.parseInt(tmp[1]));
				enqueue(process[i]);
			}

		}catch(IOException e){
			System.out.println(e);
		}
		Node node = null;
		while( (node = dequeue()) != null){
			if( node.getTime() <= limit){
				timeSt += node.getTime(); 
				System.out.println(node+" "+timeSt);
			}else{
				timeSt += limit;
				int t = node.getTime();
				node.setTime(t - limit);
				enqueue(node);
			}
		}
	}

	void enqueue(Node p){
		if(first == null){
			last = p;
			first = last; 
		} else{
			last.next = p;
			last = last.next;
		}
	}
	Node dequeue(){
		if(first != null){
			Node tmp = first;
			first = first.next;
			tmp.next = null;
			return tmp;
		}
		return null;
	}

	void printQueue(){
		Node n = first;
		while(n != null){
			System.out.println(n);
			n = n.next;
		}
	}
	
	public static void main(String[] args){
		new Main();
	}
} Main private Node first first last; last public Main(){
		int n, limit = 0, timeSt = 0;
		String[] tmp;
		Node[] process;

		BufferedReader br = 
			new BufferedReader(new InputStreamReader(System.in), 1);
		try{
			tmp = br.readLine().split(" ");
			n = Integer.parseInt(tmp[0]);
			limit = Integer.parseInt(tmp[1]);
			process = new Node[n];

			for(int i=0; i < n; i++){
				tmp = br.readLine().split(" ");
				process[i] = 
					new Node(tmp[0], Integer.parseInt(tmp[1]));
				enqueue(process[i]);
			}

		}catch(IOException e){
			System.out.println(e);
		}
		Node node = null;
		while( (node = dequeue()) != null){
			if( node.getTime() <= limit){
				timeSt += node.getTime(); 
				System.out.println(node+" "+timeSt);
			}else{
				timeSt += limit;
				int t = node.getTime();
				node.setTime(t - limit);
				enqueue(node);
			}
		}
	} Main {
		int n, limit = 0, timeSt = 0;
		String[] tmp;
		Node[] process;

		BufferedReader br = 
			new BufferedReader(new InputStreamReader(System.in), 1);
		try{
			tmp = br.readLine().split(" ");
			n = Integer.parseInt(tmp[0]);
			limit = Integer.parseInt(tmp[1]);
			process = new Node[n];

			for(int i=0; i < n; i++){
				tmp = br.readLine().split(" ");
				process[i] = 
					new Node(tmp[0], Integer.parseInt(tmp[1]));
				enqueue(process[i]);
			}

		}catch(IOException e){
			System.out.println(e);
		}
		Node node = null;
		while( (node = dequeue()) != null){
			if( node.getTime() <= limit){
				timeSt += node.getTime(); 
				System.out.println(node+" "+timeSt);
			}else{
				timeSt += limit;
				int t = node.getTime();
				node.setTime(t - limit);
				enqueue(node);
			}
		}
	} int n n limit = 0 limit 0 timeSt = 0; timeSt 0 String[] tmp; tmp Node[] process; process BufferedReader br = 
			new BufferedReader(new InputStreamReader(System.in), 1); br new BufferedReader(new InputStreamReader(System.in), 1) try{
			tmp = br.readLine().split(" ");
			n = Integer.parseInt(tmp[0]);
			limit = Integer.parseInt(tmp[1]);
			process = new Node[n];

			for(int i=0; i < n; i++){
				tmp = br.readLine().split(" ");
				process[i] = 
					new Node(tmp[0], Integer.parseInt(tmp[1]));
				enqueue(process[i]);
			}

		}catch(IOException e){
			System.out.println(e);
		} catch(IOException e){
			System.out.println(e);
		} IOException e {
			System.out.println(e);
		} System.out.println(e) System.out.println System.out System System.out e {
			tmp = br.readLine().split(" ");
			n = Integer.parseInt(tmp[0]);
			limit = Integer.parseInt(tmp[1]);
			process = new Node[n];

			for(int i=0; i < n; i++){
				tmp = br.readLine().split(" ");
				process[i] = 
					new Node(tmp[0], Integer.parseInt(tmp[1]));
				enqueue(process[i]);
			}

		} tmp = br.readLine().split(" ") tmp br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " n = Integer.parseInt(tmp[0]) n Integer.parseInt(tmp[0]) Integer.parseInt Integer tmp[0] tmp 0 limit = Integer.parseInt(tmp[1]) limit Integer.parseInt(tmp[1]) Integer.parseInt Integer tmp[1] tmp 1 process = new Node[n] process new Node[n] n for(int i=0; i < n; i++){
				tmp = br.readLine().split(" ");
				process[i] = 
					new Node(tmp[0], Integer.parseInt(tmp[1]));
				enqueue(process[i]);
			} int i=0; int i=0; i 0 i < n i n i++ i++ i {
				tmp = br.readLine().split(" ");
				process[i] = 
					new Node(tmp[0], Integer.parseInt(tmp[1]));
				enqueue(process[i]);
			} {
				tmp = br.readLine().split(" ");
				process[i] = 
					new Node(tmp[0], Integer.parseInt(tmp[1]));
				enqueue(process[i]);
			} tmp = br.readLine().split(" ") tmp br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " process[i] = 
					new Node(tmp[0], Integer.parseInt(tmp[1])) process[i] process i new Node(tmp[0], Integer.parseInt(tmp[1])) enqueue(process[i]) enqueue process[i] process i Node node = null; node null while( (node = dequeue()) != null){
			if( node.getTime() <= limit){
				timeSt += node.getTime(); 
				System.out.println(node+" "+timeSt);
			}else{
				timeSt += limit;
				int t = node.getTime();
				node.setTime(t - limit);
				enqueue(node);
			}
		} (node = dequeue()) != null (node = dequeue()) node dequeue() dequeue null {
			if( node.getTime() <= limit){
				timeSt += node.getTime(); 
				System.out.println(node+" "+timeSt);
			}else{
				timeSt += limit;
				int t = node.getTime();
				node.setTime(t - limit);
				enqueue(node);
			}
		} if( node.getTime() <= limit){
				timeSt += node.getTime(); 
				System.out.println(node+" "+timeSt);
			}else{
				timeSt += limit;
				int t = node.getTime();
				node.setTime(t - limit);
				enqueue(node);
			} node.getTime() <= limit node.getTime() node.getTime node limit {
				timeSt += node.getTime(); 
				System.out.println(node+" "+timeSt);
			} timeSt += node.getTime() timeSt node.getTime() node.getTime node System.out.println(node+" "+timeSt) System.out.println System.out System System.out node+" "+timeSt node+" "+timeSt node " " timeSt {
				timeSt += limit;
				int t = node.getTime();
				node.setTime(t - limit);
				enqueue(node);
			} timeSt += limit timeSt limit int t = node.getTime(); t node.getTime() node.getTime node node.setTime(t - limit) node.setTime node t - limit t limit enqueue(node) enqueue node void enqueue(Node p){
		if(first == null){
			last = p;
			first = last; 
		} else{
			last.next = p;
			last = last.next;
		}
	} enqueue {
		if(first == null){
			last = p;
			first = last; 
		} else{
			last.next = p;
			last = last.next;
		}
	} if(first == null){
			last = p;
			first = last; 
		} else{
			last.next = p;
			last = last.next;
		} first == null first null {
			last = p;
			first = last; 
		} last = p last p first = last first last {
			last.next = p;
			last = last.next;
		} last.next = p last.next last last.next p last = last.next last last.next last last.next Node p p Node dequeue(){
		if(first != null){
			Node tmp = first;
			first = first.next;
			tmp.next = null;
			return tmp;
		}
		return null;
	} dequeue {
		if(first != null){
			Node tmp = first;
			first = first.next;
			tmp.next = null;
			return tmp;
		}
		return null;
	} if(first != null){
			Node tmp = first;
			first = first.next;
			tmp.next = null;
			return tmp;
		} first != null first null {
			Node tmp = first;
			first = first.next;
			tmp.next = null;
			return tmp;
		} Node tmp = first; tmp first first = first.next first first.next first first.next tmp.next = null tmp.next tmp tmp.next null return tmp; tmp return null; null void printQueue(){
		Node n = first;
		while(n != null){
			System.out.println(n);
			n = n.next;
		}
	} printQueue {
		Node n = first;
		while(n != null){
			System.out.println(n);
			n = n.next;
		}
	} Node n = first; n first while(n != null){
			System.out.println(n);
			n = n.next;
		} n != null n null {
			System.out.println(n);
			n = n.next;
		} System.out.println(n) System.out.println System.out System System.out n n = n.next n n.next n n.next public static void main(String[] args){
		new Main();
	} main {
		new Main();
	} new Main() String[] args args class Node{
	private String name;
	private int time;
	Node next;

	Node(String name, int time){
		this.name = name;
		this.time = time;
	}
	int getTime(){
		return this.time;
	}
	void setTime(int time){
		this.time = time;
	}
	void setNext(Node n){
		next = n;
	}
	@Override
	public String toString(){
		return name;
	}
} Node private String name; name private int time; time Node next; next Node(String name, int time){
		this.name = name;
		this.time = time;
	} Node {
		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 int getTime(){
		return this.time;
	} getTime {
		return this.time;
	} return this.time; this.time this this.time void setTime(int time){
		this.time = time;
	} setTime {
		this.time = time;
	} this.time = time this.time this this.time time int time time void setNext(Node n){
		next = n;
	} setNext {
		next = n;
	} next = n next n Node n n @Override
	public String toString(){
		return name;
	} toString {
		return name;
	} return name; name
import java.io.*;

class Main{
	private Node first, last;

	public Main(){
		int n, limit = 0, timeSt = 0;
		String[] tmp;
		Node[] process;

		BufferedReader br = 
			new BufferedReader(new InputStreamReader(System.in), 1);
		try{
			tmp = br.readLine().split(" ");
			n = Integer.parseInt(tmp[0]);
			limit = Integer.parseInt(tmp[1]);
			process = new Node[n];

			for(int i=0; i < n; i++){
				tmp = br.readLine().split(" ");
				process[i] = 
					new Node(tmp[0], Integer.parseInt(tmp[1]));
				enqueue(process[i]);
			}

		}catch(IOException e){
			System.out.println(e);
		}
		Node node = null;
		while( (node = dequeue()) != null){
			if( node.getTime() <= limit){
				timeSt += node.getTime(); 
				System.out.println(node+" "+timeSt);
			}else{
				timeSt += limit;
				int t = node.getTime();
				node.setTime(t - limit);
				enqueue(node);
			}
		}
	}

	void enqueue(Node p){
		if(first == null){
			last = p;
			first = last; 
		} else{
			last.next = p;
			last = last.next;
		}
	}
	Node dequeue(){
		if(first != null){
			Node tmp = first;
			first = first.next;
			tmp.next = null;
			return tmp;
		}
		return null;
	}

	void printQueue(){
		Node n = first;
		while(n != null){
			System.out.println(n);
			n = n.next;
		}
	}
	
	public static void main(String[] args){
		new Main();
	}
}

class Node{
	private String name;
	private int time;
	Node next;

	Node(String name, int time){
		this.name = name;
		this.time = time;
	}
	int getTime(){
		return this.time;
	}
	void setTime(int time){
		this.time = time;
	}
	void setNext(Node n){
		next = n;
	}
	@Override
	public String toString(){
		return name;
	}
}