import java.util.*;

public class Main 
{
	final static int MAX=100005;
	static Pp[] object=new Pp[MAX];
	static int head,tail;
	public static void main(String[]args)
	{
		
		Scanner scanner=new Scanner(System.in);
		int sum=0,c;
		int q,n;
		Pp u;
		n=scanner.nextInt();
		q=scanner.nextInt();

		for(int i=1;i<=n;i++ )
		{
			object[i]=new Main().new Pp();
			object[i].name=scanner.next();
			object[i].t=scanner.nextInt();
		}
		
		head=1;tail=n+1;
		while(head!=tail)
		{
			u=dequeue();
			c=min(q,u.t);
			u.t-=c;
			sum+=c;
			if(u.t>0)
			{
				enqueue(u);
			}else {
				System.out.println(u.name+" "+sum);
			}
		}
		
		
		
		
	}
	
	static void enqueue(Pp x)
	{
		object[tail]=x;
		tail=(tail+1)%MAX;
		
	}
	
	static Pp dequeue()
	{
		Pp x=object[head];
		head=(head+1)%MAX;
		return x;
	}
	
	static int min(int a,int b)
	{
		return a<b?a:b;
	}
	
	public  class Pp
	{
		 String name;
		 int t;		
	}
	




} import java.util.*; util.* java public class Main 
{
	final static int MAX=100005;
	static Pp[] object=new Pp[MAX];
	static int head,tail;
	public static void main(String[]args)
	{
		
		Scanner scanner=new Scanner(System.in);
		int sum=0,c;
		int q,n;
		Pp u;
		n=scanner.nextInt();
		q=scanner.nextInt();

		for(int i=1;i<=n;i++ )
		{
			object[i]=new Main().new Pp();
			object[i].name=scanner.next();
			object[i].t=scanner.nextInt();
		}
		
		head=1;tail=n+1;
		while(head!=tail)
		{
			u=dequeue();
			c=min(q,u.t);
			u.t-=c;
			sum+=c;
			if(u.t>0)
			{
				enqueue(u);
			}else {
				System.out.println(u.name+" "+sum);
			}
		}
		
		
		
		
	}
	
	static void enqueue(Pp x)
	{
		object[tail]=x;
		tail=(tail+1)%MAX;
		
	}
	
	static Pp dequeue()
	{
		Pp x=object[head];
		head=(head+1)%MAX;
		return x;
	}
	
	static int min(int a,int b)
	{
		return a<b?a:b;
	}
	
	public  class Pp
	{
		 String name;
		 int t;		
	}
	




} Main final static int MAX=100005; MAX 100005 static Pp[] object=new Pp[MAX]; object new Pp[MAX] MAX static int head head tail; tail public static void main(String[]args)
	{
		
		Scanner scanner=new Scanner(System.in);
		int sum=0,c;
		int q,n;
		Pp u;
		n=scanner.nextInt();
		q=scanner.nextInt();

		for(int i=1;i<=n;i++ )
		{
			object[i]=new Main().new Pp();
			object[i].name=scanner.next();
			object[i].t=scanner.nextInt();
		}
		
		head=1;tail=n+1;
		while(head!=tail)
		{
			u=dequeue();
			c=min(q,u.t);
			u.t-=c;
			sum+=c;
			if(u.t>0)
			{
				enqueue(u);
			}else {
				System.out.println(u.name+" "+sum);
			}
		}
		
		
		
		
	} main {
		
		Scanner scanner=new Scanner(System.in);
		int sum=0,c;
		int q,n;
		Pp u;
		n=scanner.nextInt();
		q=scanner.nextInt();

		for(int i=1;i<=n;i++ )
		{
			object[i]=new Main().new Pp();
			object[i].name=scanner.next();
			object[i].t=scanner.nextInt();
		}
		
		head=1;tail=n+1;
		while(head!=tail)
		{
			u=dequeue();
			c=min(q,u.t);
			u.t-=c;
			sum+=c;
			if(u.t>0)
			{
				enqueue(u);
			}else {
				System.out.println(u.name+" "+sum);
			}
		}
		
		
		
		
	} Scanner scanner=new Scanner(System.in); scanner new Scanner(System.in) int sum=0 sum 0 c; c int q q n; n Pp u; u n=scanner.nextInt() n scanner.nextInt() scanner.nextInt scanner q=scanner.nextInt() q scanner.nextInt() scanner.nextInt scanner for(int i=1;i<=n;i++ )
		{
			object[i]=new Main().new Pp();
			object[i].name=scanner.next();
			object[i].t=scanner.nextInt();
		} int i=1; int i=1; i 1 i<=n i n i++ i++ i {
			object[i]=new Main().new Pp();
			object[i].name=scanner.next();
			object[i].t=scanner.nextInt();
		} {
			object[i]=new Main().new Pp();
			object[i].name=scanner.next();
			object[i].t=scanner.nextInt();
		} object[i]=new Main().new Pp() object[i] object i new Main().new Pp() new Main() new Main() object[i].name=scanner.next() object[i].name object[i] object i object[i].name scanner.next() scanner.next scanner object[i].t=scanner.nextInt() object[i].t object[i] object i object[i].t scanner.nextInt() scanner.nextInt scanner head=1 head 1 tail=n+1 tail n+1 n 1 while(head!=tail)
		{
			u=dequeue();
			c=min(q,u.t);
			u.t-=c;
			sum+=c;
			if(u.t>0)
			{
				enqueue(u);
			}else {
				System.out.println(u.name+" "+sum);
			}
		} head!=tail head tail {
			u=dequeue();
			c=min(q,u.t);
			u.t-=c;
			sum+=c;
			if(u.t>0)
			{
				enqueue(u);
			}else {
				System.out.println(u.name+" "+sum);
			}
		} u=dequeue() u dequeue() dequeue c=min(q,u.t) c min(q,u.t) min q u.t u u.t u.t-=c u.t u u.t c sum+=c sum c if(u.t>0)
			{
				enqueue(u);
			}else {
				System.out.println(u.name+" "+sum);
			} u.t>0 u.t u u.t 0 {
				enqueue(u);
			} enqueue(u) enqueue u {
				System.out.println(u.name+" "+sum);
			} System.out.println(u.name+" "+sum) System.out.println System.out System System.out u.name+" "+sum u.name+" "+sum u.name u u.name " " sum String[]args args static void enqueue(Pp x)
	{
		object[tail]=x;
		tail=(tail+1)%MAX;
		
	} enqueue {
		object[tail]=x;
		tail=(tail+1)%MAX;
		
	} object[tail]=x object[tail] object tail x tail=(tail+1)%MAX tail (tail+1)%MAX (tail+1) tail 1 MAX Pp x x static Pp dequeue()
	{
		Pp x=object[head];
		head=(head+1)%MAX;
		return x;
	} dequeue {
		Pp x=object[head];
		head=(head+1)%MAX;
		return x;
	} Pp x=object[head]; x object[head] object head head=(head+1)%MAX head (head+1)%MAX (head+1) head 1 MAX return x; x static int min(int a,int b)
	{
		return a<b?a:b;
	} min {
		return a<b?a:b;
	} return a<b?a:b; a<b?a:b a<b a b a b int a a int b b public  class Pp
	{
		 String name;
		 int t;		
	} Pp String name; name int t; t public class Main 
{
	final static int MAX=100005;
	static Pp[] object=new Pp[MAX];
	static int head,tail;
	public static void main(String[]args)
	{
		
		Scanner scanner=new Scanner(System.in);
		int sum=0,c;
		int q,n;
		Pp u;
		n=scanner.nextInt();
		q=scanner.nextInt();

		for(int i=1;i<=n;i++ )
		{
			object[i]=new Main().new Pp();
			object[i].name=scanner.next();
			object[i].t=scanner.nextInt();
		}
		
		head=1;tail=n+1;
		while(head!=tail)
		{
			u=dequeue();
			c=min(q,u.t);
			u.t-=c;
			sum+=c;
			if(u.t>0)
			{
				enqueue(u);
			}else {
				System.out.println(u.name+" "+sum);
			}
		}
		
		
		
		
	}
	
	static void enqueue(Pp x)
	{
		object[tail]=x;
		tail=(tail+1)%MAX;
		
	}
	
	static Pp dequeue()
	{
		Pp x=object[head];
		head=(head+1)%MAX;
		return x;
	}
	
	static int min(int a,int b)
	{
		return a<b?a:b;
	}
	
	public  class Pp
	{
		 String name;
		 int t;		
	}
	




} public class Main 
{
	final static int MAX=100005;
	static Pp[] object=new Pp[MAX];
	static int head,tail;
	public static void main(String[]args)
	{
		
		Scanner scanner=new Scanner(System.in);
		int sum=0,c;
		int q,n;
		Pp u;
		n=scanner.nextInt();
		q=scanner.nextInt();

		for(int i=1;i<=n;i++ )
		{
			object[i]=new Main().new Pp();
			object[i].name=scanner.next();
			object[i].t=scanner.nextInt();
		}
		
		head=1;tail=n+1;
		while(head!=tail)
		{
			u=dequeue();
			c=min(q,u.t);
			u.t-=c;
			sum+=c;
			if(u.t>0)
			{
				enqueue(u);
			}else {
				System.out.println(u.name+" "+sum);
			}
		}
		
		
		
		
	}
	
	static void enqueue(Pp x)
	{
		object[tail]=x;
		tail=(tail+1)%MAX;
		
	}
	
	static Pp dequeue()
	{
		Pp x=object[head];
		head=(head+1)%MAX;
		return x;
	}
	
	static int min(int a,int b)
	{
		return a<b?a:b;
	}
	
	public  class Pp
	{
		 String name;
		 int t;		
	}
	




} Main
import java.util.*;

public class Main 
{
	final static int MAX=100005;
	static Pp[] object=new Pp[MAX];
	static int head,tail;
	public static void main(String[]args)
	{
		
		Scanner scanner=new Scanner(System.in);
		int sum=0,c;
		int q,n;
		Pp u;
		n=scanner.nextInt();
		q=scanner.nextInt();

		for(int i=1;i<=n;i++ )
		{
			object[i]=new Main().new Pp();
			object[i].name=scanner.next();
			object[i].t=scanner.nextInt();
		}
		
		head=1;tail=n+1;
		while(head!=tail)
		{
			u=dequeue();
			c=min(q,u.t);
			u.t-=c;
			sum+=c;
			if(u.t>0)
			{
				enqueue(u);
			}else {
				System.out.println(u.name+" "+sum);
			}
		}
		
		
		
		
	}
	
	static void enqueue(Pp x)
	{
		object[tail]=x;
		tail=(tail+1)%MAX;
		
	}
	
	static Pp dequeue()
	{
		Pp x=object[head];
		head=(head+1)%MAX;
		return x;
	}
	
	static int min(int a,int b)
	{
		return a<b?a:b;
	}
	
	public  class Pp
	{
		 String name;
		 int t;		
	}
	




}