import java.nio.*;
import java.util.*;

public class Main {
  static Scanner sc = new Scanner(System.in);

  public static void main(String[] args) throws Exception {
    int n = sc.nextInt();
    int q = sc.nextInt();

    Queue queue = new Queue(n);

    String s;
    int t;
    for (int i = 0; i < n; i++) {
      s = sc.next();
      t = sc.nextInt();

      queue.enQueue(s, t);
    }

    int sum = 0;
    while (!queue.isEmpty()) {
      P p = queue.deQueue();
      if (p.t > q) {
        sum += q;
        queue.enQueue(p.s, p.t - q);
      } else {
        sum += p.t;
        System.out.println(p.s + " " + sum);
      }
    }

    sc.close();
  }
}

class P {
  public String s;
  public int t;

  public P(String s, int t) {
    this.s = s;
    this.t = t;
  }
}

class Queue {
  private int head = 0;
  private int tail = 0;
  private P[] p;

  public Queue(int n) {
    this.p = new P[n + 1];
  }

  public boolean isEmpty() {
    return this.head == this.tail;
  }

  public boolean isFull() {
    return this.head == (this.tail + 1) % this.p.length;
  }

  public void enQueue(String s, int t) throws Exception {
    if (this.isFull()) {
      throw new Exception();
    }

    this.p[this.tail] = new P(s, t);

    if (this.tail + 1 == this.p.length) {
      this.tail = 0;
    } else {
      this.tail++;
    }
  }

