import java.util.Scanner;

class Process {
  String name;
  int time;
}

public class Main {
  private static int head, tail;
  private final static int MAX = 100000;
  private static Process[] Queue = new Process[MAX];

  public static void main(final String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int q = sc.nextInt();
    int elaps = 0;
    for (int i = 1; i <= n; i++) {
      Queue[i] = new Process();
      Queue[i].name = sc.next();
      Queue[i].time = sc.nextInt();
    }
    head = 1;
    tail = n + 1;
    while (head != tail) {
      Process p = dequeue();
      int time = Math.min(p.time, q);
      p.time -= time;
      elaps += time;
      if (p.time > 0)
        enqueue(p);
      else {
        System.out.printf("%s %d\n", p.name, elaps);
      }
    }
  }

  private static void initialize() {
    head = tail = 0;
  }

  private static boolean isEmpty() {
    return head == tail;
  }

  private static boolean isFull() {
    return head == (tail + 1) % MAX;
    // if (tail == MAX) {
    // return head == 0;
    // } else
    // return tail - 1 == head;
  }

  private static void enqueue(Process x) {
    if (isFull()) {
      throw new Error("Queue Over Flow");
    }
    Queue[tail] = x;
    if (tail + 1 == MAX)
      tail = 0;
    else
      tail++;
  }

