import java.util.Scanner;

class Data{
	String name;
	int time;
	Data next;
	
	Data(String s,int t){
		name=s;
		time=t;
		next=null;
	}
}

public class Main {
	static Data first=new Data("",0);
	static Data attention=first;
	
	static Data dequeue(){
		Data tmp=first.next;
		if(attention==tmp){
			attention=first;
		}
		first.next=tmp.next;
		return tmp;
	}
	
	static void enqueue(String s,int t){
		attention.next=new Data(s,t);
		attention=attention.next;
	}

	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		int n=scan.nextInt();//プロセス数。
		int q=scan.nextInt();//クォンタム
		int finish=0;
		String s;
		int t;
		for(int i=0;i<n;i++){
			s=scan.next();
			t=scan.nextInt();
			enqueue(s,t);
		}

		while(first.next!=null){
			Data tmp=dequeue();
			s=tmp.name;
			t=tmp.time;
			finish+=q;
			if(t-q<=0){//プロセスが終了する場合
				finish=finish+(t-q);
				System.out.printf("%s %d\n",s,finish);
			}else{//プロセスがまだ終了しない場合
				enqueue(s,t-q);
			}
		}
		
		
		scan.close();
		
	}

} import java.util.Scanner; Scanner java.util class Data{
	String name;
	int time;
	Data next;
	
	Data(String s,int t){
		name=s;
		time=t;
		next=null;
	}
} Data String name; name int time; time Data next; next Data(String s,int t){
		name=s;
		time=t;
		next=null;
	} Data {
		name=s;
		time=t;
		next=null;
	} name=s name s time=t time t next=null next null String s s int t t public class Main {
	static Data first=new Data("",0);
	static Data attention=first;
	
	static Data dequeue(){
		Data tmp=first.next;
		if(attention==tmp){
			attention=first;
		}
		first.next=tmp.next;
		return tmp;
	}
	
	static void enqueue(String s,int t){
		attention.next=new Data(s,t);
		attention=attention.next;
	}

	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		int n=scan.nextInt();//プロセス数。
		int q=scan.nextInt();//クォンタム
		int finish=0;
		String s;
		int t;
		for(int i=0;i<n;i++){
			s=scan.next();
			t=scan.nextInt();
			enqueue(s,t);
		}

		while(first.next!=null){
			Data tmp=dequeue();
			s=tmp.name;
			t=tmp.time;
			finish+=q;
			if(t-q<=0){//プロセスが終了する場合
				finish=finish+(t-q);
				System.out.printf("%s %d\n",s,finish);
			}else{//プロセスがまだ終了しない場合
				enqueue(s,t-q);
			}
		}
		
		
		scan.close();
		
	}

} Main static Data first=new Data("",0); first new Data("",0) static Data attention=first; attention first static Data dequeue(){
		Data tmp=first.next;
		if(attention==tmp){
			attention=first;
		}
		first.next=tmp.next;
		return tmp;
	} dequeue {
		Data tmp=first.next;
		if(attention==tmp){
			attention=first;
		}
		first.next=tmp.next;
		return tmp;
	} Data tmp=first.next; tmp first.next first first.next if(attention==tmp){
			attention=first;
		} attention==tmp attention tmp {
			attention=first;
		} attention=first attention first first.next=tmp.next first.next first first.next tmp.next tmp tmp.next return tmp; tmp static void enqueue(String s,int t){
		attention.next=new Data(s,t);
		attention=attention.next;
	} enqueue {
		attention.next=new Data(s,t);
		attention=attention.next;
	} attention.next=new Data(s,t) attention.next attention attention.next new Data(s,t) attention=attention.next attention attention.next attention attention.next String s s int t t public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		int n=scan.nextInt();//プロセス数。
		int q=scan.nextInt();//クォンタム
		int finish=0;
		String s;
		int t;
		for(int i=0;i<n;i++){
			s=scan.next();
			t=scan.nextInt();
			enqueue(s,t);
		}

		while(first.next!=null){
			Data tmp=dequeue();
			s=tmp.name;
			t=tmp.time;
			finish+=q;
			if(t-q<=0){//プロセスが終了する場合
				finish=finish+(t-q);
				System.out.printf("%s %d\n",s,finish);
			}else{//プロセスがまだ終了しない場合
				enqueue(s,t-q);
			}
		}
		
		
		scan.close();
		
	} main {
		Scanner scan=new Scanner(System.in);
		int n=scan.nextInt();//プロセス数。
		int q=scan.nextInt();//クォンタム
		int finish=0;
		String s;
		int t;
		for(int i=0;i<n;i++){
			s=scan.next();
			t=scan.nextInt();
			enqueue(s,t);
		}

		while(first.next!=null){
			Data tmp=dequeue();
			s=tmp.name;
			t=tmp.time;
			finish+=q;
			if(t-q<=0){//プロセスが終了する場合
				finish=finish+(t-q);
				System.out.printf("%s %d\n",s,finish);
			}else{//プロセスがまだ終了しない場合
				enqueue(s,t-q);
			}
		}
		
		
		scan.close();
		
	} Scanner scan=new Scanner(System.in); scan new Scanner(System.in) int n=scan.nextInt(); n scan.nextInt() scan.nextInt scan int q=scan.nextInt(); q scan.nextInt() scan.nextInt scan int finish=0; finish 0 String s; s int t; t for(int i=0;i<n;i++){
			s=scan.next();
			t=scan.nextInt();
			enqueue(s,t);
		} int i=0; int i=0; i 0 i<n i n i++ i++ i {
			s=scan.next();
			t=scan.nextInt();
			enqueue(s,t);
		} {
			s=scan.next();
			t=scan.nextInt();
			enqueue(s,t);
		} s=scan.next() s scan.next() scan.next scan t=scan.nextInt() t scan.nextInt() scan.nextInt scan enqueue(s,t) enqueue s t while(first.next!=null){
			Data tmp=dequeue();
			s=tmp.name;
			t=tmp.time;
			finish+=q;
			if(t-q<=0){//プロセスが終了する場合
				finish=finish+(t-q);
				System.out.printf("%s %d\n",s,finish);
			}else{//プロセスがまだ終了しない場合
				enqueue(s,t-q);
			}
		} first.next!=null first.next first first.next null {
			Data tmp=dequeue();
			s=tmp.name;
			t=tmp.time;
			finish+=q;
			if(t-q<=0){//プロセスが終了する場合
				finish=finish+(t-q);
				System.out.printf("%s %d\n",s,finish);
			}else{//プロセスがまだ終了しない場合
				enqueue(s,t-q);
			}
		} Data tmp=dequeue(); tmp dequeue() dequeue s=tmp.name s tmp.name tmp tmp.name t=tmp.time t tmp.time tmp tmp.time finish+=q finish q if(t-q<=0){//プロセスが終了する場合
				finish=finish+(t-q);
				System.out.printf("%s %d\n",s,finish);
			}else{//プロセスがまだ終了しない場合
				enqueue(s,t-q);
			} t-q<=0 t-q t q 0 {//プロセスが終了する場合
				finish=finish+(t-q);
				System.out.printf("%s %d\n",s,finish);
			} finish=finish+(t-q) finish finish+(t-q) finish (t-q) t q System.out.printf("%s %d\n",s,finish) System.out.printf System.out System System.out "%s %d\n" s finish {//プロセスがまだ終了しない場合
				enqueue(s,t-q);
			} enqueue(s,t-q) enqueue s t-q t q scan.close() scan.close scan String[] args args public class Main {
	static Data first=new Data("",0);
	static Data attention=first;
	
	static Data dequeue(){
		Data tmp=first.next;
		if(attention==tmp){
			attention=first;
		}
		first.next=tmp.next;
		return tmp;
	}
	
	static void enqueue(String s,int t){
		attention.next=new Data(s,t);
		attention=attention.next;
	}

	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		int n=scan.nextInt();//プロセス数。
		int q=scan.nextInt();//クォンタム
		int finish=0;
		String s;
		int t;
		for(int i=0;i<n;i++){
			s=scan.next();
			t=scan.nextInt();
			enqueue(s,t);
		}

		while(first.next!=null){
			Data tmp=dequeue();
			s=tmp.name;
			t=tmp.time;
			finish+=q;
			if(t-q<=0){//プロセスが終了する場合
				finish=finish+(t-q);
				System.out.printf("%s %d\n",s,finish);
			}else{//プロセスがまだ終了しない場合
				enqueue(s,t-q);
			}
		}
		
		
		scan.close();
		
	}

} public class Main {
	static Data first=new Data("",0);
	static Data attention=first;
	
	static Data dequeue(){
		Data tmp=first.next;
		if(attention==tmp){
			attention=first;
		}
		first.next=tmp.next;
		return tmp;
	}
	
	static void enqueue(String s,int t){
		attention.next=new Data(s,t);
		attention=attention.next;
	}

	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		int n=scan.nextInt();//プロセス数。
		int q=scan.nextInt();//クォンタム
		int finish=0;
		String s;
		int t;
		for(int i=0;i<n;i++){
			s=scan.next();
			t=scan.nextInt();
			enqueue(s,t);
		}

		while(first.next!=null){
			Data tmp=dequeue();
			s=tmp.name;
			t=tmp.time;
			finish+=q;
			if(t-q<=0){//プロセスが終了する場合
				finish=finish+(t-q);
				System.out.printf("%s %d\n",s,finish);
			}else{//プロセスがまだ終了しない場合
				enqueue(s,t-q);
			}
		}
		
		
		scan.close();
		
	}

} Main
import java.util.Scanner;

class Data{
	String name;
	int time;
	Data next;
	
	Data(String s,int t){
		name=s;
		time=t;
		next=null;
	}
}

public class Main {
	static Data first=new Data("",0);
	static Data attention=first;
	
	static Data dequeue(){
		Data tmp=first.next;
		if(attention==tmp){
			attention=first;
		}
		first.next=tmp.next;
		return tmp;
	}
	
	static void enqueue(String s,int t){
		attention.next=new Data(s,t);
		attention=attention.next;
	}

	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		int n=scan.nextInt();//プロセス数。
		int q=scan.nextInt();//クォンタム
		int finish=0;
		String s;
		int t;
		for(int i=0;i<n;i++){
			s=scan.next();
			t=scan.nextInt();
			enqueue(s,t);
		}

		while(first.next!=null){
			Data tmp=dequeue();
			s=tmp.name;
			t=tmp.time;
			finish+=q;
			if(t-q<=0){//プロセスが終了する場合
				finish=finish+(t-q);
				System.out.printf("%s %d\n",s,finish);
			}else{//プロセスがまだ終了しない場合
				enqueue(s,t-q);
			}
		}
		
		
		scan.close();
		
	}

}