import java.util.Scanner;

class Queue{
  static int NUM = 100000;
  Process[] a = new Process[NUM];
  int head;
  int tail;

  Queue(){
    head = 0;
    tail = 0;
  }

  void enqueue(Process p){
    if(!this.isFull()){
      a[tail] = p;
      if(tail == NUM - 1)
        tail = 0;
      else
        tail++;
      }
  }

  Process dequeue(){
    if(!this.isEmpty()){
      if(head == NUM - 1)
        head = 0;
      else
        head++;

      if(head == 0)
        return a[NUM - 1];
      else
        return a[head-1];
    }
    else
      return null;
  }

  boolean isFull(){
    return (head == 0 && tail == NUM-1) || (head == tail+1);
  }

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

}

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

public class Main{
  public static void main(String[] args){
    Scanner stdIn = new Scanner(System.in);
    int n = stdIn.nextInt();
    int q = stdIn.nextInt();
    Queue queue = new Queue();

    for(int i = 0; i < n; i++){
      String name = stdIn.next();
      int time = stdIn.nextInt();
      queue.enqueue(new Process(name, time));
    }

    int time_sum = 0;
    while(!queue.isEmpty()){
      Process p = queue.dequeue();
      p.time -= q;
      if(p.time <= 0){
        time_sum += (q + p.time);
        System.out.println(p.name + " " + (time_sum));
      }
      else{
        queue.enqueue(p);
        time_sum += q;
      }
    }

  }
} import java.util.Scanner; Scanner java.util class Queue{
  static int NUM = 100000;
  Process[] a = new Process[NUM];
  int head;
  int tail;

  Queue(){
    head = 0;
    tail = 0;
  }

  void enqueue(Process p){
    if(!this.isFull()){
      a[tail] = p;
      if(tail == NUM - 1)
        tail = 0;
      else
        tail++;
      }
  }

  Process dequeue(){
    if(!this.isEmpty()){
      if(head == NUM - 1)
        head = 0;
      else
        head++;

      if(head == 0)
        return a[NUM - 1];
      else
        return a[head-1];
    }
    else
      return null;
  }

  boolean isFull(){
    return (head == 0 && tail == NUM-1) || (head == tail+1);
  }

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

} Queue static int NUM = 100000; NUM 100000 Process[] a = new Process[NUM]; a new Process[NUM] NUM int head; head int tail; tail Queue(){
    head = 0;
    tail = 0;
  } Queue {
    head = 0;
    tail = 0;
  } head = 0 head 0 tail = 0 tail 0 void enqueue(Process p){
    if(!this.isFull()){
      a[tail] = p;
      if(tail == NUM - 1)
        tail = 0;
      else
        tail++;
      }
  } enqueue {
    if(!this.isFull()){
      a[tail] = p;
      if(tail == NUM - 1)
        tail = 0;
      else
        tail++;
      }
  } if(!this.isFull()){
      a[tail] = p;
      if(tail == NUM - 1)
        tail = 0;
      else
        tail++;
      } !this.isFull() this.isFull() this.isFull this {
      a[tail] = p;
      if(tail == NUM - 1)
        tail = 0;
      else
        tail++;
      } a[tail] = p a[tail] a tail p if(tail == NUM - 1)
        tail = 0;
      else
        tail++; tail == NUM - 1 tail NUM - 1 NUM 1 tail = 0 tail 0 tail++ tail Process p p Process dequeue(){
    if(!this.isEmpty()){
      if(head == NUM - 1)
        head = 0;
      else
        head++;

      if(head == 0)
        return a[NUM - 1];
      else
        return a[head-1];
    }
    else
      return null;
  } dequeue {
    if(!this.isEmpty()){
      if(head == NUM - 1)
        head = 0;
      else
        head++;

      if(head == 0)
        return a[NUM - 1];
      else
        return a[head-1];
    }
    else
      return null;
  } if(!this.isEmpty()){
      if(head == NUM - 1)
        head = 0;
      else
        head++;

      if(head == 0)
        return a[NUM - 1];
      else
        return a[head-1];
    }
    else
      return null; !this.isEmpty() this.isEmpty() this.isEmpty this {
      if(head == NUM - 1)
        head = 0;
      else
        head++;

      if(head == 0)
        return a[NUM - 1];
      else
        return a[head-1];
    } if(head == NUM - 1)
        head = 0;
      else
        head++; head == NUM - 1 head NUM - 1 NUM 1 head = 0 head 0 head++ head if(head == 0)
        return a[NUM - 1];
      else
        return a[head-1]; head == 0 head 0 return a[NUM - 1]; a[NUM - 1] a NUM - 1 NUM 1 return a[head-1]; a[head-1] a head-1 head 1 return null; null boolean isFull(){
    return (head == 0 && tail == NUM-1) || (head == tail+1);
  } isFull {
    return (head == 0 && tail == NUM-1) || (head == tail+1);
  } return (head == 0 && tail == NUM-1) || (head == tail+1); (head == 0 && tail == NUM-1) || (head == tail+1) (head == 0 && tail == NUM-1) head == 0 head 0 tail == NUM-1 tail NUM-1 NUM 1 (head == tail+1) head tail+1 tail 1 boolean isEmpty(){
    return head == tail;
  } isEmpty {
    return head == tail;
  } return head == tail; head == tail head tail class Process{
  String name;
  int time;
  Process(String name, int time){
    this.name = name;
    this.time = time;
  }
  Process(Process p){
    this.name = p.name;
    this.time = p.time;
  }
} Process String name; name int time; time 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 Process(Process p){
    this.name = p.name;
    this.time = p.time;
  } Process {
    this.name = p.name;
    this.time = p.time;
  } this.name = p.name this.name this this.name p.name p p.name this.time = p.time this.time this this.time p.time p p.time Process p p public class Main{
  public static void main(String[] args){
    Scanner stdIn = new Scanner(System.in);
    int n = stdIn.nextInt();
    int q = stdIn.nextInt();
    Queue queue = new Queue();

    for(int i = 0; i < n; i++){
      String name = stdIn.next();
      int time = stdIn.nextInt();
      queue.enqueue(new Process(name, time));
    }

    int time_sum = 0;
    while(!queue.isEmpty()){
      Process p = queue.dequeue();
      p.time -= q;
      if(p.time <= 0){
        time_sum += (q + p.time);
        System.out.println(p.name + " " + (time_sum));
      }
      else{
        queue.enqueue(p);
        time_sum += q;
      }
    }

  }
} Main public static void main(String[] args){
    Scanner stdIn = new Scanner(System.in);
    int n = stdIn.nextInt();
    int q = stdIn.nextInt();
    Queue queue = new Queue();

    for(int i = 0; i < n; i++){
      String name = stdIn.next();
      int time = stdIn.nextInt();
      queue.enqueue(new Process(name, time));
    }

    int time_sum = 0;
    while(!queue.isEmpty()){
      Process p = queue.dequeue();
      p.time -= q;
      if(p.time <= 0){
        time_sum += (q + p.time);
        System.out.println(p.name + " " + (time_sum));
      }
      else{
        queue.enqueue(p);
        time_sum += q;
      }
    }

  } main {
    Scanner stdIn = new Scanner(System.in);
    int n = stdIn.nextInt();
    int q = stdIn.nextInt();
    Queue queue = new Queue();

    for(int i = 0; i < n; i++){
      String name = stdIn.next();
      int time = stdIn.nextInt();
      queue.enqueue(new Process(name, time));
    }

    int time_sum = 0;
    while(!queue.isEmpty()){
      Process p = queue.dequeue();
      p.time -= q;
      if(p.time <= 0){
        time_sum += (q + p.time);
        System.out.println(p.name + " " + (time_sum));
      }
      else{
        queue.enqueue(p);
        time_sum += q;
      }
    }

  } Scanner stdIn = new Scanner(System.in); stdIn new Scanner(System.in) int n = stdIn.nextInt(); n stdIn.nextInt() stdIn.nextInt stdIn int q = stdIn.nextInt(); q stdIn.nextInt() stdIn.nextInt stdIn Queue queue = new Queue(); queue new Queue() for(int i = 0; i < n; i++){
      String name = stdIn.next();
      int time = stdIn.nextInt();
      queue.enqueue(new Process(name, time));
    } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
      String name = stdIn.next();
      int time = stdIn.nextInt();
      queue.enqueue(new Process(name, time));
    } {
      String name = stdIn.next();
      int time = stdIn.nextInt();
      queue.enqueue(new Process(name, time));
    } String name = stdIn.next(); name stdIn.next() stdIn.next stdIn int time = stdIn.nextInt(); time stdIn.nextInt() stdIn.nextInt stdIn queue.enqueue(new Process(name, time)) queue.enqueue queue new Process(name, time) int time_sum = 0; time_sum 0 while(!queue.isEmpty()){
      Process p = queue.dequeue();
      p.time -= q;
      if(p.time <= 0){
        time_sum += (q + p.time);
        System.out.println(p.name + " " + (time_sum));
      }
      else{
        queue.enqueue(p);
        time_sum += q;
      }
    } !queue.isEmpty() queue.isEmpty() queue.isEmpty queue {
      Process p = queue.dequeue();
      p.time -= q;
      if(p.time <= 0){
        time_sum += (q + p.time);
        System.out.println(p.name + " " + (time_sum));
      }
      else{
        queue.enqueue(p);
        time_sum += q;
      }
    } Process p = queue.dequeue(); p queue.dequeue() queue.dequeue queue p.time -= q p.time p p.time q if(p.time <= 0){
        time_sum += (q + p.time);
        System.out.println(p.name + " " + (time_sum));
      }
      else{
        queue.enqueue(p);
        time_sum += q;
      } p.time <= 0 p.time p p.time 0 {
        time_sum += (q + p.time);
        System.out.println(p.name + " " + (time_sum));
      } time_sum += (q + p.time) time_sum (q + p.time) q p.time p p.time System.out.println(p.name + " " + (time_sum)) System.out.println System.out System System.out p.name + " " + (time_sum) p.name + " " + (time_sum) p.name p p.name " " (time_sum) {
        queue.enqueue(p);
        time_sum += q;
      } queue.enqueue(p) queue.enqueue queue p time_sum += q time_sum q String[] args args public class Main{
  public static void main(String[] args){
    Scanner stdIn = new Scanner(System.in);
    int n = stdIn.nextInt();
    int q = stdIn.nextInt();
    Queue queue = new Queue();

    for(int i = 0; i < n; i++){
      String name = stdIn.next();
      int time = stdIn.nextInt();
      queue.enqueue(new Process(name, time));
    }

    int time_sum = 0;
    while(!queue.isEmpty()){
      Process p = queue.dequeue();
      p.time -= q;
      if(p.time <= 0){
        time_sum += (q + p.time);
        System.out.println(p.name + " " + (time_sum));
      }
      else{
        queue.enqueue(p);
        time_sum += q;
      }
    }

  }
} public class Main{
  public static void main(String[] args){
    Scanner stdIn = new Scanner(System.in);
    int n = stdIn.nextInt();
    int q = stdIn.nextInt();
    Queue queue = new Queue();

    for(int i = 0; i < n; i++){
      String name = stdIn.next();
      int time = stdIn.nextInt();
      queue.enqueue(new Process(name, time));
    }

    int time_sum = 0;
    while(!queue.isEmpty()){
      Process p = queue.dequeue();
      p.time -= q;
      if(p.time <= 0){
        time_sum += (q + p.time);
        System.out.println(p.name + " " + (time_sum));
      }
      else{
        queue.enqueue(p);
        time_sum += q;
      }
    }

  }
} Main
import java.util.Scanner;

