import java.io.*;

class Main{
	public static void main(String[] args){
		try{
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			String wk[] = br.readLine().split(" ", 0);
			int n = Integer.parseInt(""+wk[0]);
			int q = Integer.parseInt(""+wk[1]);
			String name[] = new String[n+1];
			int time[] = new int[n+1];
			int i, ttime=0;
			int head=0, tail=n-1;
			for(i=0; i<n; i++){
				wk = br.readLine().split(" ", 0);
				name[i] = wk[0];
				time[i] = Integer.parseInt(""+wk[1]);
			}
			while(n>0){
				if(time[head]<=q){
					ttime += time[head];
					System.out.println(name[head]+" "+ttime);
					for(i=head; i<n-1; i++){
						name[i] = name[i+1];
						time[i] = time[i+1];
					}
					if(head==n-1) head=0;
					if(tail==n-1) tail=0;
					n--;
				} else{
					ttime += q;
					time[head] -= q;
					head++;
					if(head==n) head=0;
					tail++;
					if(tail==n) tail=0;
				}
			}
		} catch(IOException e){
			System.out.println("Exception :" + e);
		}
	}
} import java.io.*; io.* java class Main{
	public static void main(String[] args){
		try{
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			String wk[] = br.readLine().split(" ", 0);
			int n = Integer.parseInt(""+wk[0]);
			int q = Integer.parseInt(""+wk[1]);
			String name[] = new String[n+1];
			int time[] = new int[n+1];
			int i, ttime=0;
			int head=0, tail=n-1;
			for(i=0; i<n; i++){
				wk = br.readLine().split(" ", 0);
				name[i] = wk[0];
				time[i] = Integer.parseInt(""+wk[1]);
			}
			while(n>0){
				if(time[head]<=q){
					ttime += time[head];
					System.out.println(name[head]+" "+ttime);
					for(i=head; i<n-1; i++){
						name[i] = name[i+1];
						time[i] = time[i+1];
					}
					if(head==n-1) head=0;
					if(tail==n-1) tail=0;
					n--;
				} else{
					ttime += q;
					time[head] -= q;
					head++;
					if(head==n) head=0;
					tail++;
					if(tail==n) tail=0;
				}
			}
		} catch(IOException e){
			System.out.println("Exception :" + e);
		}
	}
} Main public static void main(String[] args){
		try{
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			String wk[] = br.readLine().split(" ", 0);
			int n = Integer.parseInt(""+wk[0]);
			int q = Integer.parseInt(""+wk[1]);
			String name[] = new String[n+1];
			int time[] = new int[n+1];
			int i, ttime=0;
			int head=0, tail=n-1;
			for(i=0; i<n; i++){
				wk = br.readLine().split(" ", 0);
				name[i] = wk[0];
				time[i] = Integer.parseInt(""+wk[1]);
			}
			while(n>0){
				if(time[head]<=q){
					ttime += time[head];
					System.out.println(name[head]+" "+ttime);
					for(i=head; i<n-1; i++){
						name[i] = name[i+1];
						time[i] = time[i+1];
					}
					if(head==n-1) head=0;
					if(tail==n-1) tail=0;
					n--;
				} else{
					ttime += q;
					time[head] -= q;
					head++;
					if(head==n) head=0;
					tail++;
					if(tail==n) tail=0;
				}
			}
		} catch(IOException e){
			System.out.println("Exception :" + e);
		}
	} main {
		try{
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			String wk[] = br.readLine().split(" ", 0);
			int n = Integer.parseInt(""+wk[0]);
			int q = Integer.parseInt(""+wk[1]);
			String name[] = new String[n+1];
			int time[] = new int[n+1];
			int i, ttime=0;
			int head=0, tail=n-1;
			for(i=0; i<n; i++){
				wk = br.readLine().split(" ", 0);
				name[i] = wk[0];
				time[i] = Integer.parseInt(""+wk[1]);
			}
			while(n>0){
				if(time[head]<=q){
					ttime += time[head];
					System.out.println(name[head]+" "+ttime);
					for(i=head; i<n-1; i++){
						name[i] = name[i+1];
						time[i] = time[i+1];
					}
					if(head==n-1) head=0;
					if(tail==n-1) tail=0;
					n--;
				} else{
					ttime += q;
					time[head] -= q;
					head++;
					if(head==n) head=0;
					tail++;
					if(tail==n) tail=0;
				}
			}
		} catch(IOException e){
			System.out.println("Exception :" + e);
		}
	} try{
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			String wk[] = br.readLine().split(" ", 0);
			int n = Integer.parseInt(""+wk[0]);
			int q = Integer.parseInt(""+wk[1]);
			String name[] = new String[n+1];
			int time[] = new int[n+1];
			int i, ttime=0;
			int head=0, tail=n-1;
			for(i=0; i<n; i++){
				wk = br.readLine().split(" ", 0);
				name[i] = wk[0];
				time[i] = Integer.parseInt(""+wk[1]);
			}
			while(n>0){
				if(time[head]<=q){
					ttime += time[head];
					System.out.println(name[head]+" "+ttime);
					for(i=head; i<n-1; i++){
						name[i] = name[i+1];
						time[i] = time[i+1];
					}
					if(head==n-1) head=0;
					if(tail==n-1) tail=0;
					n--;
				} else{
					ttime += q;
					time[head] -= q;
					head++;
					if(head==n) head=0;
					tail++;
					if(tail==n) tail=0;
				}
			}
		} catch(IOException e){
			System.out.println("Exception :" + e);
		} catch(IOException e){
			System.out.println("Exception :" + e);
		} IOException e {
			System.out.println("Exception :" + e);
		} System.out.println("Exception :" + e) System.out.println System.out System System.out "Exception :" + e "Exception :" e {
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			String wk[] = br.readLine().split(" ", 0);
			int n = Integer.parseInt(""+wk[0]);
			int q = Integer.parseInt(""+wk[1]);
			String name[] = new String[n+1];
			int time[] = new int[n+1];
			int i, ttime=0;
			int head=0, tail=n-1;
			for(i=0; i<n; i++){
				wk = br.readLine().split(" ", 0);
				name[i] = wk[0];
				time[i] = Integer.parseInt(""+wk[1]);
			}
			while(n>0){
				if(time[head]<=q){
					ttime += time[head];
					System.out.println(name[head]+" "+ttime);
					for(i=head; i<n-1; i++){
						name[i] = name[i+1];
						time[i] = time[i+1];
					}
					if(head==n-1) head=0;
					if(tail==n-1) tail=0;
					n--;
				} else{
					ttime += q;
					time[head] -= q;
					head++;
					if(head==n) head=0;
					tail++;
					if(tail==n) tail=0;
				}
			}
		} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) String wk[] = br.readLine().split(" ", 0); wk br.readLine().split(" ", 0) br.readLine().split br.readLine() br.readLine br " " 0 int n = Integer.parseInt(""+wk[0]); n Integer.parseInt(""+wk[0]) Integer.parseInt Integer ""+wk[0] "" wk[0] wk 0 int q = Integer.parseInt(""+wk[1]); q Integer.parseInt(""+wk[1]) Integer.parseInt Integer ""+wk[1] "" wk[1] wk 1 String name[] = new String[n+1]; name new String[n+1] n+1 n 1 int time[] = new int[n+1]; time new int[n+1] n+1 n 1 int i i ttime=0; ttime 0 int head=0 head 0 tail=n-1; tail n-1 n 1 for(i=0; i<n; i++){
				wk = br.readLine().split(" ", 0);
				name[i] = wk[0];
				time[i] = Integer.parseInt(""+wk[1]);
			} i=0; i=0 i 0 i<n i n i++ i++ i {
				wk = br.readLine().split(" ", 0);
				name[i] = wk[0];
				time[i] = Integer.parseInt(""+wk[1]);
			} {
				wk = br.readLine().split(" ", 0);
				name[i] = wk[0];
				time[i] = Integer.parseInt(""+wk[1]);
			} wk = br.readLine().split(" ", 0) wk br.readLine().split(" ", 0) br.readLine().split br.readLine() br.readLine br " " 0 name[i] = wk[0] name[i] name i wk[0] wk 0 time[i] = Integer.parseInt(""+wk[1]) time[i] time i Integer.parseInt(""+wk[1]) Integer.parseInt Integer ""+wk[1] "" wk[1] wk 1 while(n>0){
				if(time[head]<=q){
					ttime += time[head];
					System.out.println(name[head]+" "+ttime);
					for(i=head; i<n-1; i++){
						name[i] = name[i+1];
						time[i] = time[i+1];
					}
					if(head==n-1) head=0;
					if(tail==n-1) tail=0;
					n--;
				} else{
					ttime += q;
					time[head] -= q;
					head++;
					if(head==n) head=0;
					tail++;
					if(tail==n) tail=0;
				}
			} n>0 n 0 {
				if(time[head]<=q){
					ttime += time[head];
					System.out.println(name[head]+" "+ttime);
					for(i=head; i<n-1; i++){
						name[i] = name[i+1];
						time[i] = time[i+1];
					}
					if(head==n-1) head=0;
					if(tail==n-1) tail=0;
					n--;
				} else{
					ttime += q;
					time[head] -= q;
					head++;
					if(head==n) head=0;
					tail++;
					if(tail==n) tail=0;
				}
			} if(time[head]<=q){
					ttime += time[head];
					System.out.println(name[head]+" "+ttime);
					for(i=head; i<n-1; i++){
						name[i] = name[i+1];
						time[i] = time[i+1];
					}
					if(head==n-1) head=0;
					if(tail==n-1) tail=0;
					n--;
				} else{
					ttime += q;
					time[head] -= q;
					head++;
					if(head==n) head=0;
					tail++;
					if(tail==n) tail=0;
				} time[head]<=q time[head] time head q {
					ttime += time[head];
					System.out.println(name[head]+" "+ttime);
					for(i=head; i<n-1; i++){
						name[i] = name[i+1];
						time[i] = time[i+1];
					}
					if(head==n-1) head=0;
					if(tail==n-1) tail=0;
					n--;
				} ttime += time[head] ttime time[head] time head System.out.println(name[head]+" "+ttime) System.out.println System.out System System.out name[head]+" "+ttime name[head]+" "+ttime name[head] name head " " ttime for(i=head; i<n-1; i++){
						name[i] = name[i+1];
						time[i] = time[i+1];
					} i=head; i=head i head i<n-1 i n-1 n 1 i++ i++ i {
						name[i] = name[i+1];
						time[i] = time[i+1];
					} {
						name[i] = name[i+1];
						time[i] = time[i+1];
					} name[i] = name[i+1] name[i] name i name[i+1] name i+1 i 1 time[i] = time[i+1] time[i] time i time[i+1] time i+1 i 1 if(head==n-1) head=0; head==n-1 head n-1 n 1 head=0 head 0 if(tail==n-1) tail=0; tail==n-1 tail n-1 n 1 tail=0 tail 0 n-- n {
					ttime += q;
					time[head] -= q;
					head++;
					if(head==n) head=0;
					tail++;
					if(tail==n) tail=0;
				} ttime += q ttime q time[head] -= q time[head] time head q head++ head if(head==n) head=0; head==n head n head=0 head 0 tail++ tail if(tail==n) tail=0; tail==n tail n tail=0 tail 0 String[] args args
import java.io.*;

class Main{
	public static void main(String[] args){
		try{
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			String wk[] = br.readLine().split(" ", 0);
			int n = Integer.parseInt(""+wk[0]);
			int q = Integer.parseInt(""+wk[1]);
			String name[] = new String[n+1];
			int time[] = new int[n+1];
			int i, ttime=0;
			int head=0, tail=n-1;
			for(i=0; i<n; i++){
				wk = br.readLine().split(" ", 0);
				name[i] = wk[0];
				time[i] = Integer.parseInt(""+wk[1]);
			}
			while(n>0){
				if(time[head]<=q){
					ttime += time[head];
					System.out.println(name[head]+" "+ttime);
					for(i=head; i<n-1; i++){
						name[i] = name[i+1];
						time[i] = time[i+1];
					}
					if(head==n-1) head=0;
					if(tail==n-1) tail=0;
					n--;
				} else{
					ttime += q;
					time[head] -= q;
					head++;
					if(head==n) head=0;
					tail++;
					if(tail==n) tail=0;
				}
			}
		} catch(IOException e){
			System.out.println("Exception :" + e);
		}
	}
}