import java.util.*;

class Main {

  static int LENGTH = 100000;
  static int [] queue = new int[LENGTH];
  static String [] name = new String[LENGTH];
  static int tail = 0;
  static int head = 0;
  public static void main(String args[]){
    //宣言
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int max = sc.nextInt();
    int out;
    int count=0;
    //input
    for(int i = 0; i<n; i++){
      name[i] = sc.next();
      queue[i] = sc.nextInt();
      tail++;
    }
    //loop
    while(isEmpty() != true){
      out = dequeue();
      if((out-max)>0){
        enqueue(out-max);//
        count += max;
      }else{
        count += out;
        System.out.println(name[head-1]+" "+count);
      }
    }
  }
  //enqueue
  static void enqueue(int num){
    queue[tail] = num;
    if(head != 0){
    name[tail] = name[head-1];//
  }else{
    name[tail] = name[LENGTH-1];
  }
    if(tail == LENGTH-1){
      tail=0;
    }else{
      tail++;
    }
  }
  //dequeue
  static int dequeue(){
    if(head == LENGTH-1){
      head = 0;
      return queue[LENGTH-1];
    }
    return queue[head++];
  }
  //キューの中身がなくなったかどうかの判定
  static boolean isEmpty(){
    return head == tail;
  }

} import java.util.*; util.* java class Main {

  static int LENGTH = 100000;
  static int [] queue = new int[LENGTH];
  static String [] name = new String[LENGTH];
  static int tail = 0;
  static int head = 0;
  public static void main(String args[]){
    //宣言
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int max = sc.nextInt();
    int out;
    int count=0;
    //input
    for(int i = 0; i<n; i++){
      name[i] = sc.next();
      queue[i] = sc.nextInt();
      tail++;
    }
    //loop
    while(isEmpty() != true){
      out = dequeue();
      if((out-max)>0){
        enqueue(out-max);//
        count += max;
      }else{
        count += out;
        System.out.println(name[head-1]+" "+count);
      }
    }
  }
  //enqueue
  static void enqueue(int num){
    queue[tail] = num;
    if(head != 0){
    name[tail] = name[head-1];//
  }else{
    name[tail] = name[LENGTH-1];
  }
    if(tail == LENGTH-1){
      tail=0;
    }else{
      tail++;
    }
  }
  //dequeue
  static int dequeue(){
    if(head == LENGTH-1){
      head = 0;
      return queue[LENGTH-1];
    }
    return queue[head++];
  }
  //キューの中身がなくなったかどうかの判定
  static boolean isEmpty(){
    return head == tail;
  }

} Main static int LENGTH = 100000; LENGTH 100000 static int [] queue = new int[LENGTH]; queue new int[LENGTH] LENGTH static String [] name = new String[LENGTH]; name new String[LENGTH] LENGTH static int tail = 0; tail 0 static int head = 0; head 0 public static void main(String args[]){
    //宣言
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int max = sc.nextInt();
    int out;
    int count=0;
    //input
    for(int i = 0; i<n; i++){
      name[i] = sc.next();
      queue[i] = sc.nextInt();
      tail++;
    }
    //loop
    while(isEmpty() != true){
      out = dequeue();
      if((out-max)>0){
        enqueue(out-max);//
        count += max;
      }else{
        count += out;
        System.out.println(name[head-1]+" "+count);
      }
    }
  } main {
    //宣言
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int max = sc.nextInt();
    int out;
    int count=0;
    //input
    for(int i = 0; i<n; i++){
      name[i] = sc.next();
      queue[i] = sc.nextInt();
      tail++;
    }
    //loop
    while(isEmpty() != true){
      out = dequeue();
      if((out-max)>0){
        enqueue(out-max);//
        count += max;
      }else{
        count += out;
        System.out.println(name[head-1]+" "+count);
      }
    }
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int max = sc.nextInt(); max sc.nextInt() sc.nextInt sc int out; out int count=0; count 0 for(int i = 0; i<n; i++){
      name[i] = sc.next();
      queue[i] = sc.nextInt();
      tail++;
    } int i = 0; int i = 0; i 0 i<n i n i++ i++ i {
      name[i] = sc.next();
      queue[i] = sc.nextInt();
      tail++;
    } {
      name[i] = sc.next();
      queue[i] = sc.nextInt();
      tail++;
    } name[i] = sc.next() name[i] name i sc.next() sc.next sc queue[i] = sc.nextInt() queue[i] queue i sc.nextInt() sc.nextInt sc tail++ tail while(isEmpty() != true){
      out = dequeue();
      if((out-max)>0){
        enqueue(out-max);//
        count += max;
      }else{
        count += out;
        System.out.println(name[head-1]+" "+count);
      }
    } isEmpty() != true isEmpty() isEmpty true {
      out = dequeue();
      if((out-max)>0){
        enqueue(out-max);//
        count += max;
      }else{
        count += out;
        System.out.println(name[head-1]+" "+count);
      }
    } out = dequeue() out dequeue() dequeue if((out-max)>0){
        enqueue(out-max);//
        count += max;
      }else{
        count += out;
        System.out.println(name[head-1]+" "+count);
      } (out-max)>0 (out-max) out max 0 {
        enqueue(out-max);//
        count += max;
      } enqueue(out-max) enqueue out-max out max count += max count max {
        count += out;
        System.out.println(name[head-1]+" "+count);
      } count += out count out System.out.println(name[head-1]+" "+count) System.out.println System.out System System.out name[head-1]+" "+count name[head-1]+" "+count name[head-1] name head-1 head 1 " " count String args[] args //enqueue
  static void enqueue(int num){
    queue[tail] = num;
    if(head != 0){
    name[tail] = name[head-1];//
  }else{
    name[tail] = name[LENGTH-1];
  }
    if(tail == LENGTH-1){
      tail=0;
    }else{
      tail++;
    }
  } enqueue {
    queue[tail] = num;
    if(head != 0){
    name[tail] = name[head-1];//
  }else{
    name[tail] = name[LENGTH-1];
  }
    if(tail == LENGTH-1){
      tail=0;
    }else{
      tail++;
    }
  } queue[tail] = num queue[tail] queue tail num if(head != 0){
    name[tail] = name[head-1];//
  }else{
    name[tail] = name[LENGTH-1];
  } head != 0 head 0 {
    name[tail] = name[head-1];//
  } name[tail] = name[head-1] name[tail] name tail name[head-1] name head-1 head 1 {
    name[tail] = name[LENGTH-1];
  } name[tail] = name[LENGTH-1] name[tail] name tail name[LENGTH-1] name LENGTH-1 LENGTH 1 if(tail == LENGTH-1){
      tail=0;
    }else{
      tail++;
    } tail == LENGTH-1 tail LENGTH-1 LENGTH 1 {
      tail=0;
    } tail=0 tail 0 {
      tail++;
    } tail++ tail int num num //dequeue
  static int dequeue(){
    if(head == LENGTH-1){
      head = 0;
      return queue[LENGTH-1];
    }
    return queue[head++];
  } dequeue {
    if(head == LENGTH-1){
      head = 0;
      return queue[LENGTH-1];
    }
    return queue[head++];
  } if(head == LENGTH-1){
      head = 0;
      return queue[LENGTH-1];
    } head == LENGTH-1 head LENGTH-1 LENGTH 1 {
      head = 0;
      return queue[LENGTH-1];
    } head = 0 head 0 return queue[LENGTH-1]; queue[LENGTH-1] queue LENGTH-1 LENGTH 1 return queue[head++]; queue[head++] queue head++ head //キューの中身がなくなったかどうかの判定
  static boolean isEmpty(){
    return head == tail;
  } isEmpty {
    return head == tail;
  } return head == tail; head == tail head tail
import java.util.*;

class Main {

  static int LENGTH = 100000;
  static int [] queue = new int[LENGTH];
  static String [] name = new String[LENGTH];
  static int tail = 0;
  static int head = 0;
  public static void main(String args[]){
    //宣言
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int max = sc.nextInt();
    int out;
    int count=0;
    //input
    for(int i = 0; i<n; i++){
      name[i] = sc.next();
      queue[i] = sc.nextInt();
      tail++;
    }
    //loop
    while(isEmpty() != true){
      out = dequeue();
      if((out-max)>0){
        enqueue(out-max);//
        count += max;
      }else{
        count += out;
        System.out.println(name[head-1]+" "+count);
      }
    }
  }
  //enqueue
  static void enqueue(int num){
    queue[tail] = num;
    if(head != 0){
    name[tail] = name[head-1];//
  }else{
    name[tail] = name[LENGTH-1];
  }
    if(tail == LENGTH-1){
      tail=0;
    }else{
      tail++;
    }
  }
  //dequeue
  static int dequeue(){
    if(head == LENGTH-1){
      head = 0;
      return queue[LENGTH-1];
    }
    return queue[head++];
  }
  //キューの中身がなくなったかどうかの判定
  static boolean isEmpty(){
    return head == tail;
  }

}
