
import java.util.Scanner;
import java.util.LinkedList;
import java.util.Queue; 
import java.util.*;

public class Main {

	public static void main(String argv[]) {

        Scanner in = new Scanner(System.in);
        int numTask = in.nextInt();
        int maxTime = in.nextInt();
        int curr=0;
        in.skip("(\r\n|[\n\r\u2028\u2029\u0085])?");

        Queue<String> q = new LinkedList<>();
     // accessing the numbers in the second line
        for (int i = 0; i < numTask; i++){
//        	String str = in.nextLine();
        	q.add(in.nextLine());
        }

        while(q.size() > 0){
        	  String element = q.remove();
        	  String[] oneTask = element.split(" ");
        	  int timeDiff = Integer.parseInt(oneTask[1]) - maxTime;
        	  if(timeDiff<=0)
        	  {
        		  curr = curr + Integer.parseInt(oneTask[1]);
        		  System.out.println(oneTask[0] + ' ' + curr);
        	  }
        	  else
        	  {
        		  curr = curr + maxTime;
        		  oneTask[1] = Integer.toString(timeDiff);
        		  q.add(oneTask[0] + ' ' + oneTask[1]);
        	  }
        }

        in.close();
    }
}
 import java.util.Scanner; Scanner java.util import java.util.LinkedList; LinkedList java.util import java.util.Queue; Queue java.util import java.util.*; util.* java public class Main {

	public static void main(String argv[]) {

        Scanner in = new Scanner(System.in);
        int numTask = in.nextInt();
        int maxTime = in.nextInt();
        int curr=0;
        in.skip("(\r\n|[\n\r\u2028\u2029\u0085])?");

        Queue<String> q = new LinkedList<>();
     // accessing the numbers in the second line
        for (int i = 0; i < numTask; i++){
//        	String str = in.nextLine();
        	q.add(in.nextLine());
        }

        while(q.size() > 0){
        	  String element = q.remove();
        	  String[] oneTask = element.split(" ");
        	  int timeDiff = Integer.parseInt(oneTask[1]) - maxTime;
        	  if(timeDiff<=0)
        	  {
        		  curr = curr + Integer.parseInt(oneTask[1]);
        		  System.out.println(oneTask[0] + ' ' + curr);
        	  }
        	  else
        	  {
        		  curr = curr + maxTime;
        		  oneTask[1] = Integer.toString(timeDiff);
        		  q.add(oneTask[0] + ' ' + oneTask[1]);
        	  }
        }

        in.close();
    }
} Main public static void main(String argv[]) {

        Scanner in = new Scanner(System.in);
        int numTask = in.nextInt();
        int maxTime = in.nextInt();
        int curr=0;
        in.skip("(\r\n|[\n\r\u2028\u2029\u0085])?");

        Queue<String> q = new LinkedList<>();
     // accessing the numbers in the second line
        for (int i = 0; i < numTask; i++){
//        	String str = in.nextLine();
        	q.add(in.nextLine());
        }

        while(q.size() > 0){
        	  String element = q.remove();
        	  String[] oneTask = element.split(" ");
        	  int timeDiff = Integer.parseInt(oneTask[1]) - maxTime;
        	  if(timeDiff<=0)
        	  {
        		  curr = curr + Integer.parseInt(oneTask[1]);
        		  System.out.println(oneTask[0] + ' ' + curr);
        	  }
        	  else
        	  {
        		  curr = curr + maxTime;
        		  oneTask[1] = Integer.toString(timeDiff);
        		  q.add(oneTask[0] + ' ' + oneTask[1]);
        	  }
        }

        in.close();
    } main {

        Scanner in = new Scanner(System.in);
        int numTask = in.nextInt();
        int maxTime = in.nextInt();
        int curr=0;
        in.skip("(\r\n|[\n\r\u2028\u2029\u0085])?");

        Queue<String> q = new LinkedList<>();
     // accessing the numbers in the second line
        for (int i = 0; i < numTask; i++){
//        	String str = in.nextLine();
        	q.add(in.nextLine());
        }

        while(q.size() > 0){
        	  String element = q.remove();
        	  String[] oneTask = element.split(" ");
        	  int timeDiff = Integer.parseInt(oneTask[1]) - maxTime;
        	  if(timeDiff<=0)
        	  {
        		  curr = curr + Integer.parseInt(oneTask[1]);
        		  System.out.println(oneTask[0] + ' ' + curr);
        	  }
        	  else
        	  {
        		  curr = curr + maxTime;
        		  oneTask[1] = Integer.toString(timeDiff);
        		  q.add(oneTask[0] + ' ' + oneTask[1]);
        	  }
        }

        in.close();
    } Scanner in = new Scanner(System.in); in new Scanner(System.in) int numTask = in.nextInt(); numTask in.nextInt() in.nextInt in int maxTime = in.nextInt(); maxTime in.nextInt() in.nextInt in int curr=0; curr 0 in.skip("(\r\n|[\n\r\u2028\u2029\u0085])?") in.skip in "(\r\n|[\n\r\u2028\u2029\u0085])?" Queue<String> q = new LinkedList<>(); q new LinkedList<>() for (int i = 0; i < numTask; i++){
//        	String str = in.nextLine();
        	q.add(in.nextLine());
        } int i = 0; int i = 0; i 0 i < numTask i numTask i++ i++ i {
//        	String str = in.nextLine();
        	q.add(in.nextLine());
        } {
//        	String str = in.nextLine();
        	q.add(in.nextLine());
        } q.add(in.nextLine()) q.add q in.nextLine() in.nextLine in while(q.size() > 0){
        	  String element = q.remove();
        	  String[] oneTask = element.split(" ");
        	  int timeDiff = Integer.parseInt(oneTask[1]) - maxTime;
        	  if(timeDiff<=0)
        	  {
        		  curr = curr + Integer.parseInt(oneTask[1]);
        		  System.out.println(oneTask[0] + ' ' + curr);
        	  }
        	  else
        	  {
        		  curr = curr + maxTime;
        		  oneTask[1] = Integer.toString(timeDiff);
        		  q.add(oneTask[0] + ' ' + oneTask[1]);
        	  }
        } q.size() > 0 q.size() q.size q 0 {
        	  String element = q.remove();
        	  String[] oneTask = element.split(" ");
        	  int timeDiff = Integer.parseInt(oneTask[1]) - maxTime;
        	  if(timeDiff<=0)
        	  {
        		  curr = curr + Integer.parseInt(oneTask[1]);
        		  System.out.println(oneTask[0] + ' ' + curr);
        	  }
        	  else
        	  {
        		  curr = curr + maxTime;
        		  oneTask[1] = Integer.toString(timeDiff);
        		  q.add(oneTask[0] + ' ' + oneTask[1]);
        	  }
        } String element = q.remove(); element q.remove() q.remove q String[] oneTask = element.split(" "); oneTask element.split(" ") element.split element " " int timeDiff = Integer.parseInt(oneTask[1]) - maxTime; timeDiff Integer.parseInt(oneTask[1]) - maxTime Integer.parseInt(oneTask[1]) Integer.parseInt Integer oneTask[1] oneTask 1 maxTime if(timeDiff<=0)
        	  {
        		  curr = curr + Integer.parseInt(oneTask[1]);
        		  System.out.println(oneTask[0] + ' ' + curr);
        	  }
        	  else
        	  {
        		  curr = curr + maxTime;
        		  oneTask[1] = Integer.toString(timeDiff);
        		  q.add(oneTask[0] + ' ' + oneTask[1]);
        	  } timeDiff<=0 timeDiff 0 {
        		  curr = curr + Integer.parseInt(oneTask[1]);
        		  System.out.println(oneTask[0] + ' ' + curr);
        	  } curr = curr + Integer.parseInt(oneTask[1]) curr curr + Integer.parseInt(oneTask[1]) curr Integer.parseInt(oneTask[1]) Integer.parseInt Integer oneTask[1] oneTask 1 System.out.println(oneTask[0] + ' ' + curr) System.out.println System.out System System.out oneTask[0] + ' ' + curr oneTask[0] + ' ' + curr oneTask[0] oneTask 0 ' ' curr {
        		  curr = curr + maxTime;
        		  oneTask[1] = Integer.toString(timeDiff);
        		  q.add(oneTask[0] + ' ' + oneTask[1]);
        	  } curr = curr + maxTime curr curr + maxTime curr maxTime oneTask[1] = Integer.toString(timeDiff) oneTask[1] oneTask 1 Integer.toString(timeDiff) Integer.toString Integer timeDiff q.add(oneTask[0] + ' ' + oneTask[1]) q.add q oneTask[0] + ' ' + oneTask[1] oneTask[0] + ' ' + oneTask[1] oneTask[0] oneTask 0 ' ' oneTask[1] oneTask 1 in.close() in.close in String argv[] argv public class Main {

	public static void main(String argv[]) {

        Scanner in = new Scanner(System.in);
        int numTask = in.nextInt();
        int maxTime = in.nextInt();
        int curr=0;
        in.skip("(\r\n|[\n\r\u2028\u2029\u0085])?");

        Queue<String> q = new LinkedList<>();
     // accessing the numbers in the second line
        for (int i = 0; i < numTask; i++){
//        	String str = in.nextLine();
        	q.add(in.nextLine());
        }

        while(q.size() > 0){
        	  String element = q.remove();
        	  String[] oneTask = element.split(" ");
        	  int timeDiff = Integer.parseInt(oneTask[1]) - maxTime;
        	  if(timeDiff<=0)
        	  {
        		  curr = curr + Integer.parseInt(oneTask[1]);
        		  System.out.println(oneTask[0] + ' ' + curr);
        	  }
        	  else
        	  {
        		  curr = curr + maxTime;
        		  oneTask[1] = Integer.toString(timeDiff);
        		  q.add(oneTask[0] + ' ' + oneTask[1]);
        	  }
        }

        in.close();
    }
} public class Main {

	public static void main(String argv[]) {

        Scanner in = new Scanner(System.in);
        int numTask = in.nextInt();
        int maxTime = in.nextInt();
        int curr=0;
        in.skip("(\r\n|[\n\r\u2028\u2029\u0085])?");

        Queue<String> q = new LinkedList<>();
     // accessing the numbers in the second line
        for (int i = 0; i < numTask; i++){
//        	String str = in.nextLine();
        	q.add(in.nextLine());
        }

        while(q.size() > 0){
        	  String element = q.remove();
        	  String[] oneTask = element.split(" ");
        	  int timeDiff = Integer.parseInt(oneTask[1]) - maxTime;
        	  if(timeDiff<=0)
        	  {
        		  curr = curr + Integer.parseInt(oneTask[1]);
        		  System.out.println(oneTask[0] + ' ' + curr);
        	  }
        	  else
        	  {
        		  curr = curr + maxTime;
        		  oneTask[1] = Integer.toString(timeDiff);
        		  q.add(oneTask[0] + ' ' + oneTask[1]);
        	  }
        }

        in.close();
    }
} Main

import java.util.Scanner;
import java.util.LinkedList;
import java.util.Queue; 
import java.util.*;

public class Main {

	public static void main(String argv[]) {

        Scanner in = new Scanner(System.in);
        int numTask = in.nextInt();
        int maxTime = in.nextInt();
        int curr=0;
        in.skip("(\r\n|[\n\r\u2028\u2029\u0085])?");

        Queue<String> q = new LinkedList<>();
     // accessing the numbers in the second line
        for (int i = 0; i < numTask; i++){
//        	String str = in.nextLine();
        	q.add(in.nextLine());
        }

        while(q.size() > 0){
        	  String element = q.remove();
        	  String[] oneTask = element.split(" ");
        	  int timeDiff = Integer.parseInt(oneTask[1]) - maxTime;
        	  if(timeDiff<=0)
        	  {
        		  curr = curr + Integer.parseInt(oneTask[1]);
        		  System.out.println(oneTask[0] + ' ' + curr);
        	  }
        	  else
        	  {
        		  curr = curr + maxTime;
        		  oneTask[1] = Integer.toString(timeDiff);
        		  q.add(oneTask[0] + ' ' + oneTask[1]);
        	  }
        }

        in.close();
    }
}

