import java.util.*;

class process {
  private String name;
  private int time;

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

  public void setName(String name) {
    this.name = name;
  }

  public String getName() {
    return name;
  }

  public void setTime(int time) {
    this.time = time;
  }

  public int getTime() {
    return time;
  }
}


public class Main {
  int length, front, rear;
  process[] queue;

  // ??????????????????????????????????????????????????????????????????
  Main(int len) {
    queue = new process[len];
  }

  // ??????????????¨????????\???
  void enqueue(process val) {
    if (queue.length == length) {
      System.out.println("Fatal error: the queue is full.");
      System.exit(1);
    }

    queue[rear] = val;
    rear = (rear+1)%queue.length;
    length++;
  }

  // ????????????????????\???
  process dequeue() {
    if (length == 0) {
      System.out.println("Fatal error: the queue is empty.");
      System.exit(1);
    }

    process ret = queue[front];
    front = (front+1)%queue.length;
    length--;
    return ret;
  }

  // main ????????????
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int q = sc.nextInt();

    Main queue = new Main(n);
    for (int i=0; i<n; i++) {
      queue.enqueue(new process(sc.next(), Integer.parseInt(sc.next())));
    }
    Main result = new Main(n);

    int elapsed = 0;
    int n_ = n;
    while (n > 0) {
      process p = queue.dequeue();
      if (p.getTime() - q <= 0) {
        elapsed += p.getTime();
        result.enqueue(new process(p.getName(), elapsed));
        n--;
      } else {
        elapsed += q;
        queue.enqueue(new process(p.getName(), p.getTime()-q));
      }
    }

