import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner cin=new Scanner(System.in);
		
		int n=cin.nextInt(),q=cin.nextInt(),TIME=0;
		Queue<String> name=new ArrayDeque<>();Queue<Integer>time=new ArrayDeque<>();
		for(int i=0;i<n;i++) {
			name.add(cin.next());time.add(cin.nextInt());
		}
		
		while(name.peek()!=null) {
			String str=name.remove();int t=time.remove();
			if(t>q) {
				name.add(str);time.add(t-q);
				TIME+=q;
			}
			else{
				System.out.println(str+" "+(TIME+t));
				TIME+=t;
			}
			
		}
	}

}
 import java.util.*; util.* java public class Main {

	public static void main(String[] args) {
		Scanner cin=new Scanner(System.in);
		
		int n=cin.nextInt(),q=cin.nextInt(),TIME=0;
		Queue<String> name=new ArrayDeque<>();Queue<Integer>time=new ArrayDeque<>();
		for(int i=0;i<n;i++) {
			name.add(cin.next());time.add(cin.nextInt());
		}
		
		while(name.peek()!=null) {
			String str=name.remove();int t=time.remove();
			if(t>q) {
				name.add(str);time.add(t-q);
				TIME+=q;
			}
			else{
				System.out.println(str+" "+(TIME+t));
				TIME+=t;
			}
			
		}
	}

} Main public static void main(String[] args) {
		Scanner cin=new Scanner(System.in);
		
		int n=cin.nextInt(),q=cin.nextInt(),TIME=0;
		Queue<String> name=new ArrayDeque<>();Queue<Integer>time=new ArrayDeque<>();
		for(int i=0;i<n;i++) {
			name.add(cin.next());time.add(cin.nextInt());
		}
		
		while(name.peek()!=null) {
			String str=name.remove();int t=time.remove();
			if(t>q) {
				name.add(str);time.add(t-q);
				TIME+=q;
			}
			else{
				System.out.println(str+" "+(TIME+t));
				TIME+=t;
			}
			
		}
	} main {
		Scanner cin=new Scanner(System.in);
		
		int n=cin.nextInt(),q=cin.nextInt(),TIME=0;
		Queue<String> name=new ArrayDeque<>();Queue<Integer>time=new ArrayDeque<>();
		for(int i=0;i<n;i++) {
			name.add(cin.next());time.add(cin.nextInt());
		}
		
		while(name.peek()!=null) {
			String str=name.remove();int t=time.remove();
			if(t>q) {
				name.add(str);time.add(t-q);
				TIME+=q;
			}
			else{
				System.out.println(str+" "+(TIME+t));
				TIME+=t;
			}
			
		}
	} Scanner cin=new Scanner(System.in); cin new Scanner(System.in) int n=cin.nextInt() n cin.nextInt() cin.nextInt cin q=cin.nextInt() q cin.nextInt() cin.nextInt cin TIME=0; TIME 0 Queue<String> name=new ArrayDeque<>(); name new ArrayDeque<>() Queue<Integer>time=new ArrayDeque<>(); time new ArrayDeque<>() for(int i=0;i<n;i++) {
			name.add(cin.next());time.add(cin.nextInt());
		} int i=0; int i=0; i 0 i<n i n i++ i++ i {
			name.add(cin.next());time.add(cin.nextInt());
		} {
			name.add(cin.next());time.add(cin.nextInt());
		} name.add(cin.next()) name.add name cin.next() cin.next cin time.add(cin.nextInt()) time.add time cin.nextInt() cin.nextInt cin while(name.peek()!=null) {
			String str=name.remove();int t=time.remove();
			if(t>q) {
				name.add(str);time.add(t-q);
				TIME+=q;
			}
			else{
				System.out.println(str+" "+(TIME+t));
				TIME+=t;
			}
			
		} name.peek()!=null name.peek() name.peek name null {
			String str=name.remove();int t=time.remove();
			if(t>q) {
				name.add(str);time.add(t-q);
				TIME+=q;
			}
			else{
				System.out.println(str+" "+(TIME+t));
				TIME+=t;
			}
			
		} String str=name.remove(); str name.remove() name.remove name int t=time.remove(); t time.remove() time.remove time if(t>q) {
				name.add(str);time.add(t-q);
				TIME+=q;
			}
			else{
				System.out.println(str+" "+(TIME+t));
				TIME+=t;
			} t>q t q {
				name.add(str);time.add(t-q);
				TIME+=q;
			} name.add(str) name.add name str time.add(t-q) time.add time t-q t q TIME+=q TIME q {
				System.out.println(str+" "+(TIME+t));
				TIME+=t;
			} System.out.println(str+" "+(TIME+t)) System.out.println System.out System System.out str+" "+(TIME+t) str+" "+(TIME+t) str " " (TIME+t) TIME t TIME+=t TIME t String[] args args public class Main {

	public static void main(String[] args) {
		Scanner cin=new Scanner(System.in);
		
		int n=cin.nextInt(),q=cin.nextInt(),TIME=0;
		Queue<String> name=new ArrayDeque<>();Queue<Integer>time=new ArrayDeque<>();
		for(int i=0;i<n;i++) {
			name.add(cin.next());time.add(cin.nextInt());
		}
		
		while(name.peek()!=null) {
			String str=name.remove();int t=time.remove();
			if(t>q) {
				name.add(str);time.add(t-q);
				TIME+=q;
			}
			else{
				System.out.println(str+" "+(TIME+t));
				TIME+=t;
			}
			
		}
	}

} public class Main {

	public static void main(String[] args) {
		Scanner cin=new Scanner(System.in);
		
		int n=cin.nextInt(),q=cin.nextInt(),TIME=0;
		Queue<String> name=new ArrayDeque<>();Queue<Integer>time=new ArrayDeque<>();
		for(int i=0;i<n;i++) {
			name.add(cin.next());time.add(cin.nextInt());
		}
		
		while(name.peek()!=null) {
			String str=name.remove();int t=time.remove();
			if(t>q) {
				name.add(str);time.add(t-q);
				TIME+=q;
			}
			else{
				System.out.println(str+" "+(TIME+t));
				TIME+=t;
			}
			
		}
	}

} Main
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner cin=new Scanner(System.in);
		
		int n=cin.nextInt(),q=cin.nextInt(),TIME=0;
		Queue<String> name=new ArrayDeque<>();Queue<Integer>time=new ArrayDeque<>();
		for(int i=0;i<n;i++) {
			name.add(cin.next());time.add(cin.nextInt());
		}
		
		while(name.peek()!=null) {
			String str=name.remove();int t=time.remove();
			if(t>q) {
				name.add(str);time.add(t-q);
				TIME+=q;
			}
			else{
				System.out.println(str+" "+(TIME+t));
				TIME+=t;
			}
			
		}
	}

}

