import java.util.*;

public class Main{
	public static void main(String args[]) {
		Queue<String> p = new LinkedList<>();
		Queue<Integer> values = new LinkedList<>();
	
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int q = in.nextInt();		
		
		int time = 0;
		
		in.nextLine();
		while(n > 0) {
			p.add(in.next());
			values.add(in.nextInt());
			n--;
			
			
		}
		
		while (!p.isEmpty()) {
			String pr = p.poll();
			Integer ti = values.poll();
			
			if (ti <= q)
			{
				time += ti;
				System.out.println(pr + " " + time);
			}
			else
			{
				ti = ti - q;
				p.add(pr);
				values.add(ti);
				time += q;
			}
		}
	
		
		
	
	
	}
	

} import java.util.*; util.* java public class Main{
	public static void main(String args[]) {
		Queue<String> p = new LinkedList<>();
		Queue<Integer> values = new LinkedList<>();
	
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int q = in.nextInt();		
		
		int time = 0;
		
		in.nextLine();
		while(n > 0) {
			p.add(in.next());
			values.add(in.nextInt());
			n--;
			
			
		}
		
		while (!p.isEmpty()) {
			String pr = p.poll();
			Integer ti = values.poll();
			
			if (ti <= q)
			{
				time += ti;
				System.out.println(pr + " " + time);
			}
			else
			{
				ti = ti - q;
				p.add(pr);
				values.add(ti);
				time += q;
			}
		}
	
		
		
	
	
	}
	

} Main public static void main(String args[]) {
		Queue<String> p = new LinkedList<>();
		Queue<Integer> values = new LinkedList<>();
	
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int q = in.nextInt();		
		
		int time = 0;
		
		in.nextLine();
		while(n > 0) {
			p.add(in.next());
			values.add(in.nextInt());
			n--;
			
			
		}
		
		while (!p.isEmpty()) {
			String pr = p.poll();
			Integer ti = values.poll();
			
			if (ti <= q)
			{
				time += ti;
				System.out.println(pr + " " + time);
			}
			else
			{
				ti = ti - q;
				p.add(pr);
				values.add(ti);
				time += q;
			}
		}
	
		
		
	
	
	} main {
		Queue<String> p = new LinkedList<>();
		Queue<Integer> values = new LinkedList<>();
	
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int q = in.nextInt();		
		
		int time = 0;
		
		in.nextLine();
		while(n > 0) {
			p.add(in.next());
			values.add(in.nextInt());
			n--;
			
			
		}
		
		while (!p.isEmpty()) {
			String pr = p.poll();
			Integer ti = values.poll();
			
			if (ti <= q)
			{
				time += ti;
				System.out.println(pr + " " + time);
			}
			else
			{
				ti = ti - q;
				p.add(pr);
				values.add(ti);
				time += q;
			}
		}
	
		
		
	
	
	} Queue<String> p = new LinkedList<>(); p new LinkedList<>() Queue<Integer> values = new LinkedList<>(); values new LinkedList<>() Scanner in = new Scanner(System.in); in new Scanner(System.in) int n = in.nextInt(); n in.nextInt() in.nextInt in int q = in.nextInt(); q in.nextInt() in.nextInt in int time = 0; time 0 in.nextLine() in.nextLine in while(n > 0) {
			p.add(in.next());
			values.add(in.nextInt());
			n--;
			
			
		} n > 0 n 0 {
			p.add(in.next());
			values.add(in.nextInt());
			n--;
			
			
		} p.add(in.next()) p.add p in.next() in.next in values.add(in.nextInt()) values.add values in.nextInt() in.nextInt in n-- n while (!p.isEmpty()) {
			String pr = p.poll();
			Integer ti = values.poll();
			
			if (ti <= q)
			{
				time += ti;
				System.out.println(pr + " " + time);
			}
			else
			{
				ti = ti - q;
				p.add(pr);
				values.add(ti);
				time += q;
			}
		} !p.isEmpty() p.isEmpty() p.isEmpty p {
			String pr = p.poll();
			Integer ti = values.poll();
			
			if (ti <= q)
			{
				time += ti;
				System.out.println(pr + " " + time);
			}
			else
			{
				ti = ti - q;
				p.add(pr);
				values.add(ti);
				time += q;
			}
		} String pr = p.poll(); pr p.poll() p.poll p Integer ti = values.poll(); ti values.poll() values.poll values if (ti <= q)
			{
				time += ti;
				System.out.println(pr + " " + time);
			}
			else
			{
				ti = ti - q;
				p.add(pr);
				values.add(ti);
				time += q;
			} ti <= q ti q {
				time += ti;
				System.out.println(pr + " " + time);
			} time += ti time ti System.out.println(pr + " " + time) System.out.println System.out System System.out pr + " " + time pr + " " + time pr " " time {
				ti = ti - q;
				p.add(pr);
				values.add(ti);
				time += q;
			} ti = ti - q ti ti - q ti q p.add(pr) p.add p pr values.add(ti) values.add values ti time += q time q String args[] args public class Main{
	public static void main(String args[]) {
		Queue<String> p = new LinkedList<>();
		Queue<Integer> values = new LinkedList<>();
	
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int q = in.nextInt();		
		
		int time = 0;
		
		in.nextLine();
		while(n > 0) {
			p.add(in.next());
			values.add(in.nextInt());
			n--;
			
			
		}
		
		while (!p.isEmpty()) {
			String pr = p.poll();
			Integer ti = values.poll();
			
			if (ti <= q)
			{
				time += ti;
				System.out.println(pr + " " + time);
			}
			else
			{
				ti = ti - q;
				p.add(pr);
				values.add(ti);
				time += q;
			}
		}
	
		
		
	
	
	}
	

} public class Main{
	public static void main(String args[]) {
		Queue<String> p = new LinkedList<>();
		Queue<Integer> values = new LinkedList<>();
	
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int q = in.nextInt();		
		
		int time = 0;
		
		in.nextLine();
		while(n > 0) {
			p.add(in.next());
			values.add(in.nextInt());
			n--;
			
			
		}
		
		while (!p.isEmpty()) {
			String pr = p.poll();
			Integer ti = values.poll();
			
			if (ti <= q)
			{
				time += ti;
				System.out.println(pr + " " + time);
			}
			else
			{
				ti = ti - q;
				p.add(pr);
				values.add(ti);
				time += q;
			}
		}
	
		
		
	
	
	}
	

} Main
import java.util.*;

public class Main{
	public static void main(String args[]) {
		Queue<String> p = new LinkedList<>();
		Queue<Integer> values = new LinkedList<>();
	
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int q = in.nextInt();		
		
		int time = 0;
		
		in.nextLine();
		while(n > 0) {
			p.add(in.next());
			values.add(in.nextInt());
			n--;
			
			
		}
		
		while (!p.isEmpty()) {
			String pr = p.poll();
			Integer ti = values.poll();
			
			if (ti <= q)
			{
				time += ti;
				System.out.println(pr + " " + time);
			}
			else
			{
				ti = ti - q;
				p.add(pr);
				values.add(ti);
				time += q;
			}
		}
	
		
		
	
	
	}
	

}