  public P deQueue() throws Exception {
    if (this.isEmpty()) {
      throw new Exception();
    }

    P p = this.p[this.head];

    if (this.head + 1 == this.p.length) {
      this.head = 0;
    } else {
      this.head++;
    }

    return p;
  }
} import java.nio.*; nio.* java import java.util.*; util.* java public class Main {
  static Scanner sc = new Scanner(System.in);

  public static void main(String[] args) throws Exception {
    int n = sc.nextInt();
    int q = sc.nextInt();

    Queue queue = new Queue(n);

    String s;
    int t;
    for (int i = 0; i < n; i++) {
      s = sc.next();
      t = sc.nextInt();

      queue.enQueue(s, t);
    }

    int sum = 0;
    while (!queue.isEmpty()) {
      P p = queue.deQueue();
      if (p.t > q) {
        sum += q;
        queue.enQueue(p.s, p.t - q);
      } else {
        sum += p.t;
        System.out.println(p.s + " " + sum);
      }
    }

    sc.close();
  }
} Main static Scanner sc = new Scanner(System.in); sc new Scanner(System.in) public static void main(String[] args) throws Exception {
    int n = sc.nextInt();
    int q = sc.nextInt();

    Queue queue = new Queue(n);

    String s;
    int t;
    for (int i = 0; i < n; i++) {
      s = sc.next();
      t = sc.nextInt();

      queue.enQueue(s, t);
    }

    int sum = 0;
    while (!queue.isEmpty()) {
      P p = queue.deQueue();
      if (p.t > q) {
        sum += q;
        queue.enQueue(p.s, p.t - q);
      } else {
        sum += p.t;
        System.out.println(p.s + " " + sum);
      }
    }

    sc.close();
  } main {
    int n = sc.nextInt();
    int q = sc.nextInt();

    Queue queue = new Queue(n);

    String s;
    int t;
    for (int i = 0; i < n; i++) {
      s = sc.next();
      t = sc.nextInt();

      queue.enQueue(s, t);
    }

    int sum = 0;
    while (!queue.isEmpty()) {
      P p = queue.deQueue();
      if (p.t > q) {
        sum += q;
        queue.enQueue(p.s, p.t - q);
      } else {
        sum += p.t;
        System.out.println(p.s + " " + sum);
      }
    }

    sc.close();
  } int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int q = sc.nextInt(); q sc.nextInt() sc.nextInt sc Queue queue = new Queue(n); queue new Queue(n) String s; s int t; t for (int i = 0; i < n; i++) {
      s = sc.next();
      t = sc.nextInt();

      queue.enQueue(s, t);
    } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
      s = sc.next();
      t = sc.nextInt();

      queue.enQueue(s, t);
    } {
      s = sc.next();
      t = sc.nextInt();

      queue.enQueue(s, t);
    } s = sc.next() s sc.next() sc.next sc t = sc.nextInt() t sc.nextInt() sc.nextInt sc queue.enQueue(s, t) queue.enQueue queue s t int sum = 0; sum 0 while (!queue.isEmpty()) {
      P p = queue.deQueue();
      if (p.t > q) {
        sum += q;
        queue.enQueue(p.s, p.t - q);
      } else {
        sum += p.t;
        System.out.println(p.s + " " + sum);
      }
    } !queue.isEmpty() queue.isEmpty() queue.isEmpty queue {
      P p = queue.deQueue();
      if (p.t > q) {
        sum += q;
        queue.enQueue(p.s, p.t - q);
      } else {
        sum += p.t;
        System.out.println(p.s + " " + sum);
      }
    } P p = queue.deQueue(); p queue.deQueue() queue.deQueue queue if (p.t > q) {
        sum += q;
        queue.enQueue(p.s, p.t - q);
      } else {
        sum += p.t;
        System.out.println(p.s + " " + sum);
      } p.t > q p.t p p.t q {
        sum += q;
        queue.enQueue(p.s, p.t - q);
      } sum += q sum q queue.enQueue(p.s, p.t - q) queue.enQueue queue p.s p p.s p.t - q p.t p p.t q {
        sum += p.t;
        System.out.println(p.s + " " + sum);
      } sum += p.t sum p.t p p.t System.out.println(p.s + " " + sum) System.out.println System.out System System.out p.s + " " + sum p.s + " " + sum p.s p p.s " " sum sc.close() sc.close sc String[] args args class P {
  public String s;
  public int t;

  public P(String s, int t) {
    this.s = s;
    this.t = t;
  }
} P public String s; s public int t; t public P(String s, int t) {
    this.s = s;
    this.t = t;
  } P {
    this.s = s;
    this.t = t;
  } this.s = s this.s this this.s s this.t = t this.t this this.t t String s s int t t class Queue {
  private int head = 0;
  private int tail = 0;
  private P[] p;

  public Queue(int n) {
    this.p = new P[n + 1];
  }

  public boolean isEmpty() {
    return this.head == this.tail;
  }

  public boolean isFull() {
    return this.head == (this.tail + 1) % this.p.length;
  }

  public void enQueue(String s, int t) throws Exception {
    if (this.isFull()) {
      throw new Exception();
    }

    this.p[this.tail] = new P(s, t);

    if (this.tail + 1 == this.p.length) {
      this.tail = 0;
    } else {
      this.tail++;
    }
  }

  public P deQueue() throws Exception {
    if (this.isEmpty()) {
      throw new Exception();
    }

    P p = this.p[this.head];

    if (this.head + 1 == this.p.length) {
      this.head = 0;
    } else {
      this.head++;
    }

    return p;
  }
} Queue private int head = 0; head 0 private int tail = 0; tail 0 private P[] p; p public Queue(int n) {
    this.p = new P[n + 1];
  } Queue {
    this.p = new P[n + 1];
  } this.p = new P[n + 1] this.p this this.p new P[n + 1] n + 1 n 1 int n n public boolean isEmpty() {
    return this.head == this.tail;
  } isEmpty {
    return this.head == this.tail;
  } return this.head == this.tail; this.head == this.tail this.head this this.head this.tail this this.tail public boolean isFull() {
    return this.head == (this.tail + 1) % this.p.length;
  } isFull {
    return this.head == (this.tail + 1) % this.p.length;
  } return this.head == (this.tail + 1) % this.p.length; this.head == (this.tail + 1) % this.p.length this.head this this.head (this.tail + 1) % this.p.length (this.tail + 1) this.tail this this.tail 1 this.p.length this.p this this.p this.p.length public void enQueue(String s, int t) throws Exception {
    if (this.isFull()) {
      throw new Exception();
    }

    this.p[this.tail] = new P(s, t);

    if (this.tail + 1 == this.p.length) {
      this.tail = 0;
    } else {
      this.tail++;
    }
  } enQueue {
    if (this.isFull()) {
      throw new Exception();
    }

    this.p[this.tail] = new P(s, t);

    if (this.tail + 1 == this.p.length) {
      this.tail = 0;
    } else {
      this.tail++;
    }
  } if (this.isFull()) {
      throw new Exception();
    } this.isFull() this.isFull this {
      throw new Exception();
    } throw new Exception(); new Exception() this.p[this.tail] = new P(s, t) this.p[this.tail] this.p this this.p this.tail this this.tail new P(s, t) if (this.tail + 1 == this.p.length) {
      this.tail = 0;
    } else {
      this.tail++;
    } this.tail + 1 == this.p.length this.tail + 1 this.tail this this.tail 1 this.p.length this.p this this.p this.p.length {
      this.tail = 0;
    } this.tail = 0 this.tail this this.tail 0 {
      this.tail++;
    } this.tail++ this.tail this this.tail String s s int t t public P deQueue() throws Exception {
    if (this.isEmpty()) {
      throw new Exception();
    }

    P p = this.p[this.head];

    if (this.head + 1 == this.p.length) {
      this.head = 0;
    } else {
      this.head++;
    }

    return p;
  } deQueue {
    if (this.isEmpty()) {
      throw new Exception();
    }

    P p = this.p[this.head];

    if (this.head + 1 == this.p.length) {
      this.head = 0;
    } else {
      this.head++;
    }

    return p;
  } if (this.isEmpty()) {
      throw new Exception();
    } this.isEmpty() this.isEmpty this {
      throw new Exception();
    } throw new Exception(); new Exception() P p = this.p[this.head]; p this.p[this.head] this.p this this.p this.head this this.head if (this.head + 1 == this.p.length) {
      this.head = 0;
    } else {
      this.head++;
    } this.head + 1 == this.p.length this.head + 1 this.head this this.head 1 this.p.length this.p this this.p this.p.length {
      this.head = 0;
    } this.head = 0 this.head this this.head 0 {
      this.head++;
    } this.head++ this.head this this.head return p; p public class Main {
  static Scanner sc = new Scanner(System.in);

  public static void main(String[] args) throws Exception {
    int n = sc.nextInt();
    int q = sc.nextInt();

    Queue queue = new Queue(n);

    String s;
    int t;
    for (int i = 0; i < n; i++) {
      s = sc.next();
      t = sc.nextInt();

      queue.enQueue(s, t);
    }

    int sum = 0;
    while (!queue.isEmpty()) {
      P p = queue.deQueue();
      if (p.t > q) {
        sum += q;
        queue.enQueue(p.s, p.t - q);
      } else {
        sum += p.t;
        System.out.println(p.s + " " + sum);
      }
    }

    sc.close();
  }
} public class Main {
  static Scanner sc = new Scanner(System.in);

  public static void main(String[] args) throws Exception {
    int n = sc.nextInt();
    int q = sc.nextInt();

    Queue queue = new Queue(n);

    String s;
    int t;
    for (int i = 0; i < n; i++) {
      s = sc.next();
      t = sc.nextInt();

      queue.enQueue(s, t);
    }

    int sum = 0;
    while (!queue.isEmpty()) {
      P p = queue.deQueue();
      if (p.t > q) {
        sum += q;
        queue.enQueue(p.s, p.t - q);
      } else {
        sum += p.t;
        System.out.println(p.s + " " + sum);
      }
    }

    sc.close();
  }
} Main
import java.nio.*;
import java.util.*;

