import java.util.*;

public class Main {
	public static void main(String[] args){
		Scanner sc= new Scanner(System.in);
		int n=sc.nextInt();
		int q=sc.nextInt();
		int t=0;
		LinkedList<Process> list=new LinkedList<Process>();
		for(int i=0;i<n;i++){
			String ps=sc.next();
			int pt=sc.nextInt();
			Process pr=new Process(ps,pt);
			list.addLast(pr);
		}
		while(list.size()>0){
			if((list.getFirst()).time>q){
				Process x=list.poll();
				t+=q;
				x.time-=q;
				list.add(x);				
			}else{
				Process x=list.poll();
				t+=x.time;
				System.out.println(x.name+" "+t);
			}
		}
	}
}

class Process{
	String name;
	int time;
	Process(String a,int b){
		name=a;
		time=b;
	}
} import java.util.*; util.* java public class Main {
	public static void main(String[] args){
		Scanner sc= new Scanner(System.in);
		int n=sc.nextInt();
		int q=sc.nextInt();
		int t=0;
		LinkedList<Process> list=new LinkedList<Process>();
		for(int i=0;i<n;i++){
			String ps=sc.next();
			int pt=sc.nextInt();
			Process pr=new Process(ps,pt);
			list.addLast(pr);
		}
		while(list.size()>0){
			if((list.getFirst()).time>q){
				Process x=list.poll();
				t+=q;
				x.time-=q;
				list.add(x);				
			}else{
				Process x=list.poll();
				t+=x.time;
				System.out.println(x.name+" "+t);
			}
		}
	}
} Main public static void main(String[] args){
		Scanner sc= new Scanner(System.in);
		int n=sc.nextInt();
		int q=sc.nextInt();
		int t=0;
		LinkedList<Process> list=new LinkedList<Process>();
		for(int i=0;i<n;i++){
			String ps=sc.next();
			int pt=sc.nextInt();
			Process pr=new Process(ps,pt);
			list.addLast(pr);
		}
		while(list.size()>0){
			if((list.getFirst()).time>q){
				Process x=list.poll();
				t+=q;
				x.time-=q;
				list.add(x);				
			}else{
				Process x=list.poll();
				t+=x.time;
				System.out.println(x.name+" "+t);
			}
		}
	} main {
		Scanner sc= new Scanner(System.in);
		int n=sc.nextInt();
		int q=sc.nextInt();
		int t=0;
		LinkedList<Process> list=new LinkedList<Process>();
		for(int i=0;i<n;i++){
			String ps=sc.next();
			int pt=sc.nextInt();
			Process pr=new Process(ps,pt);
			list.addLast(pr);
		}
		while(list.size()>0){
			if((list.getFirst()).time>q){
				Process x=list.poll();
				t+=q;
				x.time-=q;
				list.add(x);				
			}else{
				Process x=list.poll();
				t+=x.time;
				System.out.println(x.name+" "+t);
			}
		}
	} Scanner sc= new Scanner(System.in); sc new Scanner(System.in) 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 LinkedList<Process> list=new LinkedList<Process>(); list new LinkedList<Process>() for(int i=0;i<n;i++){
			String ps=sc.next();
			int pt=sc.nextInt();
			Process pr=new Process(ps,pt);
			list.addLast(pr);
		} int i=0; int i=0; i 0 i<n i n i++ i++ i {
			String ps=sc.next();
			int pt=sc.nextInt();
			Process pr=new Process(ps,pt);
			list.addLast(pr);
		} {
			String ps=sc.next();
			int pt=sc.nextInt();
			Process pr=new Process(ps,pt);
			list.addLast(pr);
		} String ps=sc.next(); ps sc.next() sc.next sc int pt=sc.nextInt(); pt sc.nextInt() sc.nextInt sc Process pr=new Process(ps,pt); pr new Process(ps,pt) list.addLast(pr) list.addLast list pr while(list.size()>0){
			if((list.getFirst()).time>q){
				Process x=list.poll();
				t+=q;
				x.time-=q;
				list.add(x);				
			}else{
				Process x=list.poll();
				t+=x.time;
				System.out.println(x.name+" "+t);
			}
		} list.size()>0 list.size() list.size list 0 {
			if((list.getFirst()).time>q){
				Process x=list.poll();
				t+=q;
				x.time-=q;
				list.add(x);				
			}else{
				Process x=list.poll();
				t+=x.time;
				System.out.println(x.name+" "+t);
			}
		} if((list.getFirst()).time>q){
				Process x=list.poll();
				t+=q;
				x.time-=q;
				list.add(x);				
			}else{
				Process x=list.poll();
				t+=x.time;
				System.out.println(x.name+" "+t);
			} (list.getFirst()).time>q (list.getFirst()).time (list.getFirst()) list.getFirst list (list.getFirst()).time q {
				Process x=list.poll();
				t+=q;
				x.time-=q;
				list.add(x);				
			} Process x=list.poll(); x list.poll() list.poll list t+=q t q x.time-=q x.time x x.time q list.add(x) list.add list x {
				Process x=list.poll();
				t+=x.time;
				System.out.println(x.name+" "+t);
			} Process x=list.poll(); x list.poll() list.poll list t+=x.time t x.time x x.time System.out.println(x.name+" "+t) System.out.println System.out System System.out x.name+" "+t x.name+" "+t x.name x x.name " " t String[] args args class Process{
	String name;
	int time;
	Process(String a,int b){
		name=a;
		time=b;
	}
} Process String name; name int time; time Process(String a,int b){
		name=a;
		time=b;
	} Process {
		name=a;
		time=b;
	} name=a name a time=b time b String a a int b b public class Main {
	public static void main(String[] args){
		Scanner sc= new Scanner(System.in);
		int n=sc.nextInt();
		int q=sc.nextInt();
		int t=0;
		LinkedList<Process> list=new LinkedList<Process>();
		for(int i=0;i<n;i++){
			String ps=sc.next();
			int pt=sc.nextInt();
			Process pr=new Process(ps,pt);
			list.addLast(pr);
		}
		while(list.size()>0){
			if((list.getFirst()).time>q){
				Process x=list.poll();
				t+=q;
				x.time-=q;
				list.add(x);				
			}else{
				Process x=list.poll();
				t+=x.time;
				System.out.println(x.name+" "+t);
			}
		}
	}
} public class Main {
	public static void main(String[] args){
		Scanner sc= new Scanner(System.in);
		int n=sc.nextInt();
		int q=sc.nextInt();
		int t=0;
		LinkedList<Process> list=new LinkedList<Process>();
		for(int i=0;i<n;i++){
			String ps=sc.next();
			int pt=sc.nextInt();
			Process pr=new Process(ps,pt);
			list.addLast(pr);
		}
		while(list.size()>0){
			if((list.getFirst()).time>q){
				Process x=list.poll();
				t+=q;
				x.time-=q;
				list.add(x);				
			}else{
				Process x=list.poll();
				t+=x.time;
				System.out.println(x.name+" "+t);
			}
		}
	}
} Main
import java.util.*;

public class Main {
	public static void main(String[] args){
		Scanner sc= new Scanner(System.in);
		int n=sc.nextInt();
		int q=sc.nextInt();
		int t=0;
		LinkedList<Process> list=new LinkedList<Process>();
		for(int i=0;i<n;i++){
			String ps=sc.next();
			int pt=sc.nextInt();
			Process pr=new Process(ps,pt);
			list.addLast(pr);
		}
		while(list.size()>0){
			if((list.getFirst()).time>q){
				Process x=list.poll();
				t+=q;
				x.time-=q;
				list.add(x);				
			}else{
				Process x=list.poll();
				t+=x.time;
				System.out.println(x.name+" "+t);
			}
		}
	}
}

class Process{
	String name;
	int time;
	Process(String a,int b){
		name=a;
		time=b;
	}
}