import java.util.Scanner;

class Work {
	String name;
	int time;
	
	Work(String n,int t){
		name=n;  time=t;
	}
	
}

class Queue {
	int head;
	int tail;
	Work[] a;
	
	/*コンストラクタ*/
	Queue(int n){
		head=0; tail=-1; a=new Work[n];
	}
	
	void enqueue(Work x,int n){
		tail=(tail+1)%n;
		a[tail]=x;
	}
	
	Work dequeue(int n){
		Work temp=a[head];
		head=(head+1)%n;
		return temp;
	}
	
	void decrease(int t){
		a[head].time-=t;
	}
	
	int getTime(){
		return a[head].time;
	}
	
	String getName(){
		return a[head].name;
	}
	
}

class Main {
	
	static void solve(Queue Q,int n,int q,int sum){
		int time=0;
		Work temp;
		
		while(time != sum){
			if(Q.getTime() == q){
				time+=q;
				System.out.println(Q.getName() + " " + time);
				temp=Q.dequeue(n);
			}
			else if(Q.getTime() < q){
				time+=Q.getTime();
				System.out.println(Q.getName() + " " + time);
				temp=Q.dequeue(n);
			}
			else {
				time+=q;
				Q.decrease(q);
				temp=Q.dequeue(n);
				Q.enqueue(temp,n);
			}
		}
		
		return;
	}
		
	
	