    while (n_-- > 0) {
      process r = result.dequeue();
      System.out.println(r.getName() + " " + String.valueOf(r.getTime()));
    }
  }
} import java.util.*; util.* java class process {
  private String name;
  private int time;

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

  public void setName(String name) {
    this.name = name;
  }

  public String getName() {
    return name;
  }

  public void setTime(int time) {
    this.time = time;
  }

  public int getTime() {
    return time;
  }
} 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 void setName(String name) {
    this.name = name;
  } setName {
    this.name = name;
  } this.name = name this.name this this.name name String name name public String getName() {
    return name;
  } getName {
    return name;
  } return name; name public void setTime(int time) {
    this.time = time;
  } setTime {
    this.time = time;
  } this.time = time this.time this this.time time int time time public int getTime() {
    return time;
  } getTime {
    return time;
  } return time; time public class Main {
  int length, front, rear;
  process[] queue;

  // ??????????????????????????????????????????????????????????????????
  Main(int len) {
    queue = new process[len];
  }

  // ??????????????¨????????\???
  void enqueue(process val) {
    if (queue.length == length) {
      System.out.println("Fatal error: the queue is full.");
      System.exit(1);
    }

    queue[rear] = val;
    rear = (rear+1)%queue.length;
    length++;
  }

  // ????????????????????\???
  process dequeue() {
    if (length == 0) {
      System.out.println("Fatal error: the queue is empty.");
      System.exit(1);
    }

    process ret = queue[front];
    front = (front+1)%queue.length;
    length--;
    return ret;
  }

  // main ????????????
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int q = sc.nextInt();

    Main queue = new Main(n);
    for (int i=0; i<n; i++) {
      queue.enqueue(new process(sc.next(), Integer.parseInt(sc.next())));
    }
    Main result = new Main(n);

    int elapsed = 0;
    int n_ = n;
    while (n > 0) {
      process p = queue.dequeue();
      if (p.getTime() - q <= 0) {
        elapsed += p.getTime();
        result.enqueue(new process(p.getName(), elapsed));
        n--;
      } else {
        elapsed += q;
        queue.enqueue(new process(p.getName(), p.getTime()-q));
      }
    }

    while (n_-- > 0) {
      process r = result.dequeue();
      System.out.println(r.getName() + " " + String.valueOf(r.getTime()));
    }
  }
} Main int length length front front rear; rear process[] queue; queue // ??????????????????????????????????????????????????????????????????
  Main(int len) {
    queue = new process[len];
  } Main {
    queue = new process[len];
  } queue = new process[len] queue new process[len] len int len len // ??????????????¨????????\???
  void enqueue(process val) {
    if (queue.length == length) {
      System.out.println("Fatal error: the queue is full.");
      System.exit(1);
    }

    queue[rear] = val;
    rear = (rear+1)%queue.length;
    length++;
  } enqueue {
    if (queue.length == length) {
      System.out.println("Fatal error: the queue is full.");
      System.exit(1);
    }

    queue[rear] = val;
    rear = (rear+1)%queue.length;
    length++;
  } if (queue.length == length) {
      System.out.println("Fatal error: the queue is full.");
      System.exit(1);
    } queue.length == length queue.length queue queue.length length {
      System.out.println("Fatal error: the queue is full.");
      System.exit(1);
    } System.out.println("Fatal error: the queue is full.") System.out.println System.out System System.out "Fatal error: the queue is full." System.exit(1) System.exit System 1 queue[rear] = val queue[rear] queue rear val rear = (rear+1)%queue.length rear (rear+1)%queue.length (rear+1) rear 1 queue.length queue queue.length length++ length process val val // ????????????????????\???
  process dequeue() {
    if (length == 0) {
      System.out.println("Fatal error: the queue is empty.");
      System.exit(1);
    }

    process ret = queue[front];
    front = (front+1)%queue.length;
    length--;
    return ret;
  } dequeue {
    if (length == 0) {
      System.out.println("Fatal error: the queue is empty.");
      System.exit(1);
    }

    process ret = queue[front];
    front = (front+1)%queue.length;
    length--;
    return ret;
  } if (length == 0) {
      System.out.println("Fatal error: the queue is empty.");
      System.exit(1);
    } length == 0 length 0 {
      System.out.println("Fatal error: the queue is empty.");
      System.exit(1);
    } System.out.println("Fatal error: the queue is empty.") System.out.println System.out System System.out "Fatal error: the queue is empty." System.exit(1) System.exit System 1 process ret = queue[front]; ret queue[front] queue front front = (front+1)%queue.length front (front+1)%queue.length (front+1) front 1 queue.length queue queue.length length-- length return ret; ret // main ????????????
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int q = sc.nextInt();

    Main queue = new Main(n);
    for (int i=0; i<n; i++) {
      queue.enqueue(new process(sc.next(), Integer.parseInt(sc.next())));
    }
    Main result = new Main(n);

    int elapsed = 0;
    int n_ = n;
    while (n > 0) {
      process p = queue.dequeue();
      if (p.getTime() - q <= 0) {
        elapsed += p.getTime();
        result.enqueue(new process(p.getName(), elapsed));
        n--;
      } else {
        elapsed += q;
        queue.enqueue(new process(p.getName(), p.getTime()-q));
      }
    }

    while (n_-- > 0) {
      process r = result.dequeue();
      System.out.println(r.getName() + " " + String.valueOf(r.getTime()));
    }
  } main {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int q = sc.nextInt();

    Main queue = new Main(n);
    for (int i=0; i<n; i++) {
      queue.enqueue(new process(sc.next(), Integer.parseInt(sc.next())));
    }
    Main result = new Main(n);

    int elapsed = 0;
    int n_ = n;
    while (n > 0) {
      process p = queue.dequeue();
      if (p.getTime() - q <= 0) {
        elapsed += p.getTime();
        result.enqueue(new process(p.getName(), elapsed));
        n--;
      } else {
        elapsed += q;
        queue.enqueue(new process(p.getName(), p.getTime()-q));
      }
    }

    while (n_-- > 0) {
      process r = result.dequeue();
      System.out.println(r.getName() + " " + String.valueOf(r.getTime()));
    }
  } 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 Main queue = new Main(n); queue new Main(n) for (int i=0; i<n; i++) {
      queue.enqueue(new process(sc.next(), Integer.parseInt(sc.next())));
    } int i=0; int i=0; i 0 i<n i n i++ i++ i {
      queue.enqueue(new process(sc.next(), Integer.parseInt(sc.next())));
    } {
      queue.enqueue(new process(sc.next(), Integer.parseInt(sc.next())));
    } queue.enqueue(new process(sc.next(), Integer.parseInt(sc.next()))) queue.enqueue queue new process(sc.next(), Integer.parseInt(sc.next())) Main result = new Main(n); result new Main(n) int elapsed = 0; elapsed 0 int n_ = n; n_ n while (n > 0) {
      process p = queue.dequeue();
      if (p.getTime() - q <= 0) {
        elapsed += p.getTime();
        result.enqueue(new process(p.getName(), elapsed));
        n--;
      } else {
        elapsed += q;
        queue.enqueue(new process(p.getName(), p.getTime()-q));
      }
    } n > 0 n 0 {
      process p = queue.dequeue();
      if (p.getTime() - q <= 0) {
        elapsed += p.getTime();
        result.enqueue(new process(p.getName(), elapsed));
        n--;
      } else {
        elapsed += q;
        queue.enqueue(new process(p.getName(), p.getTime()-q));
      }
    } process p = queue.dequeue(); p queue.dequeue() queue.dequeue queue if (p.getTime() - q <= 0) {
        elapsed += p.getTime();
        result.enqueue(new process(p.getName(), elapsed));
        n--;
      } else {
        elapsed += q;
        queue.enqueue(new process(p.getName(), p.getTime()-q));
      } p.getTime() - q <= 0 p.getTime() - q p.getTime() p.getTime p q 0 {
        elapsed += p.getTime();
        result.enqueue(new process(p.getName(), elapsed));
        n--;
      } elapsed += p.getTime() elapsed p.getTime() p.getTime p result.enqueue(new process(p.getName(), elapsed)) result.enqueue result new process(p.getName(), elapsed) n-- n {
        elapsed += q;
        queue.enqueue(new process(p.getName(), p.getTime()-q));
      } elapsed += q elapsed q queue.enqueue(new process(p.getName(), p.getTime()-q)) queue.enqueue queue new process(p.getName(), p.getTime()-q) while (n_-- > 0) {
      process r = result.dequeue();
      System.out.println(r.getName() + " " + String.valueOf(r.getTime()));
    } n_-- > 0 n_-- n_ 0 {
      process r = result.dequeue();
      System.out.println(r.getName() + " " + String.valueOf(r.getTime()));
    } process r = result.dequeue(); r result.dequeue() result.dequeue result System.out.println(r.getName() + " " + String.valueOf(r.getTime())) System.out.println System.out System System.out r.getName() + " " + String.valueOf(r.getTime()) r.getName() + " " + String.valueOf(r.getTime()) r.getName() r.getName r " " String.valueOf(r.getTime()) String.valueOf String r.getTime() r.getTime r String[] args args public class Main {
  int length, front, rear;
  process[] queue;

  // ??????????????????????????????????????????????????????????????????
  Main(int len) {
    queue = new process[len];
  }

  // ??????????????¨????????\???
  void enqueue(process val) {
    if (queue.length == length) {
      System.out.println("Fatal error: the queue is full.");
      System.exit(1);
    }

    queue[rear] = val;
    rear = (rear+1)%queue.length;
    length++;
  }

  // ????????????????????\???
  process dequeue() {
    if (length == 0) {
      System.out.println("Fatal error: the queue is empty.");
      System.exit(1);
    }

    process ret = queue[front];
    front = (front+1)%queue.length;
    length--;
    return ret;
  }

  // main ????????????
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int q = sc.nextInt();

    Main queue = new Main(n);
    for (int i=0; i<n; i++) {
      queue.enqueue(new process(sc.next(), Integer.parseInt(sc.next())));
    }
    Main result = new Main(n);

    int elapsed = 0;
    int n_ = n;
    while (n > 0) {
      process p = queue.dequeue();
      if (p.getTime() - q <= 0) {
        elapsed += p.getTime();
        result.enqueue(new process(p.getName(), elapsed));
        n--;
      } else {
        elapsed += q;
        queue.enqueue(new process(p.getName(), p.getTime()-q));
      }
    }

    while (n_-- > 0) {
      process r = result.dequeue();
      System.out.println(r.getName() + " " + String.valueOf(r.getTime()));
    }
  }
} public class Main {
  int length, front, rear;
  process[] queue;

  // ??????????????????????????????????????????????????????????????????
  Main(int len) {
    queue = new process[len];
  }

  // ??????????????¨????????\???
  void enqueue(process val) {
    if (queue.length == length) {
      System.out.println("Fatal error: the queue is full.");
      System.exit(1);
    }

    queue[rear] = val;
    rear = (rear+1)%queue.length;
    length++;
  }

  // ????????????????????\???
  process dequeue() {
    if (length == 0) {
      System.out.println("Fatal error: the queue is empty.");
      System.exit(1);
    }

    process ret = queue[front];
    front = (front+1)%queue.length;
    length--;
    return ret;
  }

  // main ????????????
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int q = sc.nextInt();

    Main queue = new Main(n);
    for (int i=0; i<n; i++) {
      queue.enqueue(new process(sc.next(), Integer.parseInt(sc.next())));
    }
    Main result = new Main(n);

    int elapsed = 0;
    int n_ = n;
    while (n > 0) {
      process p = queue.dequeue();
      if (p.getTime() - q <= 0) {
        elapsed += p.getTime();
        result.enqueue(new process(p.getName(), elapsed));
        n--;
      } else {
        elapsed += q;
        queue.enqueue(new process(p.getName(), p.getTime()-q));
      }
    }

    while (n_-- > 0) {
      process r = result.dequeue();
      System.out.println(r.getName() + " " + String.valueOf(r.getTime()));
    }
  }
} Main
import java.util.*;

