import java.io.*;
import java.util.*;

public class Main
{
	static StringBuilder sb = new StringBuilder();
	public static void main(String[] args)throws IOException
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		//Scanner sc = new Scanner(System.in);
		Deque<String> nameQue = new ArrayDeque<>();
		Deque<Integer> workQue = new ArrayDeque<>();
		String[] rem  = br.readLine().split(" "); 
		int n = Integer.parseInt(rem[0]);//Integer.parseInt(sc.next());
		int time = Integer.parseInt(rem[1]); //Integer.parseInt(sc.next());
		//int[][] data = new int[n][2];
		//String[] stemp ;
		for(int i= 0 ; i< n ; i++){
			rem = br.readLine().split(" "); 
			nameQue.offer(rem[0]);
			workQue.offer(Integer.parseInt(rem[1]));
		}
		roundSche(nameQue,workQue,time);
	}
	public static void roundSche(Deque<String> nameQ , Deque<Integer> workQ , int time)
	{
		int pos , prog = 0;
		int temp ;
		while(workQ.size() != 0)
		{
			temp =  workQ.poll();
			if(temp <= time){
				prog += temp;
				sb.append(nameQ.poll()).append(' ').append(prog).append('\n');
			}
			else 
			{
				workQ.offer(temp - time);
				nameQ.offer(nameQ.poll());
				prog += time;
			}
		}
		System.out.print(sb);
		
	}
	
} import java.io.*; io.* java import java.util.*; util.* java public class Main
{
	static StringBuilder sb = new StringBuilder();
	public static void main(String[] args)throws IOException
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		//Scanner sc = new Scanner(System.in);
		Deque<String> nameQue = new ArrayDeque<>();
		Deque<Integer> workQue = new ArrayDeque<>();
		String[] rem  = br.readLine().split(" "); 
		int n = Integer.parseInt(rem[0]);//Integer.parseInt(sc.next());
		int time = Integer.parseInt(rem[1]); //Integer.parseInt(sc.next());
		//int[][] data = new int[n][2];
		//String[] stemp ;
		for(int i= 0 ; i< n ; i++){
			rem = br.readLine().split(" "); 
			nameQue.offer(rem[0]);
			workQue.offer(Integer.parseInt(rem[1]));
		}
		roundSche(nameQue,workQue,time);
	}
	public static void roundSche(Deque<String> nameQ , Deque<Integer> workQ , int time)
	{
		int pos , prog = 0;
		int temp ;
		while(workQ.size() != 0)
		{
			temp =  workQ.poll();
			if(temp <= time){
				prog += temp;
				sb.append(nameQ.poll()).append(' ').append(prog).append('\n');
			}
			else 
			{
				workQ.offer(temp - time);
				nameQ.offer(nameQ.poll());
				prog += time;
			}
		}
		System.out.print(sb);
		
	}
	
} Main static StringBuilder sb = new StringBuilder(); sb new StringBuilder() public static void main(String[] args)throws IOException
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		//Scanner sc = new Scanner(System.in);
		Deque<String> nameQue = new ArrayDeque<>();
		Deque<Integer> workQue = new ArrayDeque<>();
		String[] rem  = br.readLine().split(" "); 
		int n = Integer.parseInt(rem[0]);//Integer.parseInt(sc.next());
		int time = Integer.parseInt(rem[1]); //Integer.parseInt(sc.next());
		//int[][] data = new int[n][2];
		//String[] stemp ;
		for(int i= 0 ; i< n ; i++){
			rem = br.readLine().split(" "); 
			nameQue.offer(rem[0]);
			workQue.offer(Integer.parseInt(rem[1]));
		}
		roundSche(nameQue,workQue,time);
	} main {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		//Scanner sc = new Scanner(System.in);
		Deque<String> nameQue = new ArrayDeque<>();
		Deque<Integer> workQue = new ArrayDeque<>();
		String[] rem  = br.readLine().split(" "); 
		int n = Integer.parseInt(rem[0]);//Integer.parseInt(sc.next());
		int time = Integer.parseInt(rem[1]); //Integer.parseInt(sc.next());
		//int[][] data = new int[n][2];
		//String[] stemp ;
		for(int i= 0 ; i< n ; i++){
			rem = br.readLine().split(" "); 
			nameQue.offer(rem[0]);
			workQue.offer(Integer.parseInt(rem[1]));
		}
		roundSche(nameQue,workQue,time);
	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) Deque<String> nameQue = new ArrayDeque<>(); nameQue new ArrayDeque<>() Deque<Integer> workQue = new ArrayDeque<>(); workQue new ArrayDeque<>() String[] rem  = br.readLine().split(" "); rem br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " int n = Integer.parseInt(rem[0]); n Integer.parseInt(rem[0]) Integer.parseInt Integer rem[0] rem 0 int time = Integer.parseInt(rem[1]); time Integer.parseInt(rem[1]) Integer.parseInt Integer rem[1] rem 1 for(int i= 0 ; i< n ; i++){
			rem = br.readLine().split(" "); 
			nameQue.offer(rem[0]);
			workQue.offer(Integer.parseInt(rem[1]));
		} int i= 0 ; int i= 0 ; i 0 i< n i n i++ i++ i {
			rem = br.readLine().split(" "); 
			nameQue.offer(rem[0]);
			workQue.offer(Integer.parseInt(rem[1]));
		} {
			rem = br.readLine().split(" "); 
			nameQue.offer(rem[0]);
			workQue.offer(Integer.parseInt(rem[1]));
		} rem = br.readLine().split(" ") rem br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " nameQue.offer(rem[0]) nameQue.offer nameQue rem[0] rem 0 workQue.offer(Integer.parseInt(rem[1])) workQue.offer workQue Integer.parseInt(rem[1]) Integer.parseInt Integer rem[1] rem 1 roundSche(nameQue,workQue,time) roundSche nameQue workQue time String[] args args public static void roundSche(Deque<String> nameQ , Deque<Integer> workQ , int time)
	{
		int pos , prog = 0;
		int temp ;
		while(workQ.size() != 0)
		{
			temp =  workQ.poll();
			if(temp <= time){
				prog += temp;
				sb.append(nameQ.poll()).append(' ').append(prog).append('\n');
			}
			else 
			{
				workQ.offer(temp - time);
				nameQ.offer(nameQ.poll());
				prog += time;
			}
		}
		System.out.print(sb);
		
	} roundSche {
		int pos , prog = 0;
		int temp ;
		while(workQ.size() != 0)
		{
			temp =  workQ.poll();
			if(temp <= time){
				prog += temp;
				sb.append(nameQ.poll()).append(' ').append(prog).append('\n');
			}
			else 
			{
				workQ.offer(temp - time);
				nameQ.offer(nameQ.poll());
				prog += time;
			}
		}
		System.out.print(sb);
		
	} int pos pos prog = 0; prog 0 int temp ; temp while(workQ.size() != 0)
		{
			temp =  workQ.poll();
			if(temp <= time){
				prog += temp;
				sb.append(nameQ.poll()).append(' ').append(prog).append('\n');
			}
			else 
			{
				workQ.offer(temp - time);
				nameQ.offer(nameQ.poll());
				prog += time;
			}
		} workQ.size() != 0 workQ.size() workQ.size workQ 0 {
			temp =  workQ.poll();
			if(temp <= time){
				prog += temp;
				sb.append(nameQ.poll()).append(' ').append(prog).append('\n');
			}
			else 
			{
				workQ.offer(temp - time);
				nameQ.offer(nameQ.poll());
				prog += time;
			}
		} temp =  workQ.poll() temp workQ.poll() workQ.poll workQ if(temp <= time){
				prog += temp;
				sb.append(nameQ.poll()).append(' ').append(prog).append('\n');
			}
			else 
			{
				workQ.offer(temp - time);
				nameQ.offer(nameQ.poll());
				prog += time;
			} temp <= time temp time {
				prog += temp;
				sb.append(nameQ.poll()).append(' ').append(prog).append('\n');
			} prog += temp prog temp sb.append(nameQ.poll()).append(' ').append(prog).append('\n') sb.append(nameQ.poll()).append(' ').append(prog).append sb.append(nameQ.poll()).append(' ').append(prog) sb.append(nameQ.poll()).append(' ').append sb.append(nameQ.poll()).append(' ') sb.append(nameQ.poll()).append sb.append(nameQ.poll()) sb.append sb nameQ.poll() nameQ.poll nameQ ' ' prog '\n' {
				workQ.offer(temp - time);
				nameQ.offer(nameQ.poll());
				prog += time;
			} workQ.offer(temp - time) workQ.offer workQ temp - time temp time nameQ.offer(nameQ.poll()) nameQ.offer nameQ nameQ.poll() nameQ.poll nameQ prog += time prog time System.out.print(sb) System.out.print System.out System System.out sb Deque<String> nameQ nameQ Deque<Integer> workQ workQ int time time public class Main
{
	static StringBuilder sb = new StringBuilder();
	public static void main(String[] args)throws IOException
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		//Scanner sc = new Scanner(System.in);
		Deque<String> nameQue = new ArrayDeque<>();
		Deque<Integer> workQue = new ArrayDeque<>();
		String[] rem  = br.readLine().split(" "); 
		int n = Integer.parseInt(rem[0]);//Integer.parseInt(sc.next());
		int time = Integer.parseInt(rem[1]); //Integer.parseInt(sc.next());
		//int[][] data = new int[n][2];
		//String[] stemp ;
		for(int i= 0 ; i< n ; i++){
			rem = br.readLine().split(" "); 
			nameQue.offer(rem[0]);
			workQue.offer(Integer.parseInt(rem[1]));
		}
		roundSche(nameQue,workQue,time);
	}
	public static void roundSche(Deque<String> nameQ , Deque<Integer> workQ , int time)
	{
		int pos , prog = 0;
		int temp ;
		while(workQ.size() != 0)
		{
			temp =  workQ.poll();
			if(temp <= time){
				prog += temp;
				sb.append(nameQ.poll()).append(' ').append(prog).append('\n');
			}
			else 
			{
				workQ.offer(temp - time);
				nameQ.offer(nameQ.poll());
				prog += time;
			}
		}
		System.out.print(sb);
		
	}
	
} public class Main
{
	static StringBuilder sb = new StringBuilder();
	public static void main(String[] args)throws IOException
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		//Scanner sc = new Scanner(System.in);
		Deque<String> nameQue = new ArrayDeque<>();
		Deque<Integer> workQue = new ArrayDeque<>();
		String[] rem  = br.readLine().split(" "); 
		int n = Integer.parseInt(rem[0]);//Integer.parseInt(sc.next());
		int time = Integer.parseInt(rem[1]); //Integer.parseInt(sc.next());
		//int[][] data = new int[n][2];
		//String[] stemp ;
		for(int i= 0 ; i< n ; i++){
			rem = br.readLine().split(" "); 
			nameQue.offer(rem[0]);
			workQue.offer(Integer.parseInt(rem[1]));
		}
		roundSche(nameQue,workQue,time);
	}
	public static void roundSche(Deque<String> nameQ , Deque<Integer> workQ , int time)
	{
		int pos , prog = 0;
		int temp ;
		while(workQ.size() != 0)
		{
			temp =  workQ.poll();
			if(temp <= time){
				prog += temp;
				sb.append(nameQ.poll()).append(' ').append(prog).append('\n');
			}
			else 
			{
				workQ.offer(temp - time);
				nameQ.offer(nameQ.poll());
				prog += time;
			}
		}
		System.out.print(sb);
		
	}
	
} Main
import java.io.*;
import java.util.*;