class Queue{
  static int NUM = 100000;
  Process[] a = new Process[NUM];
  int head;
  int tail;

  Queue(){
    head = 0;
    tail = 0;
  }

  void enqueue(Process p){
    if(!this.isFull()){
      a[tail] = p;
      if(tail == NUM - 1)
        tail = 0;
      else
        tail++;
      }
  }

  Process dequeue(){
    if(!this.isEmpty()){
      if(head == NUM - 1)
        head = 0;
      else
        head++;

      if(head == 0)
        return a[NUM - 1];
      else
        return a[head-1];
    }
    else
      return null;
  }

  boolean isFull(){
    return (head == 0 && tail == NUM-1) || (head == tail+1);
  }

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

}

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

public class Main{
  public static void main(String[] args){
    Scanner stdIn = new Scanner(System.in);
    int n = stdIn.nextInt();
    int q = stdIn.nextInt();
    Queue queue = new Queue();

    for(int i = 0; i < n; i++){
      String name = stdIn.next();
      int time = stdIn.nextInt();
      queue.enqueue(new Process(name, time));
    }

    int time_sum = 0;
    while(!queue.isEmpty()){
      Process p = queue.dequeue();
      p.time -= q;
      if(p.time <= 0){
        time_sum += (q + p.time);
        System.out.println(p.name + " " + (time_sum));
      }
      else{
        queue.enqueue(p);
        time_sum += q;
      }
    }

  }
}