class process {
  private String name;
  private int time;

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

  public void setName(String name) {
    this.name = name;
  }

  public String getName() {
    return name;
  }

  public void setTime(int time) {
    this.time = time;
  }

  public int getTime() {
    return time;
  }
}


public class Main {
  int length, front, rear;
  process[] queue;

  // ??????????????????????????????????????????????????????????????????
  Main(int len) {
    queue = new process[len];
  }

  // ??????????????¨????????\???
  void enqueue(process val) {
    if (queue.length == length) {
      System.out.println("Fatal error: the queue is full.");
      System.exit(1);
    }

    queue[rear] = val;
    rear = (rear+1)%queue.length;
    length++;
  }

  // ????????????????????\???
  process dequeue() {
    if (length == 0) {
      System.out.println("Fatal error: the queue is empty.");
      System.exit(1);
    }

    process ret = queue[front];
    front = (front+1)%queue.length;
    length--;
    return ret;
  }

  // main ????????????
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int q = sc.nextInt();

    Main queue = new Main(n);
    for (int i=0; i<n; i++) {
      queue.enqueue(new process(sc.next(), Integer.parseInt(sc.next())));
    }
    Main result = new Main(n);

    int elapsed = 0;
    int n_ = n;
    while (n > 0) {
      process p = queue.dequeue();
      if (p.getTime() - q <= 0) {
        elapsed += p.getTime();
        result.enqueue(new process(p.getName(), elapsed));
        n--;
      } else {
        elapsed += q;
        queue.enqueue(new process(p.getName(), p.getTime()-q));
      }
    }

    while (n_-- > 0) {
      process r = result.dequeue();
      System.out.println(r.getName() + " " + String.valueOf(r.getTime()));
    }
  }
}