

import java.util.Deque;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		
		Deque<Integer> queue = new LinkedList<>();
		Deque<String> name = new LinkedList<>();
		
		int time = 0;
		int n = sc.nextInt();
		int q = sc.nextInt();
		
		for(int i=0;i<n;i++)
		{
			name.add(sc.next());
			queue.add(sc.nextInt());
		}
		
		while(queue.size()>0)
		{
			queue.addLast(queue.poll()-q);//减去
			name.addLast(name.poll());
			time += q; //时间累加
			if(queue.peekLast()<=0)
			{
				//以P2为例
				//P1 150 - 100 50 p1 50 time =100
				//p2 80 -20  -20+200 180
				time += queue.pollLast();
				System.out.println(name.pollLast()+" "+time);
			}
			
		}
		
		

		
	}
}
 import java.util.Deque; Deque java.util import java.util.HashMap; HashMap java.util import java.util.LinkedList; LinkedList java.util import java.util.Queue; Queue java.util import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		
		Deque<Integer> queue = new LinkedList<>();
		Deque<String> name = new LinkedList<>();
		
		int time = 0;
		int n = sc.nextInt();
		int q = sc.nextInt();
		
		for(int i=0;i<n;i++)
		{
			name.add(sc.next());
			queue.add(sc.nextInt());
		}
		
		while(queue.size()>0)
		{
			queue.addLast(queue.poll()-q);//减去
			name.addLast(name.poll());
			time += q; //时间累加
			if(queue.peekLast()<=0)
			{
				//以P2为例
				//P1 150 - 100 50 p1 50 time =100
				//p2 80 -20  -20+200 180
				time += queue.pollLast();
				System.out.println(name.pollLast()+" "+time);
			}
			
		}
		
		

		
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		
		Deque<Integer> queue = new LinkedList<>();
		Deque<String> name = new LinkedList<>();
		
		int time = 0;
		int n = sc.nextInt();
		int q = sc.nextInt();
		
		for(int i=0;i<n;i++)
		{
			name.add(sc.next());
			queue.add(sc.nextInt());
		}
		
		while(queue.size()>0)
		{
			queue.addLast(queue.poll()-q);//减去
			name.addLast(name.poll());
			time += q; //时间累加
			if(queue.peekLast()<=0)
			{
				//以P2为例
				//P1 150 - 100 50 p1 50 time =100
				//p2 80 -20  -20+200 180
				time += queue.pollLast();
				System.out.println(name.pollLast()+" "+time);
			}
			
		}
		
		

		
	} main {
		Scanner sc = new Scanner(System.in);

		
		Deque<Integer> queue = new LinkedList<>();
		Deque<String> name = new LinkedList<>();
		
		int time = 0;
		int n = sc.nextInt();
		int q = sc.nextInt();
		
		for(int i=0;i<n;i++)
		{
			name.add(sc.next());
			queue.add(sc.nextInt());
		}
		
		while(queue.size()>0)
		{
			queue.addLast(queue.poll()-q);//减去
			name.addLast(name.poll());
			time += q; //时间累加
			if(queue.peekLast()<=0)
			{
				//以P2为例
				//P1 150 - 100 50 p1 50 time =100
				//p2 80 -20  -20+200 180
				time += queue.pollLast();
				System.out.println(name.pollLast()+" "+time);
			}
			
		}
		
		

		
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) Deque<Integer> queue = new LinkedList<>(); queue new LinkedList<>() Deque<String> name = new LinkedList<>(); name new LinkedList<>() int time = 0; time 0 int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int q = sc.nextInt(); q sc.nextInt() sc.nextInt sc for(int i=0;i<n;i++)
		{
			name.add(sc.next());
			queue.add(sc.nextInt());
		} int i=0; int i=0; i 0 i<n i n i++ i++ i {
			name.add(sc.next());
			queue.add(sc.nextInt());
		} {
			name.add(sc.next());
			queue.add(sc.nextInt());
		} name.add(sc.next()) name.add name sc.next() sc.next sc queue.add(sc.nextInt()) queue.add queue sc.nextInt() sc.nextInt sc while(queue.size()>0)
		{
			queue.addLast(queue.poll()-q);//减去
			name.addLast(name.poll());
			time += q; //时间累加
			if(queue.peekLast()<=0)
			{
				//以P2为例
				//P1 150 - 100 50 p1 50 time =100
				//p2 80 -20  -20+200 180
				time += queue.pollLast();
				System.out.println(name.pollLast()+" "+time);
			}
			
		} queue.size()>0 queue.size() queue.size queue 0 {
			queue.addLast(queue.poll()-q);//减去
			name.addLast(name.poll());
			time += q; //时间累加
			if(queue.peekLast()<=0)
			{
				//以P2为例
				//P1 150 - 100 50 p1 50 time =100
				//p2 80 -20  -20+200 180
				time += queue.pollLast();
				System.out.println(name.pollLast()+" "+time);
			}
			
		} queue.addLast(queue.poll()-q) queue.addLast queue queue.poll()-q queue.poll() queue.poll queue q name.addLast(name.poll()) name.addLast name name.poll() name.poll name time += q time q if(queue.peekLast()<=0)
			{
				//以P2为例
				//P1 150 - 100 50 p1 50 time =100
				//p2 80 -20  -20+200 180
				time += queue.pollLast();
				System.out.println(name.pollLast()+" "+time);
			} queue.peekLast()<=0 queue.peekLast() queue.peekLast queue 0 {
				//以P2为例
				//P1 150 - 100 50 p1 50 time =100
				//p2 80 -20  -20+200 180
				time += queue.pollLast();
				System.out.println(name.pollLast()+" "+time);
			} time += queue.pollLast() time queue.pollLast() queue.pollLast queue System.out.println(name.pollLast()+" "+time) System.out.println System.out System System.out name.pollLast()+" "+time name.pollLast()+" "+time name.pollLast() name.pollLast name " " time String[] args args public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		
		Deque<Integer> queue = new LinkedList<>();
		Deque<String> name = new LinkedList<>();
		
		int time = 0;
		int n = sc.nextInt();
		int q = sc.nextInt();
		
		for(int i=0;i<n;i++)
		{
			name.add(sc.next());
			queue.add(sc.nextInt());
		}
		
		while(queue.size()>0)
		{
			queue.addLast(queue.poll()-q);//减去
			name.addLast(name.poll());
			time += q; //时间累加
			if(queue.peekLast()<=0)
			{
				//以P2为例
				//P1 150 - 100 50 p1 50 time =100
				//p2 80 -20  -20+200 180
				time += queue.pollLast();
				System.out.println(name.pollLast()+" "+time);
			}
			
		}
		
		

		
	}
} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		
		Deque<Integer> queue = new LinkedList<>();
		Deque<String> name = new LinkedList<>();
		
		int time = 0;
		int n = sc.nextInt();
		int q = sc.nextInt();
		
		for(int i=0;i<n;i++)
		{
			name.add(sc.next());
			queue.add(sc.nextInt());
		}
		
		while(queue.size()>0)
		{
			queue.addLast(queue.poll()-q);//减去
			name.addLast(name.poll());
			time += q; //时间累加
			if(queue.peekLast()<=0)
			{
				//以P2为例
				//P1 150 - 100 50 p1 50 time =100
				//p2 80 -20  -20+200 180
				time += queue.pollLast();
				System.out.println(name.pollLast()+" "+time);
			}
			
		}
		
		

		
	}
} Main


import java.util.Deque;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		
		Deque<Integer> queue = new LinkedList<>();
		Deque<String> name = new LinkedList<>();
		
		int time = 0;
		int n = sc.nextInt();
		int q = sc.nextInt();
		
		for(int i=0;i<n;i++)
		{
			name.add(sc.next());
			queue.add(sc.nextInt());
		}
		
		while(queue.size()>0)
		{
			queue.addLast(queue.poll()-q);//减去
			name.addLast(name.poll());
			time += q; //时间累加
			if(queue.peekLast()<=0)
			{
				//以P2为例
				//P1 150 - 100 50 p1 50 time =100
				//p2 80 -20  -20+200 180
				time += queue.pollLast();
				System.out.println(name.pollLast()+" "+time);
			}
			
		}
		
		

		
	}
}

