import java.util.LinkedList;
import java.util.Scanner;

public class Main {
	private static Scanner sc;
	public static void main(String[] args){
		sc=new Scanner(System.in);
		LinkedList<String> name=new LinkedList<String>();
		LinkedList<Integer> time=new LinkedList<Integer>();
		int n=sc.nextInt();
		int q=sc.nextInt();
		int t=0;
		for(int i=0;i<n;i++){
			name.add(sc.next());
			time.add(sc.nextInt());
		}
		while(!name.isEmpty()){
			if(time.peek()<=q){
				System.out.print(name.poll()+" ");
				t=t+time.poll();
				System.out.println(t);
			}else{
				name.add(name.poll());
				time.add(time.poll()-q);
				t=t+q;
			}
		}
	}

} import java.util.LinkedList; LinkedList java.util import java.util.Scanner; Scanner java.util public class Main {
	private static Scanner sc;
	public static void main(String[] args){
		sc=new Scanner(System.in);
		LinkedList<String> name=new LinkedList<String>();
		LinkedList<Integer> time=new LinkedList<Integer>();
		int n=sc.nextInt();
		int q=sc.nextInt();
		int t=0;
		for(int i=0;i<n;i++){
			name.add(sc.next());
			time.add(sc.nextInt());
		}
		while(!name.isEmpty()){
			if(time.peek()<=q){
				System.out.print(name.poll()+" ");
				t=t+time.poll();
				System.out.println(t);
			}else{
				name.add(name.poll());
				time.add(time.poll()-q);
				t=t+q;
			}
		}
	}

} Main private static Scanner sc; sc public static void main(String[] args){
		sc=new Scanner(System.in);
		LinkedList<String> name=new LinkedList<String>();
		LinkedList<Integer> time=new LinkedList<Integer>();
		int n=sc.nextInt();
		int q=sc.nextInt();
		int t=0;
		for(int i=0;i<n;i++){
			name.add(sc.next());
			time.add(sc.nextInt());
		}
		while(!name.isEmpty()){
			if(time.peek()<=q){
				System.out.print(name.poll()+" ");
				t=t+time.poll();
				System.out.println(t);
			}else{
				name.add(name.poll());
				time.add(time.poll()-q);
				t=t+q;
			}
		}
	} main {
		sc=new Scanner(System.in);
		LinkedList<String> name=new LinkedList<String>();
		LinkedList<Integer> time=new LinkedList<Integer>();
		int n=sc.nextInt();
		int q=sc.nextInt();
		int t=0;
		for(int i=0;i<n;i++){
			name.add(sc.next());
			time.add(sc.nextInt());
		}
		while(!name.isEmpty()){
			if(time.peek()<=q){
				System.out.print(name.poll()+" ");
				t=t+time.poll();
				System.out.println(t);
			}else{
				name.add(name.poll());
				time.add(time.poll()-q);
				t=t+q;
			}
		}
	} sc=new Scanner(System.in) sc new Scanner(System.in) LinkedList<String> name=new LinkedList<String>(); name new LinkedList<String>() LinkedList<Integer> time=new LinkedList<Integer>(); time new LinkedList<Integer>() int n=sc.nextInt(); n sc.nextInt() sc.nextInt sc int q=sc.nextInt(); q sc.nextInt() sc.nextInt sc int t=0; t 0 for(int i=0;i<n;i++){
			name.add(sc.next());
			time.add(sc.nextInt());
		} int i=0; int i=0; i 0 i<n i n i++ i++ i {
			name.add(sc.next());
			time.add(sc.nextInt());
		} {
			name.add(sc.next());
			time.add(sc.nextInt());
		} name.add(sc.next()) name.add name sc.next() sc.next sc time.add(sc.nextInt()) time.add time sc.nextInt() sc.nextInt sc while(!name.isEmpty()){
			if(time.peek()<=q){
				System.out.print(name.poll()+" ");
				t=t+time.poll();
				System.out.println(t);
			}else{
				name.add(name.poll());
				time.add(time.poll()-q);
				t=t+q;
			}
		} !name.isEmpty() name.isEmpty() name.isEmpty name {
			if(time.peek()<=q){
				System.out.print(name.poll()+" ");
				t=t+time.poll();
				System.out.println(t);
			}else{
				name.add(name.poll());
				time.add(time.poll()-q);
				t=t+q;
			}
		} if(time.peek()<=q){
				System.out.print(name.poll()+" ");
				t=t+time.poll();
				System.out.println(t);
			}else{
				name.add(name.poll());
				time.add(time.poll()-q);
				t=t+q;
			} time.peek()<=q time.peek() time.peek time q {
				System.out.print(name.poll()+" ");
				t=t+time.poll();
				System.out.println(t);
			} System.out.print(name.poll()+" ") System.out.print System.out System System.out name.poll()+" " name.poll() name.poll name " " t=t+time.poll() t t+time.poll() t time.poll() time.poll time System.out.println(t) System.out.println System.out System System.out t {
				name.add(name.poll());
				time.add(time.poll()-q);
				t=t+q;
			} name.add(name.poll()) name.add name name.poll() name.poll name time.add(time.poll()-q) time.add time time.poll()-q time.poll() time.poll time q t=t+q t t+q t q String[] args args public class Main {
	private static Scanner sc;
	public static void main(String[] args){
		sc=new Scanner(System.in);
		LinkedList<String> name=new LinkedList<String>();
		LinkedList<Integer> time=new LinkedList<Integer>();
		int n=sc.nextInt();
		int q=sc.nextInt();
		int t=0;
		for(int i=0;i<n;i++){
			name.add(sc.next());
			time.add(sc.nextInt());
		}
		while(!name.isEmpty()){
			if(time.peek()<=q){
				System.out.print(name.poll()+" ");
				t=t+time.poll();
				System.out.println(t);
			}else{
				name.add(name.poll());
				time.add(time.poll()-q);
				t=t+q;
			}
		}
	}

} public class Main {
	private static Scanner sc;
	public static void main(String[] args){
		sc=new Scanner(System.in);
		LinkedList<String> name=new LinkedList<String>();
		LinkedList<Integer> time=new LinkedList<Integer>();
		int n=sc.nextInt();
		int q=sc.nextInt();
		int t=0;
		for(int i=0;i<n;i++){
			name.add(sc.next());
			time.add(sc.nextInt());
		}
		while(!name.isEmpty()){
			if(time.peek()<=q){
				System.out.print(name.poll()+" ");
				t=t+time.poll();
				System.out.println(t);
			}else{
				name.add(name.poll());
				time.add(time.poll()-q);
				t=t+q;
			}
		}
	}

} Main
import java.util.LinkedList;
import java.util.Scanner;

public class Main {
	private static Scanner sc;
	public static void main(String[] args){
		sc=new Scanner(System.in);
		LinkedList<String> name=new LinkedList<String>();
		LinkedList<Integer> time=new LinkedList<Integer>();
		int n=sc.nextInt();
		int q=sc.nextInt();
		int t=0;
		for(int i=0;i<n;i++){
			name.add(sc.next());
			time.add(sc.nextInt());
		}
		while(!name.isEmpty()){
			if(time.peek()<=q){
				System.out.print(name.poll()+" ");
				t=t+time.poll();
				System.out.println(t);
			}else{
				name.add(name.poll());
				time.add(time.poll()-q);
				t=t+q;
			}
		}
	}

}