  private static Process dequeue() {
    if (isEmpty()) {
      throw new Error("Queue Under Flow");
    }
    Process x = Queue[head];
    if (head + 1 == MAX)
      head = 0;
    else
      head++;
    return x;
  }

} import java.util.Scanner; Scanner java.util class Process {
  String name;
  int time;
} Process String name; name int time; time public class Main {
  private static int head, tail;
  private final static int MAX = 100000;
  private static Process[] Queue = new Process[MAX];

  public static void main(final String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int q = sc.nextInt();
    int elaps = 0;
    for (int i = 1; i <= n; i++) {
      Queue[i] = new Process();
      Queue[i].name = sc.next();
      Queue[i].time = sc.nextInt();
    }
    head = 1;
    tail = n + 1;
    while (head != tail) {
      Process p = dequeue();
      int time = Math.min(p.time, q);
      p.time -= time;
      elaps += time;
      if (p.time > 0)
        enqueue(p);
      else {
        System.out.printf("%s %d\n", p.name, elaps);
      }
    }
  }

  private static void initialize() {
    head = tail = 0;
  }

  private static boolean isEmpty() {
    return head == tail;
  }

  private static boolean isFull() {
    return head == (tail + 1) % MAX;
    // if (tail == MAX) {
    // return head == 0;
    // } else
    // return tail - 1 == head;
  }

  private static void enqueue(Process x) {
    if (isFull()) {
      throw new Error("Queue Over Flow");
    }
    Queue[tail] = x;
    if (tail + 1 == MAX)
      tail = 0;
    else
      tail++;
  }

  private static Process dequeue() {
    if (isEmpty()) {
      throw new Error("Queue Under Flow");
    }
    Process x = Queue[head];
    if (head + 1 == MAX)
      head = 0;
    else
      head++;
    return x;
  }

} Main private static int head head tail; tail private final static int MAX = 100000; MAX 100000 private static Process[] Queue = new Process[MAX]; Queue new Process[MAX] MAX public static void main(final String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int q = sc.nextInt();
    int elaps = 0;
    for (int i = 1; i <= n; i++) {
      Queue[i] = new Process();
      Queue[i].name = sc.next();
      Queue[i].time = sc.nextInt();
    }
    head = 1;
    tail = n + 1;
    while (head != tail) {
      Process p = dequeue();
      int time = Math.min(p.time, q);
      p.time -= time;
      elaps += time;
      if (p.time > 0)
        enqueue(p);
      else {
        System.out.printf("%s %d\n", p.name, elaps);
      }
    }
  } main {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int q = sc.nextInt();
    int elaps = 0;
    for (int i = 1; i <= n; i++) {
      Queue[i] = new Process();
      Queue[i].name = sc.next();
      Queue[i].time = sc.nextInt();
    }
    head = 1;
    tail = n + 1;
    while (head != tail) {
      Process p = dequeue();
      int time = Math.min(p.time, q);
      p.time -= time;
      elaps += time;
      if (p.time > 0)
        enqueue(p);
      else {
        System.out.printf("%s %d\n", p.name, elaps);
      }
    }
  } 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 int elaps = 0; elaps 0 for (int i = 1; i <= n; i++) {
      Queue[i] = new Process();
      Queue[i].name = sc.next();
      Queue[i].time = sc.nextInt();
    } int i = 1; int i = 1; i 1 i <= n i n i++ i++ i {
      Queue[i] = new Process();
      Queue[i].name = sc.next();
      Queue[i].time = sc.nextInt();
    } {
      Queue[i] = new Process();
      Queue[i].name = sc.next();
      Queue[i].time = sc.nextInt();
    } Queue[i] = new Process() Queue[i] Queue i new Process() Queue[i].name = sc.next() Queue[i].name Queue[i] Queue i Queue[i].name sc.next() sc.next sc Queue[i].time = sc.nextInt() Queue[i].time Queue[i] Queue i Queue[i].time sc.nextInt() sc.nextInt sc head = 1 head 1 tail = n + 1 tail n + 1 n 1 while (head != tail) {
      Process p = dequeue();
      int time = Math.min(p.time, q);
      p.time -= time;
      elaps += time;
      if (p.time > 0)
        enqueue(p);
      else {
        System.out.printf("%s %d\n", p.name, elaps);
      }
    } head != tail head tail {
      Process p = dequeue();
      int time = Math.min(p.time, q);
      p.time -= time;
      elaps += time;
      if (p.time > 0)
        enqueue(p);
      else {
        System.out.printf("%s %d\n", p.name, elaps);
      }
    } Process p = dequeue(); p dequeue() dequeue int time = Math.min(p.time, q); time Math.min(p.time, q) Math.min Math p.time p p.time q p.time -= time p.time p p.time time elaps += time elaps time if (p.time > 0)
        enqueue(p);
      else {
        System.out.printf("%s %d\n", p.name, elaps);
      } p.time > 0 p.time p p.time 0 enqueue(p) enqueue p {
        System.out.printf("%s %d\n", p.name, elaps);
      } System.out.printf("%s %d\n", p.name, elaps) System.out.printf System.out System System.out "%s %d\n" p.name p p.name elaps final String[] args args private static void initialize() {
    head = tail = 0;
  } initialize {
    head = tail = 0;
  } head = tail = 0 head tail = 0 tail 0 private static boolean isEmpty() {
    return head == tail;
  } isEmpty {
    return head == tail;
  } return head == tail; head == tail head tail private static boolean isFull() {
    return head == (tail + 1) % MAX;
    // if (tail == MAX) {
    // return head == 0;
    // } else
    // return tail - 1 == head;
  } isFull {
    return head == (tail + 1) % MAX;
    // if (tail == MAX) {
    // return head == 0;
    // } else
    // return tail - 1 == head;
  } return head == (tail + 1) % MAX; head == (tail + 1) % MAX head (tail + 1) % MAX (tail + 1) tail 1 MAX private static void enqueue(Process x) {
    if (isFull()) {
      throw new Error("Queue Over Flow");
    }
    Queue[tail] = x;
    if (tail + 1 == MAX)
      tail = 0;
    else
      tail++;
  } enqueue {
    if (isFull()) {
      throw new Error("Queue Over Flow");
    }
    Queue[tail] = x;
    if (tail + 1 == MAX)
      tail = 0;
    else
      tail++;
  } if (isFull()) {
      throw new Error("Queue Over Flow");
    } isFull() isFull {
      throw new Error("Queue Over Flow");
    } throw new Error("Queue Over Flow"); new Error("Queue Over Flow") Queue[tail] = x Queue[tail] Queue tail x if (tail + 1 == MAX)
      tail = 0;
    else
      tail++; tail + 1 == MAX tail + 1 tail 1 MAX tail = 0 tail 0 tail++ tail Process x x private static Process dequeue() {
    if (isEmpty()) {
      throw new Error("Queue Under Flow");
    }
    Process x = Queue[head];
    if (head + 1 == MAX)
      head = 0;
    else
      head++;
    return x;
  } dequeue {
    if (isEmpty()) {
      throw new Error("Queue Under Flow");
    }
    Process x = Queue[head];
    if (head + 1 == MAX)
      head = 0;
    else
      head++;
    return x;
  } if (isEmpty()) {
      throw new Error("Queue Under Flow");
    } isEmpty() isEmpty {
      throw new Error("Queue Under Flow");
    } throw new Error("Queue Under Flow"); new Error("Queue Under Flow") Process x = Queue[head]; x Queue[head] Queue head if (head + 1 == MAX)
      head = 0;
    else
      head++; head + 1 == MAX head + 1 head 1 MAX head = 0 head 0 head++ head return x; x public class Main {
  private static int head, tail;
  private final static int MAX = 100000;
  private static Process[] Queue = new Process[MAX];

  public static void main(final String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int q = sc.nextInt();
    int elaps = 0;
    for (int i = 1; i <= n; i++) {
      Queue[i] = new Process();
      Queue[i].name = sc.next();
      Queue[i].time = sc.nextInt();
    }
    head = 1;
    tail = n + 1;
    while (head != tail) {
      Process p = dequeue();
      int time = Math.min(p.time, q);
      p.time -= time;
      elaps += time;
      if (p.time > 0)
        enqueue(p);
      else {
        System.out.printf("%s %d\n", p.name, elaps);
      }
    }
  }

  private static void initialize() {
    head = tail = 0;
  }

  private static boolean isEmpty() {
    return head == tail;
  }

  private static boolean isFull() {
    return head == (tail + 1) % MAX;
    // if (tail == MAX) {
    // return head == 0;
    // } else
    // return tail - 1 == head;
  }

  private static void enqueue(Process x) {
    if (isFull()) {
      throw new Error("Queue Over Flow");
    }
    Queue[tail] = x;
    if (tail + 1 == MAX)
      tail = 0;
    else
      tail++;
  }

  private static Process dequeue() {
    if (isEmpty()) {
      throw new Error("Queue Under Flow");
    }
    Process x = Queue[head];
    if (head + 1 == MAX)
      head = 0;
    else
      head++;
    return x;
  }

} public class Main {
  private static int head, tail;
  private final static int MAX = 100000;
  private static Process[] Queue = new Process[MAX];

  public static void main(final String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int q = sc.nextInt();
    int elaps = 0;
    for (int i = 1; i <= n; i++) {
      Queue[i] = new Process();
      Queue[i].name = sc.next();
      Queue[i].time = sc.nextInt();
    }
    head = 1;
    tail = n + 1;
    while (head != tail) {
      Process p = dequeue();
      int time = Math.min(p.time, q);
      p.time -= time;
      elaps += time;
      if (p.time > 0)
        enqueue(p);
      else {
        System.out.printf("%s %d\n", p.name, elaps);
      }
    }
  }

  private static void initialize() {
    head = tail = 0;
  }

  private static boolean isEmpty() {
    return head == tail;
  }

  private static boolean isFull() {
    return head == (tail + 1) % MAX;
    // if (tail == MAX) {
    // return head == 0;
    // } else
    // return tail - 1 == head;
  }

  private static void enqueue(Process x) {
    if (isFull()) {
      throw new Error("Queue Over Flow");
    }
    Queue[tail] = x;
    if (tail + 1 == MAX)
      tail = 0;
    else
      tail++;
  }

  private static Process dequeue() {
    if (isEmpty()) {
      throw new Error("Queue Under Flow");
    }
    Process x = Queue[head];
    if (head + 1 == MAX)
      head = 0;
    else
      head++;
    return x;
  }

} Main
import java.util.Scanner;

