import java.util.*;
public class Main
{
	public static class process
	{
		String name;
		int time;
		public process(String n, int t)
		{
			name=n;
			time=t;
		}
		public String getName()
		{
			return this.name;
		}
		
		public int getTime()
		{
			return this.time;
		}
		
		public void run(int t)
		{
			if(this.time-t<0)
			{
				this.time=0;
			}
			else
			{
				this.time = this.time - t;
			}
		}
	}
	
	public static void main(String[] args)
	{
		Queue<process> q = new LinkedList<process>();
		Scanner in = new Scanner(System.in);
		int procs = in.nextInt();
		int lot = in.nextInt();
		for(int c = 0; c < procs ; c++)
		{
			q.add(new process(in.next(),in.nextInt()));
		}
		in.close();
		
		//start of algorithm
		int runTime = 0;
		while(!q.isEmpty())
		{
			process p = q.poll();
			int remainingPTime = p.getTime();
			p.run(lot);
			if(p.time == 0)
			{
				runTime+= remainingPTime;
				System.out.println(p.getName()+" "+runTime);
			}
			else 
			{
				runTime+=lot;
				q.add(p);
			}
		}
	}
} import java.util.*; util.* java public class Main
{
	public static class process
	{
		String name;
		int time;
		public process(String n, int t)
		{
			name=n;
			time=t;
		}
		public String getName()
		{
			return this.name;
		}
		
		public int getTime()
		{
			return this.time;
		}
		
		public void run(int t)
		{
			if(this.time-t<0)
			{
				this.time=0;
			}
			else
			{
				this.time = this.time - t;
			}
		}
	}
	
	public static void main(String[] args)
	{
		Queue<process> q = new LinkedList<process>();
		Scanner in = new Scanner(System.in);
		int procs = in.nextInt();
		int lot = in.nextInt();
		for(int c = 0; c < procs ; c++)
		{
			q.add(new process(in.next(),in.nextInt()));
		}
		in.close();
		
		//start of algorithm
		int runTime = 0;
		while(!q.isEmpty())
		{
			process p = q.poll();
			int remainingPTime = p.getTime();
			p.run(lot);
			if(p.time == 0)
			{
				runTime+= remainingPTime;
				System.out.println(p.getName()+" "+runTime);
			}
			else 
			{
				runTime+=lot;
				q.add(p);
			}
		}
	}
} Main public static void main(String[] args)
	{
		Queue<process> q = new LinkedList<process>();
		Scanner in = new Scanner(System.in);
		int procs = in.nextInt();
		int lot = in.nextInt();
		for(int c = 0; c < procs ; c++)
		{
			q.add(new process(in.next(),in.nextInt()));
		}
		in.close();
		
		//start of algorithm
		int runTime = 0;
		while(!q.isEmpty())
		{
			process p = q.poll();
			int remainingPTime = p.getTime();
			p.run(lot);
			if(p.time == 0)
			{
				runTime+= remainingPTime;
				System.out.println(p.getName()+" "+runTime);
			}
			else 
			{
				runTime+=lot;
				q.add(p);
			}
		}
	} main {
		Queue<process> q = new LinkedList<process>();
		Scanner in = new Scanner(System.in);
		int procs = in.nextInt();
		int lot = in.nextInt();
		for(int c = 0; c < procs ; c++)
		{
			q.add(new process(in.next(),in.nextInt()));
		}
		in.close();
		
		//start of algorithm
		int runTime = 0;
		while(!q.isEmpty())
		{
			process p = q.poll();
			int remainingPTime = p.getTime();
			p.run(lot);
			if(p.time == 0)
			{
				runTime+= remainingPTime;
				System.out.println(p.getName()+" "+runTime);
			}
			else 
			{
				runTime+=lot;
				q.add(p);
			}
		}
	} Queue<process> q = new LinkedList<process>(); q new LinkedList<process>() Scanner in = new Scanner(System.in); in new Scanner(System.in) int procs = in.nextInt(); procs in.nextInt() in.nextInt in int lot = in.nextInt(); lot in.nextInt() in.nextInt in for(int c = 0; c < procs ; c++)
		{
			q.add(new process(in.next(),in.nextInt()));
		} int c = 0; int c = 0; c 0 c < procs c procs c++ c++ c {
			q.add(new process(in.next(),in.nextInt()));
		} {
			q.add(new process(in.next(),in.nextInt()));
		} q.add(new process(in.next(),in.nextInt())) q.add q new process(in.next(),in.nextInt()) in.close() in.close in int runTime = 0; runTime 0 while(!q.isEmpty())
		{
			process p = q.poll();
			int remainingPTime = p.getTime();
			p.run(lot);
			if(p.time == 0)
			{
				runTime+= remainingPTime;
				System.out.println(p.getName()+" "+runTime);
			}
			else 
			{
				runTime+=lot;
				q.add(p);
			}
		} !q.isEmpty() q.isEmpty() q.isEmpty q {
			process p = q.poll();
			int remainingPTime = p.getTime();
			p.run(lot);
			if(p.time == 0)
			{
				runTime+= remainingPTime;
				System.out.println(p.getName()+" "+runTime);
			}
			else 
			{
				runTime+=lot;
				q.add(p);
			}
		} process p = q.poll(); p q.poll() q.poll q int remainingPTime = p.getTime(); remainingPTime p.getTime() p.getTime p p.run(lot) p.run p lot if(p.time == 0)
			{
				runTime+= remainingPTime;
				System.out.println(p.getName()+" "+runTime);
			}
			else 
			{
				runTime+=lot;
				q.add(p);
			} p.time == 0 p.time p p.time 0 {
				runTime+= remainingPTime;
				System.out.println(p.getName()+" "+runTime);
			} runTime+= remainingPTime runTime remainingPTime System.out.println(p.getName()+" "+runTime) System.out.println System.out System System.out p.getName()+" "+runTime p.getName()+" "+runTime p.getName() p.getName p " " runTime {
				runTime+=lot;
				q.add(p);
			} runTime+=lot runTime lot q.add(p) q.add q p String[] args args public static class process
	{
		String name;
		int time;
		public process(String n, int t)
		{
			name=n;
			time=t;
		}
		public String getName()
		{
			return this.name;
		}
		
		public int getTime()
		{
			return this.time;
		}
		
		public void run(int t)
		{
			if(this.time-t<0)
			{
				this.time=0;
			}
			else
			{
				this.time = this.time - t;
			}
		}
	} process String name; name int time; time public process(String n, int t)
		{
			name=n;
			time=t;
		} process {
			name=n;
			time=t;
		} name=n name n time=t time t String n n int t t public String getName()
		{
			return this.name;
		} getName {
			return this.name;
		} return this.name; this.name this this.name public int getTime()
		{
			return this.time;
		} getTime {
			return this.time;
		} return this.time; this.time this this.time public void run(int t)
		{
			if(this.time-t<0)
			{
				this.time=0;
			}
			else
			{
				this.time = this.time - t;
			}
		} run {
			if(this.time-t<0)
			{
				this.time=0;
			}
			else
			{
				this.time = this.time - t;
			}
		} if(this.time-t<0)
			{
				this.time=0;
			}
			else
			{
				this.time = this.time - t;
			} this.time-t<0 this.time-t this.time this this.time t 0 {
				this.time=0;
			} this.time=0 this.time this this.time 0 {
				this.time = this.time - t;
			} this.time = this.time - t this.time this this.time this.time - t this.time this this.time t int t t public class Main
{
	public static class process
	{
		String name;
		int time;
		public process(String n, int t)
		{
			name=n;
			time=t;
		}
		public String getName()
		{
			return this.name;
		}
		
		public int getTime()
		{
			return this.time;
		}
		
		public void run(int t)
		{
			if(this.time-t<0)
			{
				this.time=0;
			}
			else
			{
				this.time = this.time - t;
			}
		}
	}
	
	public static void main(String[] args)
	{
		Queue<process> q = new LinkedList<process>();
		Scanner in = new Scanner(System.in);
		int procs = in.nextInt();
		int lot = in.nextInt();
		for(int c = 0; c < procs ; c++)
		{
			q.add(new process(in.next(),in.nextInt()));
		}
		in.close();
		
		//start of algorithm
		int runTime = 0;
		while(!q.isEmpty())
		{
			process p = q.poll();
			int remainingPTime = p.getTime();
			p.run(lot);
			if(p.time == 0)
			{
				runTime+= remainingPTime;
				System.out.println(p.getName()+" "+runTime);
			}
			else 
			{
				runTime+=lot;
				q.add(p);
			}
		}
	}
} public class Main
{
	public static class process
	{
		String name;
		int time;
		public process(String n, int t)
		{
			name=n;
			time=t;
		}
		public String getName()
		{
			return this.name;
		}
		
		public int getTime()
		{
			return this.time;
		}
		
		public void run(int t)
		{
			if(this.time-t<0)
			{
				this.time=0;
			}
			else
			{
				this.time = this.time - t;
			}
		}
	}
	
	public static void main(String[] args)
	{
		Queue<process> q = new LinkedList<process>();
		Scanner in = new Scanner(System.in);
		int procs = in.nextInt();
		int lot = in.nextInt();
		for(int c = 0; c < procs ; c++)
		{
			q.add(new process(in.next(),in.nextInt()));
		}
		in.close();
		
		//start of algorithm
		int runTime = 0;
		while(!q.isEmpty())
		{
			process p = q.poll();
			int remainingPTime = p.getTime();
			p.run(lot);
			if(p.time == 0)
			{
				runTime+= remainingPTime;
				System.out.println(p.getName()+" "+runTime);
			}
			else 
			{
				runTime+=lot;
				q.add(p);
			}
		}
	}
} Main
import java.util.*;
public class Main
{
	public static class process
	{
		String name;
		int time;
		public process(String n, int t)
		{
			name=n;
			time=t;
		}
		public String getName()
		{
			return this.name;
		}
		
		public int getTime()
		{
			return this.time;
		}
		
		public void run(int t)
		{
			if(this.time-t<0)
			{
				this.time=0;
			}
			else
			{
				this.time = this.time - t;
			}
		}
	}
	
	public static void main(String[] args)
	{
		Queue<process> q = new LinkedList<process>();
		Scanner in = new Scanner(System.in);
		int procs = in.nextInt();
		int lot = in.nextInt();
		for(int c = 0; c < procs ; c++)
		{
			q.add(new process(in.next(),in.nextInt()));
		}
		in.close();
		
		//start of algorithm
		int runTime = 0;
		while(!q.isEmpty())
		{
			process p = q.poll();
			int remainingPTime = p.getTime();
			p.run(lot);
			if(p.time == 0)
			{
				runTime+= remainingPTime;
				System.out.println(p.getName()+" "+runTime);
			}
			else 
			{
				runTime+=lot;
				q.add(p);
			}
		}
	}
}