public class Main {
  static Scanner sc = new Scanner(System.in);

  public static void main(String[] args) throws Exception {
    int n = sc.nextInt();
    int q = sc.nextInt();

    Queue queue = new Queue(n);

    String s;
    int t;
    for (int i = 0; i < n; i++) {
      s = sc.next();
      t = sc.nextInt();

      queue.enQueue(s, t);
    }

    int sum = 0;
    while (!queue.isEmpty()) {
      P p = queue.deQueue();
      if (p.t > q) {
        sum += q;
        queue.enQueue(p.s, p.t - q);
      } else {
        sum += p.t;
        System.out.println(p.s + " " + sum);
      }
    }

    sc.close();
  }
}

class P {
  public String s;
  public int t;

  public P(String s, int t) {
    this.s = s;
    this.t = t;
  }
}

class Queue {
  private int head = 0;
  private int tail = 0;
  private P[] p;

  public Queue(int n) {
    this.p = new P[n + 1];
  }

  public boolean isEmpty() {
    return this.head == this.tail;
  }

  public boolean isFull() {
    return this.head == (this.tail + 1) % this.p.length;
  }

  public void enQueue(String s, int t) throws Exception {
    if (this.isFull()) {
      throw new Exception();
    }

    this.p[this.tail] = new P(s, t);

    if (this.tail + 1 == this.p.length) {
      this.tail = 0;
    } else {
      this.tail++;
    }
  }

  public P deQueue() throws Exception {
    if (this.isEmpty()) {
      throw new Exception();
    }

    P p = this.p[this.head];

    if (this.head + 1 == this.p.length) {
      this.head = 0;
    } else {
      this.head++;
    }

    return p;
  }
}
