import java.util.ArrayList;
import java.util.List;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Queue;

class Main {

  public static class Process {

    public String name;
    public int time;

    public Process(String name, int time) {
      this.name = name;
      this.time = time;
    }

  }

  public static void process(Queue<Process> q, int quantum) {

    int curr_time = 0;

    while (q.isEmpty() == false) {

      Process curr_ps = q.remove();

      int time_passed = Math.min(quantum, curr_ps.time);
      curr_time += time_passed;
      curr_ps.time -= time_passed;

      if (curr_ps.time == 0)
        System.out.println(curr_ps.name + " " + curr_time);
      else
        q.add(curr_ps);
    }

  }

  public static void main(String[] args) {
    Scanner s = new Scanner(System.in);
    int n = s.nextInt();
    int quantum = s.nextInt();
    Queue<Process> processes = new LinkedList<Process>();
    for (int i = 0; i < n; i++) {
      processes.add(new Process(s.next(), s.nextInt()));
    }
    process(processes, quantum);
  }
} import java.util.ArrayList; ArrayList java.util import java.util.List; List java.util import java.util.LinkedList; LinkedList java.util import java.util.Scanner; Scanner java.util import java.util.Queue; Queue java.util class Main {

  public static class Process {

    public String name;
    public int time;

    public Process(String name, int time) {
      this.name = name;
      this.time = time;
    }

  }

  public static void process(Queue<Process> q, int quantum) {

    int curr_time = 0;

    while (q.isEmpty() == false) {

      Process curr_ps = q.remove();

      int time_passed = Math.min(quantum, curr_ps.time);
      curr_time += time_passed;
      curr_ps.time -= time_passed;

      if (curr_ps.time == 0)
        System.out.println(curr_ps.name + " " + curr_time);
      else
        q.add(curr_ps);
    }

  }

  public static void main(String[] args) {
    Scanner s = new Scanner(System.in);
    int n = s.nextInt();
    int quantum = s.nextInt();
    Queue<Process> processes = new LinkedList<Process>();
    for (int i = 0; i < n; i++) {
      processes.add(new Process(s.next(), s.nextInt()));
    }
    process(processes, quantum);
  }
} Main public static void process(Queue<Process> q, int quantum) {

    int curr_time = 0;

    while (q.isEmpty() == false) {

      Process curr_ps = q.remove();

      int time_passed = Math.min(quantum, curr_ps.time);
      curr_time += time_passed;
      curr_ps.time -= time_passed;

      if (curr_ps.time == 0)
        System.out.println(curr_ps.name + " " + curr_time);
      else
        q.add(curr_ps);
    }

  } process {

    int curr_time = 0;

    while (q.isEmpty() == false) {

      Process curr_ps = q.remove();

      int time_passed = Math.min(quantum, curr_ps.time);
      curr_time += time_passed;
      curr_ps.time -= time_passed;

      if (curr_ps.time == 0)
        System.out.println(curr_ps.name + " " + curr_time);
      else
        q.add(curr_ps);
    }

  } int curr_time = 0; curr_time 0 while (q.isEmpty() == false) {

      Process curr_ps = q.remove();

      int time_passed = Math.min(quantum, curr_ps.time);
      curr_time += time_passed;
      curr_ps.time -= time_passed;

      if (curr_ps.time == 0)
        System.out.println(curr_ps.name + " " + curr_time);
      else
        q.add(curr_ps);
    } q.isEmpty() == false q.isEmpty() q.isEmpty q false {

      Process curr_ps = q.remove();

      int time_passed = Math.min(quantum, curr_ps.time);
      curr_time += time_passed;
      curr_ps.time -= time_passed;

      if (curr_ps.time == 0)
        System.out.println(curr_ps.name + " " + curr_time);
      else
        q.add(curr_ps);
    } Process curr_ps = q.remove(); curr_ps q.remove() q.remove q int time_passed = Math.min(quantum, curr_ps.time); time_passed Math.min(quantum, curr_ps.time) Math.min Math quantum curr_ps.time curr_ps curr_ps.time curr_time += time_passed curr_time time_passed curr_ps.time -= time_passed curr_ps.time curr_ps curr_ps.time time_passed if (curr_ps.time == 0)
        System.out.println(curr_ps.name + " " + curr_time);
      else
        q.add(curr_ps); curr_ps.time == 0 curr_ps.time curr_ps curr_ps.time 0 System.out.println(curr_ps.name + " " + curr_time) System.out.println System.out System System.out curr_ps.name + " " + curr_time curr_ps.name + " " + curr_time curr_ps.name curr_ps curr_ps.name " " curr_time q.add(curr_ps) q.add q curr_ps Queue<Process> q q int quantum quantum public static void main(String[] args) {
    Scanner s = new Scanner(System.in);
    int n = s.nextInt();
    int quantum = s.nextInt();
    Queue<Process> processes = new LinkedList<Process>();
    for (int i = 0; i < n; i++) {
      processes.add(new Process(s.next(), s.nextInt()));
    }
    process(processes, quantum);
  } main {
    Scanner s = new Scanner(System.in);
    int n = s.nextInt();
    int quantum = s.nextInt();
    Queue<Process> processes = new LinkedList<Process>();
    for (int i = 0; i < n; i++) {
      processes.add(new Process(s.next(), s.nextInt()));
    }
    process(processes, quantum);
  } Scanner s = new Scanner(System.in); s new Scanner(System.in) int n = s.nextInt(); n s.nextInt() s.nextInt s int quantum = s.nextInt(); quantum s.nextInt() s.nextInt s Queue<Process> processes = new LinkedList<Process>(); processes new LinkedList<Process>() for (int i = 0; i < n; i++) {
      processes.add(new Process(s.next(), s.nextInt()));
    } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
      processes.add(new Process(s.next(), s.nextInt()));
    } {
      processes.add(new Process(s.next(), s.nextInt()));
    } processes.add(new Process(s.next(), s.nextInt())) processes.add processes new Process(s.next(), s.nextInt()) process(processes, quantum) process processes quantum String[] args args public static class Process {

    public String name;
    public int time;

    public Process(String name, int time) {
      this.name = name;
      this.time = time;
    }

  } Process public String name; name public int time; time public Process(String name, int time) {
      this.name = name;
      this.time = time;
    } Process {
      this.name = name;
      this.time = time;
    } this.name = name this.name this this.name name this.time = time this.time this this.time time String name name int time time
import java.util.ArrayList;
import java.util.List;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Queue;

class Main {

  public static class Process {

    public String name;
    public int time;

    public Process(String name, int time) {
      this.name = name;
      this.time = time;
    }

  }

  public static void process(Queue<Process> q, int quantum) {

    int curr_time = 0;

    while (q.isEmpty() == false) {

      Process curr_ps = q.remove();

      int time_passed = Math.min(quantum, curr_ps.time);
      curr_time += time_passed;
      curr_ps.time -= time_passed;

      if (curr_ps.time == 0)
        System.out.println(curr_ps.name + " " + curr_time);
      else
        q.add(curr_ps);
    }

  }

  public static void main(String[] args) {
    Scanner s = new Scanner(System.in);
    int n = s.nextInt();
    int quantum = s.nextInt();
    Queue<Process> processes = new LinkedList<Process>();
    for (int i = 0; i < n; i++) {
      processes.add(new Process(s.next(), s.nextInt()));
    }
    process(processes, quantum);
  }
}
