import java.util.*;
class Pair{
	int t;
	String name;
	public Pair(int val,String str){
		t = val;
		name = str; 
	}
}
public class Main {
	public static void main(String args[]){
		Scanner sc =new Scanner(System.in);
		int n,quantum;
		n = sc.nextInt();
		quantum = sc.nextInt();
		Queue<Pair> queue = new LinkedList<Pair>();
		for(int i=0;i<n;i++){
			String name = sc.next();
			int t = sc.nextInt();
			queue.offer(new Pair(t,name));
		}
		int elapse =0;
		while(!queue.isEmpty()){
			Pair p = queue.poll();
			int c= Math.min(p.t, quantum);
			p.t -=c;
			elapse+=c;
			if(p.t>0){
				queue.offer(p);
			}else{
				System.out.println(p.name+" "+elapse);
			}
		}
		
	}
} import java.util.*; util.* java class Pair{
	int t;
	String name;
	public Pair(int val,String str){
		t = val;
		name = str; 
	}
} Pair int t; t String name; name public Pair(int val,String str){
		t = val;
		name = str; 
	} Pair {
		t = val;
		name = str; 
	} t = val t val name = str name str int val val String str str public class Main {
	public static void main(String args[]){
		Scanner sc =new Scanner(System.in);
		int n,quantum;
		n = sc.nextInt();
		quantum = sc.nextInt();
		Queue<Pair> queue = new LinkedList<Pair>();
		for(int i=0;i<n;i++){
			String name = sc.next();
			int t = sc.nextInt();
			queue.offer(new Pair(t,name));
		}
		int elapse =0;
		while(!queue.isEmpty()){
			Pair p = queue.poll();
			int c= Math.min(p.t, quantum);
			p.t -=c;
			elapse+=c;
			if(p.t>0){
				queue.offer(p);
			}else{
				System.out.println(p.name+" "+elapse);
			}
		}
		
	}
} Main public static void main(String args[]){
		Scanner sc =new Scanner(System.in);
		int n,quantum;
		n = sc.nextInt();
		quantum = sc.nextInt();
		Queue<Pair> queue = new LinkedList<Pair>();
		for(int i=0;i<n;i++){
			String name = sc.next();
			int t = sc.nextInt();
			queue.offer(new Pair(t,name));
		}
		int elapse =0;
		while(!queue.isEmpty()){
			Pair p = queue.poll();
			int c= Math.min(p.t, quantum);
			p.t -=c;
			elapse+=c;
			if(p.t>0){
				queue.offer(p);
			}else{
				System.out.println(p.name+" "+elapse);
			}
		}
		
	} main {
		Scanner sc =new Scanner(System.in);
		int n,quantum;
		n = sc.nextInt();
		quantum = sc.nextInt();
		Queue<Pair> queue = new LinkedList<Pair>();
		for(int i=0;i<n;i++){
			String name = sc.next();
			int t = sc.nextInt();
			queue.offer(new Pair(t,name));
		}
		int elapse =0;
		while(!queue.isEmpty()){
			Pair p = queue.poll();
			int c= Math.min(p.t, quantum);
			p.t -=c;
			elapse+=c;
			if(p.t>0){
				queue.offer(p);
			}else{
				System.out.println(p.name+" "+elapse);
			}
		}
		
	} Scanner sc =new Scanner(System.in); sc new Scanner(System.in) int n n quantum; quantum n = sc.nextInt() n sc.nextInt() sc.nextInt sc quantum = sc.nextInt() quantum sc.nextInt() sc.nextInt sc Queue<Pair> queue = new LinkedList<Pair>(); queue new LinkedList<Pair>() for(int i=0;i<n;i++){
			String name = sc.next();
			int t = sc.nextInt();
			queue.offer(new Pair(t,name));
		} int i=0; int i=0; i 0 i<n i n i++ i++ i {
			String name = sc.next();
			int t = sc.nextInt();
			queue.offer(new Pair(t,name));
		} {
			String name = sc.next();
			int t = sc.nextInt();
			queue.offer(new Pair(t,name));
		} String name = sc.next(); name sc.next() sc.next sc int t = sc.nextInt(); t sc.nextInt() sc.nextInt sc queue.offer(new Pair(t,name)) queue.offer queue new Pair(t,name) int elapse =0; elapse 0 while(!queue.isEmpty()){
			Pair p = queue.poll();
			int c= Math.min(p.t, quantum);
			p.t -=c;
			elapse+=c;
			if(p.t>0){
				queue.offer(p);
			}else{
				System.out.println(p.name+" "+elapse);
			}
		} !queue.isEmpty() queue.isEmpty() queue.isEmpty queue {
			Pair p = queue.poll();
			int c= Math.min(p.t, quantum);
			p.t -=c;
			elapse+=c;
			if(p.t>0){
				queue.offer(p);
			}else{
				System.out.println(p.name+" "+elapse);
			}
		} Pair p = queue.poll(); p queue.poll() queue.poll queue int c= Math.min(p.t, quantum); c Math.min(p.t, quantum) Math.min Math p.t p p.t quantum p.t -=c p.t p p.t c elapse+=c elapse c if(p.t>0){
				queue.offer(p);
			}else{
				System.out.println(p.name+" "+elapse);
			} p.t>0 p.t p p.t 0 {
				queue.offer(p);
			} queue.offer(p) queue.offer queue p {
				System.out.println(p.name+" "+elapse);
			} System.out.println(p.name+" "+elapse) System.out.println System.out System System.out p.name+" "+elapse p.name+" "+elapse p.name p p.name " " elapse String args[] args public class Main {
	public static void main(String args[]){
		Scanner sc =new Scanner(System.in);
		int n,quantum;
		n = sc.nextInt();
		quantum = sc.nextInt();
		Queue<Pair> queue = new LinkedList<Pair>();
		for(int i=0;i<n;i++){
			String name = sc.next();
			int t = sc.nextInt();
			queue.offer(new Pair(t,name));
		}
		int elapse =0;
		while(!queue.isEmpty()){
			Pair p = queue.poll();
			int c= Math.min(p.t, quantum);
			p.t -=c;
			elapse+=c;
			if(p.t>0){
				queue.offer(p);
			}else{
				System.out.println(p.name+" "+elapse);
			}
		}
		
	}
} public class Main {
	public static void main(String args[]){
		Scanner sc =new Scanner(System.in);
		int n,quantum;
		n = sc.nextInt();
		quantum = sc.nextInt();
		Queue<Pair> queue = new LinkedList<Pair>();
		for(int i=0;i<n;i++){
			String name = sc.next();
			int t = sc.nextInt();
			queue.offer(new Pair(t,name));
		}
		int elapse =0;
		while(!queue.isEmpty()){
			Pair p = queue.poll();
			int c= Math.min(p.t, quantum);
			p.t -=c;
			elapse+=c;
			if(p.t>0){
				queue.offer(p);
			}else{
				System.out.println(p.name+" "+elapse);
			}
		}
		
	}
} Main
import java.util.*;
class Pair{
	int t;
	String name;
	public Pair(int val,String str){
		t = val;
		name = str; 
	}
}
public class Main {
	public static void main(String args[]){
		Scanner sc =new Scanner(System.in);
		int n,quantum;
		n = sc.nextInt();
		quantum = sc.nextInt();
		Queue<Pair> queue = new LinkedList<Pair>();
		for(int i=0;i<n;i++){
			String name = sc.next();
			int t = sc.nextInt();
			queue.offer(new Pair(t,name));
		}
		int elapse =0;
		while(!queue.isEmpty()){
			Pair p = queue.poll();
			int c= Math.min(p.t, quantum);
			p.t -=c;
			elapse+=c;
			if(p.t>0){
				queue.offer(p);
			}else{
				System.out.println(p.name+" "+elapse);
			}
		}
		
	}
}