import java.util.LinkedList;
import java.util.Scanner;



public class Main{
	public static void main(String[] args)
	{
		Scanner in = new Scanner(System.in);
		LinkedList<String> qName = new LinkedList<>();
		LinkedList<Integer> qTime = new LinkedList<>();
		
		int amount = in.nextInt();
		int quantum = in.nextInt();
		for(int i= 0; i < amount; i++) 
		{
			qName.addLast(in.next());
			qTime.addLast(in.nextInt());
		}

		int time = 0;
		while(qName.size() != 0)
		{
			String cName = qName.removeFirst();
			int cTime = qTime.removeFirst();
			if(cTime > quantum)
			{
				time = time + quantum;
				cTime = cTime - quantum;
				
				qName.addLast(cName);
				qTime.addLast(cTime);
			}else
			{
				time = time + cTime;
				System.out.println(cName + " " + time);
			}
		}
	}

	
} import java.util.LinkedList; LinkedList java.util import java.util.Scanner; Scanner java.util public class Main{
	public static void main(String[] args)
	{
		Scanner in = new Scanner(System.in);
		LinkedList<String> qName = new LinkedList<>();
		LinkedList<Integer> qTime = new LinkedList<>();
		
		int amount = in.nextInt();
		int quantum = in.nextInt();
		for(int i= 0; i < amount; i++) 
		{
			qName.addLast(in.next());
			qTime.addLast(in.nextInt());
		}

		int time = 0;
		while(qName.size() != 0)
		{
			String cName = qName.removeFirst();
			int cTime = qTime.removeFirst();
			if(cTime > quantum)
			{
				time = time + quantum;
				cTime = cTime - quantum;
				
				qName.addLast(cName);
				qTime.addLast(cTime);
			}else
			{
				time = time + cTime;
				System.out.println(cName + " " + time);
			}
		}
	}

	
} Main public static void main(String[] args)
	{
		Scanner in = new Scanner(System.in);
		LinkedList<String> qName = new LinkedList<>();
		LinkedList<Integer> qTime = new LinkedList<>();
		
		int amount = in.nextInt();
		int quantum = in.nextInt();
		for(int i= 0; i < amount; i++) 
		{
			qName.addLast(in.next());
			qTime.addLast(in.nextInt());
		}

		int time = 0;
		while(qName.size() != 0)
		{
			String cName = qName.removeFirst();
			int cTime = qTime.removeFirst();
			if(cTime > quantum)
			{
				time = time + quantum;
				cTime = cTime - quantum;
				
				qName.addLast(cName);
				qTime.addLast(cTime);
			}else
			{
				time = time + cTime;
				System.out.println(cName + " " + time);
			}
		}
	} main {
		Scanner in = new Scanner(System.in);
		LinkedList<String> qName = new LinkedList<>();
		LinkedList<Integer> qTime = new LinkedList<>();
		
		int amount = in.nextInt();
		int quantum = in.nextInt();
		for(int i= 0; i < amount; i++) 
		{
			qName.addLast(in.next());
			qTime.addLast(in.nextInt());
		}

		int time = 0;
		while(qName.size() != 0)
		{
			String cName = qName.removeFirst();
			int cTime = qTime.removeFirst();
			if(cTime > quantum)
			{
				time = time + quantum;
				cTime = cTime - quantum;
				
				qName.addLast(cName);
				qTime.addLast(cTime);
			}else
			{
				time = time + cTime;
				System.out.println(cName + " " + time);
			}
		}
	} Scanner in = new Scanner(System.in); in new Scanner(System.in) LinkedList<String> qName = new LinkedList<>(); qName new LinkedList<>() LinkedList<Integer> qTime = new LinkedList<>(); qTime new LinkedList<>() int amount = in.nextInt(); amount in.nextInt() in.nextInt in int quantum = in.nextInt(); quantum in.nextInt() in.nextInt in for(int i= 0; i < amount; i++) 
		{
			qName.addLast(in.next());
			qTime.addLast(in.nextInt());
		} int i= 0; int i= 0; i 0 i < amount i amount i++ i++ i {
			qName.addLast(in.next());
			qTime.addLast(in.nextInt());
		} {
			qName.addLast(in.next());
			qTime.addLast(in.nextInt());
		} qName.addLast(in.next()) qName.addLast qName in.next() in.next in qTime.addLast(in.nextInt()) qTime.addLast qTime in.nextInt() in.nextInt in int time = 0; time 0 while(qName.size() != 0)
		{
			String cName = qName.removeFirst();
			int cTime = qTime.removeFirst();
			if(cTime > quantum)
			{
				time = time + quantum;
				cTime = cTime - quantum;
				
				qName.addLast(cName);
				qTime.addLast(cTime);
			}else
			{
				time = time + cTime;
				System.out.println(cName + " " + time);
			}
		} qName.size() != 0 qName.size() qName.size qName 0 {
			String cName = qName.removeFirst();
			int cTime = qTime.removeFirst();
			if(cTime > quantum)
			{
				time = time + quantum;
				cTime = cTime - quantum;
				
				qName.addLast(cName);
				qTime.addLast(cTime);
			}else
			{
				time = time + cTime;
				System.out.println(cName + " " + time);
			}
		} String cName = qName.removeFirst(); cName qName.removeFirst() qName.removeFirst qName int cTime = qTime.removeFirst(); cTime qTime.removeFirst() qTime.removeFirst qTime if(cTime > quantum)
			{
				time = time + quantum;
				cTime = cTime - quantum;
				
				qName.addLast(cName);
				qTime.addLast(cTime);
			}else
			{
				time = time + cTime;
				System.out.println(cName + " " + time);
			} cTime > quantum cTime quantum {
				time = time + quantum;
				cTime = cTime - quantum;
				
				qName.addLast(cName);
				qTime.addLast(cTime);
			} time = time + quantum time time + quantum time quantum cTime = cTime - quantum cTime cTime - quantum cTime quantum qName.addLast(cName) qName.addLast qName cName qTime.addLast(cTime) qTime.addLast qTime cTime {
				time = time + cTime;
				System.out.println(cName + " " + time);
			} time = time + cTime time time + cTime time cTime System.out.println(cName + " " + time) System.out.println System.out System System.out cName + " " + time cName + " " + time cName " " time String[] args args public class Main{
	public static void main(String[] args)
	{
		Scanner in = new Scanner(System.in);
		LinkedList<String> qName = new LinkedList<>();
		LinkedList<Integer> qTime = new LinkedList<>();
		
		int amount = in.nextInt();
		int quantum = in.nextInt();
		for(int i= 0; i < amount; i++) 
		{
			qName.addLast(in.next());
			qTime.addLast(in.nextInt());
		}

		int time = 0;
		while(qName.size() != 0)
		{
			String cName = qName.removeFirst();
			int cTime = qTime.removeFirst();
			if(cTime > quantum)
			{
				time = time + quantum;
				cTime = cTime - quantum;
				
				qName.addLast(cName);
				qTime.addLast(cTime);
			}else
			{
				time = time + cTime;
				System.out.println(cName + " " + time);
			}
		}
	}

	
} public class Main{
	public static void main(String[] args)
	{
		Scanner in = new Scanner(System.in);
		LinkedList<String> qName = new LinkedList<>();
		LinkedList<Integer> qTime = new LinkedList<>();
		
		int amount = in.nextInt();
		int quantum = in.nextInt();
		for(int i= 0; i < amount; i++) 
		{
			qName.addLast(in.next());
			qTime.addLast(in.nextInt());
		}

		int time = 0;
		while(qName.size() != 0)
		{
			String cName = qName.removeFirst();
			int cTime = qTime.removeFirst();
			if(cTime > quantum)
			{
				time = time + quantum;
				cTime = cTime - quantum;
				
				qName.addLast(cName);
				qTime.addLast(cTime);
			}else
			{
				time = time + cTime;
				System.out.println(cName + " " + time);
			}
		}
	}

	
} Main
import java.util.LinkedList;
import java.util.Scanner;



public class Main{
	public static void main(String[] args)
	{
		Scanner in = new Scanner(System.in);
		LinkedList<String> qName = new LinkedList<>();
		LinkedList<Integer> qTime = new LinkedList<>();
		
		int amount = in.nextInt();
		int quantum = in.nextInt();
		for(int i= 0; i < amount; i++) 
		{
			qName.addLast(in.next());
			qTime.addLast(in.nextInt());
		}

		int time = 0;
		while(qName.size() != 0)
		{
			String cName = qName.removeFirst();
			int cTime = qTime.removeFirst();
			if(cTime > quantum)
			{
				time = time + quantum;
				cTime = cTime - quantum;
				
				qName.addLast(cName);
				qTime.addLast(cTime);
			}else
			{
				time = time + cTime;
				System.out.println(cName + " " + time);
			}
		}
	}

	
}
