public class Main{
  static int head, tail;
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
/*answer*/
    int n, q;
    String[] name;
    int[] time;
    int i, t, a;
    String s;

    n = sc.nextInt();
    q = sc.nextInt();
    name = new String[n + 1];
    time = new int[n + 1];
    for(i = 0;i < n;i++){
      name[i] = sc.next();
      time[i] = sc.nextInt();
    }
    head = 0;
    tail = n;
    t = 0;

    for(;!isEmpty();){
      a = dequeue(time, n);
      s = strdequeue(name, n);
      if(a > q){
        t += q;
        a -= q;
        strenqueue(name, n, s);
        enqueue(time, n, a);
      }else{
        t += a;
        System.out.println(s + " " + t);
      }
    }

    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }

  private static void enqueue(int[] time, int n, int a){
    time[tail] = a;
    tail = (tail + 1) % (n + 1);
  }

  private static void strenqueue(String[] name, int n, String s){
    name[tail] = s;
  }

  private static int dequeue(int[] time, int n){
    head = (head + 1) % (n + 1);
    return time[(n + head) % (n + 1)];
  }

  private static String strdequeue(String[] name, int n){
    return name[(head + n) % (n + 1)];
  }

  private static boolean isEmpty(){
    if(head == tail){
      return true;
    }else{
      return false;
    }
  }

} public class Main{
  static int head, tail;
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
/*answer*/
    int n, q;
    String[] name;
    int[] time;
    int i, t, a;
    String s;

    n = sc.nextInt();
    q = sc.nextInt();
    name = new String[n + 1];
    time = new int[n + 1];
    for(i = 0;i < n;i++){
      name[i] = sc.next();
      time[i] = sc.nextInt();
    }
    head = 0;
    tail = n;
    t = 0;

    for(;!isEmpty();){
      a = dequeue(time, n);
      s = strdequeue(name, n);
      if(a > q){
        t += q;
        a -= q;
        strenqueue(name, n, s);
        enqueue(time, n, a);
      }else{
        t += a;
        System.out.println(s + " " + t);
      }
    }

    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }

  private static void enqueue(int[] time, int n, int a){
    time[tail] = a;
    tail = (tail + 1) % (n + 1);
  }

  private static void strenqueue(String[] name, int n, String s){
    name[tail] = s;
  }

  private static int dequeue(int[] time, int n){
    head = (head + 1) % (n + 1);
    return time[(n + head) % (n + 1)];
  }

  private static String strdequeue(String[] name, int n){
    return name[(head + n) % (n + 1)];
  }

  private static boolean isEmpty(){
    if(head == tail){
      return true;
    }else{
      return false;
    }
  }

} Main static int head head tail; tail public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
/*answer*/
    int n, q;
    String[] name;
    int[] time;
    int i, t, a;
    String s;

    n = sc.nextInt();
    q = sc.nextInt();
    name = new String[n + 1];
    time = new int[n + 1];
    for(i = 0;i < n;i++){
      name[i] = sc.next();
      time[i] = sc.nextInt();
    }
    head = 0;
    tail = n;
    t = 0;

    for(;!isEmpty();){
      a = dequeue(time, n);
      s = strdequeue(name, n);
      if(a > q){
        t += q;
        a -= q;
        strenqueue(name, n, s);
        enqueue(time, n, a);
      }else{
        t += a;
        System.out.println(s + " " + t);
      }
    }

    sc.close();
  } run {
    java.util.Scanner sc = new java.util.Scanner(in);
/*answer*/
    int n, q;
    String[] name;
    int[] time;
    int i, t, a;
    String s;

    n = sc.nextInt();
    q = sc.nextInt();
    name = new String[n + 1];
    time = new int[n + 1];
    for(i = 0;i < n;i++){
      name[i] = sc.next();
      time[i] = sc.nextInt();
    }
    head = 0;
    tail = n;
    t = 0;

    for(;!isEmpty();){
      a = dequeue(time, n);
      s = strdequeue(name, n);
      if(a > q){
        t += q;
        a -= q;
        strenqueue(name, n, s);
        enqueue(time, n, a);
      }else{
        t += a;
        System.out.println(s + " " + t);
      }
    }

    sc.close();
  } java.util.Scanner sc = new java.util.Scanner(in); sc new java.util.Scanner(in) int n n q; q String[] name; name int[] time; time int i i t t a; a String s; s n = sc.nextInt() n sc.nextInt() sc.nextInt sc q = sc.nextInt() q sc.nextInt() sc.nextInt sc name = new String[n + 1] name new String[n + 1] n + 1 n 1 time = new int[n + 1] time new int[n + 1] n + 1 n 1 for(i = 0;i < n;i++){
      name[i] = sc.next();
      time[i] = sc.nextInt();
    } i = 0; i = 0 i 0 i < n i n i++ i++ i {
      name[i] = sc.next();
      time[i] = sc.nextInt();
    } {
      name[i] = sc.next();
      time[i] = sc.nextInt();
    } name[i] = sc.next() name[i] name i sc.next() sc.next sc time[i] = sc.nextInt() time[i] time i sc.nextInt() sc.nextInt sc head = 0 head 0 tail = n tail n t = 0 t 0 for(;!isEmpty();){
      a = dequeue(time, n);
      s = strdequeue(name, n);
      if(a > q){
        t += q;
        a -= q;
        strenqueue(name, n, s);
        enqueue(time, n, a);
      }else{
        t += a;
        System.out.println(s + " " + t);
      }
    } ; !isEmpty() isEmpty() isEmpty {
      a = dequeue(time, n);
      s = strdequeue(name, n);
      if(a > q){
        t += q;
        a -= q;
        strenqueue(name, n, s);
        enqueue(time, n, a);
      }else{
        t += a;
        System.out.println(s + " " + t);
      }
    } {
      a = dequeue(time, n);
      s = strdequeue(name, n);
      if(a > q){
        t += q;
        a -= q;
        strenqueue(name, n, s);
        enqueue(time, n, a);
      }else{
        t += a;
        System.out.println(s + " " + t);
      }
    } a = dequeue(time, n) a dequeue(time, n) dequeue time n s = strdequeue(name, n) s strdequeue(name, n) strdequeue name n if(a > q){
        t += q;
        a -= q;
        strenqueue(name, n, s);
        enqueue(time, n, a);
      }else{
        t += a;
        System.out.println(s + " " + t);
      } a > q a q {
        t += q;
        a -= q;
        strenqueue(name, n, s);
        enqueue(time, n, a);
      } t += q t q a -= q a q strenqueue(name, n, s) strenqueue name n s enqueue(time, n, a) enqueue time n a {
        t += a;
        System.out.println(s + " " + t);
      } t += a t a System.out.println(s + " " + t) System.out.println System.out System System.out s + " " + t s + " " + t s " " t sc.close() sc.close sc java.io.InputStream in in java.io.PrintStream out out public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  } main {
    (new Main()).run(System.in, System.out);
  } (new Main()).run(System.in, System.out) (new Main()).run (new Main()) System.in System System.in System.out System System.out String[] args args private static void enqueue(int[] time, int n, int a){
    time[tail] = a;
    tail = (tail + 1) % (n + 1);
  } enqueue {
    time[tail] = a;
    tail = (tail + 1) % (n + 1);
  } time[tail] = a time[tail] time tail a tail = (tail + 1) % (n + 1) tail (tail + 1) % (n + 1) (tail + 1) tail 1 (n + 1) n 1 int[] time time int n n int a a private static void strenqueue(String[] name, int n, String s){
    name[tail] = s;
  } strenqueue {
    name[tail] = s;
  } name[tail] = s name[tail] name tail s String[] name name int n n String s s private static int dequeue(int[] time, int n){
    head = (head + 1) % (n + 1);
    return time[(n + head) % (n + 1)];
  } dequeue {
    head = (head + 1) % (n + 1);
    return time[(n + head) % (n + 1)];
  } head = (head + 1) % (n + 1) head (head + 1) % (n + 1) (head + 1) head 1 (n + 1) n 1 return time[(n + head) % (n + 1)]; time[(n + head) % (n + 1)] time (n + head) % (n + 1) (n + head) n head (n + 1) n 1 int[] time time int n n private static String strdequeue(String[] name, int n){
    return name[(head + n) % (n + 1)];
  } strdequeue {
    return name[(head + n) % (n + 1)];
  } return name[(head + n) % (n + 1)]; name[(head + n) % (n + 1)] name (head + n) % (n + 1) (head + n) head n (n + 1) n 1 String[] name name int n n private static boolean isEmpty(){
    if(head == tail){
      return true;
    }else{
      return false;
    }
  } isEmpty {
    if(head == tail){
      return true;
    }else{
      return false;
    }
  } if(head == tail){
      return true;
    }else{
      return false;
    } head == tail head tail {
      return true;
    } return true; true {
      return false;
    } return false; false public class Main{
  static int head, tail;
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
/*answer*/
    int n, q;
    String[] name;
    int[] time;
    int i, t, a;
    String s;

    n = sc.nextInt();
    q = sc.nextInt();
    name = new String[n + 1];
    time = new int[n + 1];
    for(i = 0;i < n;i++){
      name[i] = sc.next();
      time[i] = sc.nextInt();
    }
    head = 0;
    tail = n;
    t = 0;

    for(;!isEmpty();){
      a = dequeue(time, n);
      s = strdequeue(name, n);
      if(a > q){
        t += q;
        a -= q;
        strenqueue(name, n, s);
        enqueue(time, n, a);
      }else{
        t += a;
        System.out.println(s + " " + t);
      }
    }

    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }

  private static void enqueue(int[] time, int n, int a){
    time[tail] = a;
    tail = (tail + 1) % (n + 1);
  }

  private static void strenqueue(String[] name, int n, String s){
    name[tail] = s;
  }

  private static int dequeue(int[] time, int n){
    head = (head + 1) % (n + 1);
    return time[(n + head) % (n + 1)];
  }

  private static String strdequeue(String[] name, int n){
    return name[(head + n) % (n + 1)];
  }

  private static boolean isEmpty(){
    if(head == tail){
      return true;
    }else{
      return false;
    }
  }

} public class Main{
  static int head, tail;
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
/*answer*/
    int n, q;
    String[] name;
    int[] time;
    int i, t, a;
    String s;

    n = sc.nextInt();
    q = sc.nextInt();
    name = new String[n + 1];
    time = new int[n + 1];
    for(i = 0;i < n;i++){
      name[i] = sc.next();
      time[i] = sc.nextInt();
    }
    head = 0;
    tail = n;
    t = 0;

    for(;!isEmpty();){
      a = dequeue(time, n);
      s = strdequeue(name, n);
      if(a > q){
        t += q;
        a -= q;
        strenqueue(name, n, s);
        enqueue(time, n, a);
      }else{
        t += a;
        System.out.println(s + " " + t);
      }
    }

    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }

  private static void enqueue(int[] time, int n, int a){
    time[tail] = a;
    tail = (tail + 1) % (n + 1);
  }

  private static void strenqueue(String[] name, int n, String s){
    name[tail] = s;
  }

  private static int dequeue(int[] time, int n){
    head = (head + 1) % (n + 1);
    return time[(n + head) % (n + 1)];
  }

  private static String strdequeue(String[] name, int n){
    return name[(head + n) % (n + 1)];
  }

  private static boolean isEmpty(){
    if(head == tail){
      return true;
    }else{
      return false;
    }
  }

} Main
public class Main{
  static int head, tail;
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
/*answer*/
    int n, q;
    String[] name;
    int[] time;
    int i, t, a;
    String s;

    n = sc.nextInt();
    q = sc.nextInt();
    name = new String[n + 1];
    time = new int[n + 1];
    for(i = 0;i < n;i++){
      name[i] = sc.next();
      time[i] = sc.nextInt();
    }
    head = 0;
    tail = n;
    t = 0;

    for(;!isEmpty();){
      a = dequeue(time, n);
      s = strdequeue(name, n);
      if(a > q){
        t += q;
        a -= q;
        strenqueue(name, n, s);
        enqueue(time, n, a);
      }else{
        t += a;
        System.out.println(s + " " + t);
      }
    }

    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }

  private static void enqueue(int[] time, int n, int a){
    time[tail] = a;
    tail = (tail + 1) % (n + 1);
  }

  private static void strenqueue(String[] name, int n, String s){
    name[tail] = s;
  }

  private static int dequeue(int[] time, int n){
    head = (head + 1) % (n + 1);
    return time[(n + head) % (n + 1)];
  }

  private static String strdequeue(String[] name, int n){
    return name[(head + n) % (n + 1)];
  }

  private static boolean isEmpty(){
    if(head == tail){
      return true;
    }else{
      return false;
    }
  }

}