public class Main
{
	static StringBuilder sb = new StringBuilder();
	public static void main(String[] args)throws IOException
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		//Scanner sc = new Scanner(System.in);
		Deque<String> nameQue = new ArrayDeque<>();
		Deque<Integer> workQue = new ArrayDeque<>();
		String[] rem  = br.readLine().split(" "); 
		int n = Integer.parseInt(rem[0]);//Integer.parseInt(sc.next());
		int time = Integer.parseInt(rem[1]); //Integer.parseInt(sc.next());
		//int[][] data = new int[n][2];
		//String[] stemp ;
		for(int i= 0 ; i< n ; i++){
			rem = br.readLine().split(" "); 
			nameQue.offer(rem[0]);
			workQue.offer(Integer.parseInt(rem[1]));
		}
		roundSche(nameQue,workQue,time);
	}
	public static void roundSche(Deque<String> nameQ , Deque<Integer> workQ , int time)
	{
		int pos , prog = 0;
		int temp ;
		while(workQ.size() != 0)
		{
			temp =  workQ.poll();
			if(temp <= time){
				prog += temp;
				sb.append(nameQ.poll()).append(' ').append(prog).append('\n');
			}
			else 
			{
				workQ.offer(temp - time);
				nameQ.offer(nameQ.poll());
				prog += time;
			}
		}
		System.out.print(sb);
		
	}
	
}