class Process {
  String name;
  int time;
}

public class Main {
  private static int head, tail;
  private final static int MAX = 100000;
  private static Process[] Queue = new Process[MAX];

  public static void main(final String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int q = sc.nextInt();
    int elaps = 0;
    for (int i = 1; i <= n; i++) {
      Queue[i] = new Process();
      Queue[i].name = sc.next();
      Queue[i].time = sc.nextInt();
    }
    head = 1;
    tail = n + 1;
    while (head != tail) {
      Process p = dequeue();
      int time = Math.min(p.time, q);
      p.time -= time;
      elaps += time;
      if (p.time > 0)
        enqueue(p);
      else {
        System.out.printf("%s %d\n", p.name, elaps);
      }
    }
  }

  private static void initialize() {
    head = tail = 0;
  }

  private static boolean isEmpty() {
    return head == tail;
  }

  private static boolean isFull() {
    return head == (tail + 1) % MAX;
    // if (tail == MAX) {
    // return head == 0;
    // } else
    // return tail - 1 == head;
  }

  private static void enqueue(Process x) {
    if (isFull()) {
      throw new Error("Queue Over Flow");
    }
    Queue[tail] = x;
    if (tail + 1 == MAX)
      tail = 0;
    else
      tail++;
  }

  private static Process dequeue() {
    if (isEmpty()) {
      throw new Error("Queue Under Flow");
    }
    Process x = Queue[head];
    if (head + 1 == MAX)
      head = 0;
    else
      head++;
    return x;
  }

}
