import java.util.Scanner;

class Queue{
  Process[] a = new Process[100001];
  int top;

  Queue(){
    top = 0;
  }

  void enqueue(Process p){
    a[++top] = p;
  }

  Process dequeue(){
    Process p = new Process(a[1]);
    for(int i = 1; i < top; i++){
      a[i] = a[i+1];
    }
    top--;
    return p;
  }

  boolean isFull(){
    if(top == 100000)
      return true;
    else
      return false;
  }

  boolean isEmpty(){
    if(top == 0)
      return true;
    else
      return false;
  }

}

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{
  Process[] a = new Process[100001];
  int top;

  Queue(){
    top = 0;
  }

  void enqueue(Process p){
    a[++top] = p;
  }

  Process dequeue(){
    Process p = new Process(a[1]);
    for(int i = 1; i < top; i++){
      a[i] = a[i+1];
    }
    top--;
    return p;
  }

  boolean isFull(){
    if(top == 100000)
      return true;
    else
      return false;
  }

  boolean isEmpty(){
    if(top == 0)
      return true;
    else
      return false;
  }

} Queue Process[] a = new Process[100001]; a new Process[100001] 100001 int top; top Queue(){
    top = 0;
  } Queue {
    top = 0;
  } top = 0 top 0 void enqueue(Process p){
    a[++top] = p;
  } enqueue {
    a[++top] = p;
  } a[++top] = p a[++top] a ++top top p Process p p Process dequeue(){
    Process p = new Process(a[1]);
    for(int i = 1; i < top; i++){
      a[i] = a[i+1];
    }
    top--;
    return p;
  } dequeue {
    Process p = new Process(a[1]);
    for(int i = 1; i < top; i++){
      a[i] = a[i+1];
    }
    top--;
    return p;
  } Process p = new Process(a[1]); p new Process(a[1]) for(int i = 1; i < top; i++){
      a[i] = a[i+1];
    } int i = 1; int i = 1; i 1 i < top i top i++ i++ i {
      a[i] = a[i+1];
    } {
      a[i] = a[i+1];
    } a[i] = a[i+1] a[i] a i a[i+1] a i+1 i 1 top-- top return p; p boolean isFull(){
    if(top == 100000)
      return true;
    else
      return false;
  } isFull {
    if(top == 100000)
      return true;
    else
      return false;
  } if(top == 100000)
      return true;
    else
      return false; top == 100000 top 100000 return true; true return false; false boolean isEmpty(){
    if(top == 0)
      return true;
    else
      return false;
  } isEmpty {
    if(top == 0)
      return true;
    else
      return false;
  } if(top == 0)
      return true;
    else
      return false; top == 0 top 0 return true; true return false; false 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{
  Process[] a = new Process[100001];
  int top;

  Queue(){
    top = 0;
  }

  void enqueue(Process p){
    a[++top] = p;
  }

  Process dequeue(){
    Process p = new Process(a[1]);
    for(int i = 1; i < top; i++){
      a[i] = a[i+1];
    }
    top--;
    return p;
  }

  boolean isFull(){
    if(top == 100000)
      return true;
    else
      return false;
  }

  boolean isEmpty(){
    if(top == 0)
      return true;
    else
      return false;
  }

}

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;
      }
    }

  }
}