	public static void main(String[] args){
		Scanner scan=new Scanner(System.in);
		
		int n=scan.nextInt();
		int q=scan.nextInt();
		int sum=0;
		Queue Q=new Queue(n);
		
		for(int i=0;i<n;i++){
			Work temp=new Work(scan.next(),scan.nextInt());
			Q.enqueue(temp,n);
			sum+=temp.time;
		}
		
		solve(Q,n,q,sum);
		
	}
} import java.util.Scanner; Scanner java.util class Work {
	String name;
	int time;
	
	Work(String n,int t){
		name=n;  time=t;
	}
	
} Work String name; name int time; time Work(String n,int t){
		name=n;  time=t;
	} Work {
		name=n;  time=t;
	} name=n name n time=t time t String n n int t t class Queue {
	int head;
	int tail;
	Work[] a;
	
	/*コンストラクタ*/
	Queue(int n){
		head=0; tail=-1; a=new Work[n];
	}
	
	void enqueue(Work x,int n){
		tail=(tail+1)%n;
		a[tail]=x;
	}
	
	Work dequeue(int n){
		Work temp=a[head];
		head=(head+1)%n;
		return temp;
	}
	
	void decrease(int t){
		a[head].time-=t;
	}
	
	int getTime(){
		return a[head].time;
	}
	
	String getName(){
		return a[head].name;
	}
	
} Queue int head; head int tail; tail Work[] a; a /*コンストラクタ*/
	Queue(int n){
		head=0; tail=-1; a=new Work[n];
	} Queue {
		head=0; tail=-1; a=new Work[n];
	} head=0 head 0 tail=-1 tail -1 1 a=new Work[n] a new Work[n] n int n n void enqueue(Work x,int n){
		tail=(tail+1)%n;
		a[tail]=x;
	} enqueue {
		tail=(tail+1)%n;
		a[tail]=x;
	} tail=(tail+1)%n tail (tail+1)%n (tail+1) tail 1 n a[tail]=x a[tail] a tail x Work x x int n n Work dequeue(int n){
		Work temp=a[head];
		head=(head+1)%n;
		return temp;
	} dequeue {
		Work temp=a[head];
		head=(head+1)%n;
		return temp;
	} Work temp=a[head]; temp a[head] a head head=(head+1)%n head (head+1)%n (head+1) head 1 n return temp; temp int n n void decrease(int t){
		a[head].time-=t;
	} decrease {
		a[head].time-=t;
	} a[head].time-=t a[head].time a[head] a head a[head].time t int t t int getTime(){
		return a[head].time;
	} getTime {
		return a[head].time;
	} return a[head].time; a[head].time a[head] a head a[head].time String getName(){
		return a[head].name;
	} getName {
		return a[head].name;
	} return a[head].name; a[head].name a[head] a head a[head].name class Main {
	
	static void solve(Queue Q,int n,int q,int sum){
		int time=0;
		Work temp;
		
		while(time != sum){
			if(Q.getTime() == q){
				time+=q;
				System.out.println(Q.getName() + " " + time);
				temp=Q.dequeue(n);
			}
			else if(Q.getTime() < q){
				time+=Q.getTime();
				System.out.println(Q.getName() + " " + time);
				temp=Q.dequeue(n);
			}
			else {
				time+=q;
				Q.decrease(q);
				temp=Q.dequeue(n);
				Q.enqueue(temp,n);
			}
		}
		
		return;
	}
		
	
	
	public static void main(String[] args){
		Scanner scan=new Scanner(System.in);
		
		int n=scan.nextInt();
		int q=scan.nextInt();
		int sum=0;
		Queue Q=new Queue(n);
		
		for(int i=0;i<n;i++){
			Work temp=new Work(scan.next(),scan.nextInt());
			Q.enqueue(temp,n);
			sum+=temp.time;
		}
		
		solve(Q,n,q,sum);
		
	}
} Main static void solve(Queue Q,int n,int q,int sum){
		int time=0;
		Work temp;
		
		while(time != sum){
			if(Q.getTime() == q){
				time+=q;
				System.out.println(Q.getName() + " " + time);
				temp=Q.dequeue(n);
			}
			else if(Q.getTime() < q){
				time+=Q.getTime();
				System.out.println(Q.getName() + " " + time);
				temp=Q.dequeue(n);
			}
			else {
				time+=q;
				Q.decrease(q);
				temp=Q.dequeue(n);
				Q.enqueue(temp,n);
			}
		}
		
		return;
	} solve {
		int time=0;
		Work temp;
		
		while(time != sum){
			if(Q.getTime() == q){
				time+=q;
				System.out.println(Q.getName() + " " + time);
				temp=Q.dequeue(n);
			}
			else if(Q.getTime() < q){
				time+=Q.getTime();
				System.out.println(Q.getName() + " " + time);
				temp=Q.dequeue(n);
			}
			else {
				time+=q;
				Q.decrease(q);
				temp=Q.dequeue(n);
				Q.enqueue(temp,n);
			}
		}
		
		return;
	} int time=0; time 0 Work temp; temp while(time != sum){
			if(Q.getTime() == q){
				time+=q;
				System.out.println(Q.getName() + " " + time);
				temp=Q.dequeue(n);
			}
			else if(Q.getTime() < q){
				time+=Q.getTime();
				System.out.println(Q.getName() + " " + time);
				temp=Q.dequeue(n);
			}
			else {
				time+=q;
				Q.decrease(q);
				temp=Q.dequeue(n);
				Q.enqueue(temp,n);
			}
		} time != sum time sum {
			if(Q.getTime() == q){
				time+=q;
				System.out.println(Q.getName() + " " + time);
				temp=Q.dequeue(n);
			}
			else if(Q.getTime() < q){
				time+=Q.getTime();
				System.out.println(Q.getName() + " " + time);
				temp=Q.dequeue(n);
			}
			else {
				time+=q;
				Q.decrease(q);
				temp=Q.dequeue(n);
				Q.enqueue(temp,n);
			}
		} if(Q.getTime() == q){
				time+=q;
				System.out.println(Q.getName() + " " + time);
				temp=Q.dequeue(n);
			}
			else if(Q.getTime() < q){
				time+=Q.getTime();
				System.out.println(Q.getName() + " " + time);
				temp=Q.dequeue(n);
			}
			else {
				time+=q;
				Q.decrease(q);
				temp=Q.dequeue(n);
				Q.enqueue(temp,n);
			} Q.getTime() == q Q.getTime() Q.getTime Q q {
				time+=q;
				System.out.println(Q.getName() + " " + time);
				temp=Q.dequeue(n);
			} time+=q time q System.out.println(Q.getName() + " " + time) System.out.println System.out System System.out Q.getName() + " " + time Q.getName() + " " + time Q.getName() Q.getName Q " " time temp=Q.dequeue(n) temp Q.dequeue(n) Q.dequeue Q n if(Q.getTime() < q){
				time+=Q.getTime();
				System.out.println(Q.getName() + " " + time);
				temp=Q.dequeue(n);
			}
			else {
				time+=q;
				Q.decrease(q);
				temp=Q.dequeue(n);
				Q.enqueue(temp,n);
			} Q.getTime() < q Q.getTime() Q.getTime Q q {
				time+=Q.getTime();
				System.out.println(Q.getName() + " " + time);
				temp=Q.dequeue(n);
			} time+=Q.getTime() time Q.getTime() Q.getTime Q System.out.println(Q.getName() + " " + time) System.out.println System.out System System.out Q.getName() + " " + time Q.getName() + " " + time Q.getName() Q.getName Q " " time temp=Q.dequeue(n) temp Q.dequeue(n) Q.dequeue Q n {
				time+=q;
				Q.decrease(q);
				temp=Q.dequeue(n);
				Q.enqueue(temp,n);
			} time+=q time q Q.decrease(q) Q.decrease Q q temp=Q.dequeue(n) temp Q.dequeue(n) Q.dequeue Q n Q.enqueue(temp,n) Q.enqueue Q temp n return; Queue Q Q int n n int q q int sum sum public static void main(String[] args){
		Scanner scan=new Scanner(System.in);
		
		int n=scan.nextInt();
		int q=scan.nextInt();
		int sum=0;
		Queue Q=new Queue(n);
		
		for(int i=0;i<n;i++){
			Work temp=new Work(scan.next(),scan.nextInt());
			Q.enqueue(temp,n);
			sum+=temp.time;
		}
		
		solve(Q,n,q,sum);
		
	} main {
		Scanner scan=new Scanner(System.in);
		
		int n=scan.nextInt();
		int q=scan.nextInt();
		int sum=0;
		Queue Q=new Queue(n);
		
		for(int i=0;i<n;i++){
			Work temp=new Work(scan.next(),scan.nextInt());
			Q.enqueue(temp,n);
			sum+=temp.time;
		}
		
		solve(Q,n,q,sum);
		
	} 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 sum=0; sum 0 Queue Q=new Queue(n); Q new Queue(n) for(int i=0;i<n;i++){
			Work temp=new Work(scan.next(),scan.nextInt());
			Q.enqueue(temp,n);
			sum+=temp.time;
		} int i=0; int i=0; i 0 i<n i n i++ i++ i {
			Work temp=new Work(scan.next(),scan.nextInt());
			Q.enqueue(temp,n);
			sum+=temp.time;
		} {
			Work temp=new Work(scan.next(),scan.nextInt());
			Q.enqueue(temp,n);
			sum+=temp.time;
		} Work temp=new Work(scan.next(),scan.nextInt()); temp new Work(scan.next(),scan.nextInt()) Q.enqueue(temp,n) Q.enqueue Q temp n sum+=temp.time sum temp.time temp temp.time solve(Q,n,q,sum) solve Q n q sum String[] args args
