import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    int q = sc.nextInt();

    Deque<Process> procs = new ArrayDeque<>();
    for (int i = 0; i < n; i++) {
      String name = sc.next();
      int time = sc.nextInt();
      procs.push(new Process(name, time));
    }

    Deque<Process> finishedProcs = new ArrayDeque<>();

    int totalQ = 0;

    while (procs.size() > 0) {
      Process p = procs.removeLast();
      int quantum = Math.min(q, p.getTime());
      totalQ += quantum;
      p = p.progress(quantum);
      if (p.finished()) {
        finishedProcs.addLast(new Process(p.getName(), totalQ));
      } else {
        procs.addFirst(p);
      }
    }

    PrintWriter pw = new PrintWriter(System.out);
    for (Process p : finishedProcs) {
      pw.println(p.getName() + " " + p.getTime());
    }

    pw.flush();
  }

  private static class Process {
    private String name;
    private int time;

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

    public String getName() {
      return name;
    }

    public int getTime() {
      return time;
    }

    public Process progress(int ms) {
      return new Process(name, time - ms);
    }

    public boolean finished() {
      return time <= 0;
    }
  }
} import java.io.PrintWriter; PrintWriter java.io import java.util.ArrayDeque; ArrayDeque java.util import java.util.Deque; Deque java.util import java.util.Scanner; Scanner java.util public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    int q = sc.nextInt();

    Deque<Process> procs = new ArrayDeque<>();
    for (int i = 0; i < n; i++) {
      String name = sc.next();
      int time = sc.nextInt();
      procs.push(new Process(name, time));
    }

    Deque<Process> finishedProcs = new ArrayDeque<>();

    int totalQ = 0;

    while (procs.size() > 0) {
      Process p = procs.removeLast();
      int quantum = Math.min(q, p.getTime());
      totalQ += quantum;
      p = p.progress(quantum);
      if (p.finished()) {
        finishedProcs.addLast(new Process(p.getName(), totalQ));
      } else {
        procs.addFirst(p);
      }
    }

    PrintWriter pw = new PrintWriter(System.out);
    for (Process p : finishedProcs) {
      pw.println(p.getName() + " " + p.getTime());
    }

    pw.flush();
  }

  private static class Process {
    private String name;
    private int time;

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

    public String getName() {
      return name;
    }

    public int getTime() {
      return time;
    }

    public Process progress(int ms) {
      return new Process(name, time - ms);
    }

    public boolean finished() {
      return time <= 0;
    }
  }
} Main public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    int q = sc.nextInt();

    Deque<Process> procs = new ArrayDeque<>();
    for (int i = 0; i < n; i++) {
      String name = sc.next();
      int time = sc.nextInt();
      procs.push(new Process(name, time));
    }

    Deque<Process> finishedProcs = new ArrayDeque<>();

    int totalQ = 0;

    while (procs.size() > 0) {
      Process p = procs.removeLast();
      int quantum = Math.min(q, p.getTime());
      totalQ += quantum;
      p = p.progress(quantum);
      if (p.finished()) {
        finishedProcs.addLast(new Process(p.getName(), totalQ));
      } else {
        procs.addFirst(p);
      }
    }

    PrintWriter pw = new PrintWriter(System.out);
    for (Process p : finishedProcs) {
      pw.println(p.getName() + " " + p.getTime());
    }

    pw.flush();
  } main {
    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    int q = sc.nextInt();

    Deque<Process> procs = new ArrayDeque<>();
    for (int i = 0; i < n; i++) {
      String name = sc.next();
      int time = sc.nextInt();
      procs.push(new Process(name, time));
    }

    Deque<Process> finishedProcs = new ArrayDeque<>();

    int totalQ = 0;

    while (procs.size() > 0) {
      Process p = procs.removeLast();
      int quantum = Math.min(q, p.getTime());
      totalQ += quantum;
      p = p.progress(quantum);
      if (p.finished()) {
        finishedProcs.addLast(new Process(p.getName(), totalQ));
      } else {
        procs.addFirst(p);
      }
    }

    PrintWriter pw = new PrintWriter(System.out);
    for (Process p : finishedProcs) {
      pw.println(p.getName() + " " + p.getTime());
    }

    pw.flush();
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int q = sc.nextInt(); q sc.nextInt() sc.nextInt sc Deque<Process> procs = new ArrayDeque<>(); procs new ArrayDeque<>() for (int i = 0; i < n; i++) {
      String name = sc.next();
      int time = sc.nextInt();
      procs.push(new Process(name, time));
    } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
      String name = sc.next();
      int time = sc.nextInt();
      procs.push(new Process(name, time));
    } {
      String name = sc.next();
      int time = sc.nextInt();
      procs.push(new Process(name, time));
    } String name = sc.next(); name sc.next() sc.next sc int time = sc.nextInt(); time sc.nextInt() sc.nextInt sc procs.push(new Process(name, time)) procs.push procs new Process(name, time) Deque<Process> finishedProcs = new ArrayDeque<>(); finishedProcs new ArrayDeque<>() int totalQ = 0; totalQ 0 while (procs.size() > 0) {
      Process p = procs.removeLast();
      int quantum = Math.min(q, p.getTime());
      totalQ += quantum;
      p = p.progress(quantum);
      if (p.finished()) {
        finishedProcs.addLast(new Process(p.getName(), totalQ));
      } else {
        procs.addFirst(p);
      }
    } procs.size() > 0 procs.size() procs.size procs 0 {
      Process p = procs.removeLast();
      int quantum = Math.min(q, p.getTime());
      totalQ += quantum;
      p = p.progress(quantum);
      if (p.finished()) {
        finishedProcs.addLast(new Process(p.getName(), totalQ));
      } else {
        procs.addFirst(p);
      }
    } Process p = procs.removeLast(); p procs.removeLast() procs.removeLast procs int quantum = Math.min(q, p.getTime()); quantum Math.min(q, p.getTime()) Math.min Math q p.getTime() p.getTime p totalQ += quantum totalQ quantum p = p.progress(quantum) p p.progress(quantum) p.progress p quantum if (p.finished()) {
        finishedProcs.addLast(new Process(p.getName(), totalQ));
      } else {
        procs.addFirst(p);
      } p.finished() p.finished p {
        finishedProcs.addLast(new Process(p.getName(), totalQ));
      } finishedProcs.addLast(new Process(p.getName(), totalQ)) finishedProcs.addLast finishedProcs new Process(p.getName(), totalQ) {
        procs.addFirst(p);
      } procs.addFirst(p) procs.addFirst procs p PrintWriter pw = new PrintWriter(System.out); pw new PrintWriter(System.out) for (Process p : finishedProcs) {
      pw.println(p.getName() + " " + p.getTime());
    } Process p finishedProcs {
      pw.println(p.getName() + " " + p.getTime());
    } {
      pw.println(p.getName() + " " + p.getTime());
    } pw.println(p.getName() + " " + p.getTime()) pw.println pw p.getName() + " " + p.getTime() p.getName() + " " + p.getTime() p.getName() p.getName p " " p.getTime() p.getTime p pw.flush() pw.flush pw String[] args args private static class Process {
    private String name;
    private int time;

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

    public String getName() {
      return name;
    }

    public int getTime() {
      return time;
    }

    public Process progress(int ms) {
      return new Process(name, time - ms);
    }

    public boolean finished() {
      return time <= 0;
    }
  } Process private String name; name private 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 public String getName() {
      return name;
    } getName {
      return name;
    } return name; name public int getTime() {
      return time;
    } getTime {
      return time;
    } return time; time public Process progress(int ms) {
      return new Process(name, time - ms);
    } progress {
      return new Process(name, time - ms);
    } return new Process(name, time - ms); new Process(name, time - ms) int ms ms public boolean finished() {
      return time <= 0;
    } finished {
      return time <= 0;
    } return time <= 0; time <= 0 time 0 public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    int q = sc.nextInt();

    Deque<Process> procs = new ArrayDeque<>();
    for (int i = 0; i < n; i++) {
      String name = sc.next();
      int time = sc.nextInt();
      procs.push(new Process(name, time));
    }

    Deque<Process> finishedProcs = new ArrayDeque<>();

    int totalQ = 0;

    while (procs.size() > 0) {
      Process p = procs.removeLast();
      int quantum = Math.min(q, p.getTime());
      totalQ += quantum;
      p = p.progress(quantum);
      if (p.finished()) {
        finishedProcs.addLast(new Process(p.getName(), totalQ));
      } else {
        procs.addFirst(p);
      }
    }

    PrintWriter pw = new PrintWriter(System.out);
    for (Process p : finishedProcs) {
      pw.println(p.getName() + " " + p.getTime());
    }

    pw.flush();
  }

  private static class Process {
    private String name;
    private int time;

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

    public String getName() {
      return name;
    }

    public int getTime() {
      return time;
    }

    public Process progress(int ms) {
      return new Process(name, time - ms);
    }

    public boolean finished() {
      return time <= 0;
    }
  }
} public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    int q = sc.nextInt();

    Deque<Process> procs = new ArrayDeque<>();
    for (int i = 0; i < n; i++) {
      String name = sc.next();
      int time = sc.nextInt();
      procs.push(new Process(name, time));
    }

    Deque<Process> finishedProcs = new ArrayDeque<>();

    int totalQ = 0;

    while (procs.size() > 0) {
      Process p = procs.removeLast();
      int quantum = Math.min(q, p.getTime());
      totalQ += quantum;
      p = p.progress(quantum);
      if (p.finished()) {
        finishedProcs.addLast(new Process(p.getName(), totalQ));
      } else {
        procs.addFirst(p);
      }
    }

    PrintWriter pw = new PrintWriter(System.out);
    for (Process p : finishedProcs) {
      pw.println(p.getName() + " " + p.getTime());
    }

    pw.flush();
  }

  private static class Process {
    private String name;
    private int time;

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

    public String getName() {
      return name;
    }

    public int getTime() {
      return time;
    }

    public Process progress(int ms) {
      return new Process(name, time - ms);
    }

    public boolean finished() {
      return time <= 0;
    }
  }
} Main
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    int q = sc.nextInt();

    Deque<Process> procs = new ArrayDeque<>();
    for (int i = 0; i < n; i++) {
      String name = sc.next();
      int time = sc.nextInt();
      procs.push(new Process(name, time));
    }

    Deque<Process> finishedProcs = new ArrayDeque<>();

    int totalQ = 0;

    while (procs.size() > 0) {
      Process p = procs.removeLast();
      int quantum = Math.min(q, p.getTime());
      totalQ += quantum;
      p = p.progress(quantum);
      if (p.finished()) {
        finishedProcs.addLast(new Process(p.getName(), totalQ));
      } else {
        procs.addFirst(p);
      }
    }

    PrintWriter pw = new PrintWriter(System.out);
    for (Process p : finishedProcs) {
      pw.println(p.getName() + " " + p.getTime());
    }

    pw.flush();
  }

  private static class Process {
    private String name;
    private int time;

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

    public String getName() {
      return name;
    }

    public int getTime() {
      return time;
    }

    public Process progress(int ms) {
      return new Process(name, time - ms);
    }

    public boolean finished() {
      return time <= 0;
    }
  }
}