import java.util.Scanner;

class Work {
	String name;
	int time;
	
	Work(String n,int t){
		name=n;  time=t;
	}
	
}

class Queue {
	int head;
	int tail;
	Work[] a;
	
	/*コンストラクタ*/
	Queue(int n){
		head=0; tail=-1; a=new Work[n];
	}
	
	void enqueue(Work x,int n){
		tail=(tail+1)%n;
		a[tail]=x;
	}
	
	Work dequeue(int n){
		Work temp=a[head];
		head=(head+1)%n;
		return temp;
	}
	
	void decrease(int t){
		a[head].time-=t;
	}
	
	int getTime(){
		return a[head].time;
	}
	
	String getName(){
		return a[head].name;
	}
	
}

class Main {
	
	static void solve(Queue Q,int n,int q,int sum){
		int time=0;
		Work temp;
		
		while(time != sum){
			if(Q.getTime() == q){
				time+=q;
				System.out.println(Q.getName() + " " + time);
				temp=Q.dequeue(n);
			}
			else if(Q.getTime() < q){
				time+=Q.getTime();
				System.out.println(Q.getName() + " " + time);
				temp=Q.dequeue(n);
			}
			else {
				time+=q;
				Q.decrease(q);
				temp=Q.dequeue(n);
				Q.enqueue(temp,n);
			}
		}
		
		return;
	}
		
	
	
	public static void main(String[] args){
		Scanner scan=new Scanner(System.in);
		
		int n=scan.nextInt();
		int q=scan.nextInt();
		int sum=0;
		Queue Q=new Queue(n);
		
		for(int i=0;i<n;i++){
			Work temp=new Work(scan.next(),scan.nextInt());
			Q.enqueue(temp,n);
			sum+=temp.time;
		}
		
		solve(Q,n,q,sum);
		
	}
}
