import java.util.*;

public class Main {
  static int head = 0;
  static int tail = 0;
  static int max = 100000;
  static int[] queue = new int[max];
  static String[] str = new String[max];

  public static void initialize() {
    head = tail = 0;
  }
  public static boolean isEmpty() {
    return head == tail;
  }
  public static boolean isFull() {
    return head == (tail + 1) % max;
  }
  public static void enqueue(int x, String s) {
    if(isFull()) {
      throw new IllegalArgumentException("オーバーフロー");
    } else {
      queue[tail] = x;
      str[tail] = s;
      if(tail + 1 == max) {
        tail = 0;
      } else {
        tail++;
      }
    }
  }
  public static int dequeue() {
    if(isEmpty()) {
      throw new IllegalArgumentException("アンダーフロー");
    } else {
      int x = queue[head];
      if(head + 1 == max) {
        head = 0;
      } else {
        head++;
      }
      return x;
    }
  }
  public static String destr() {
    if(head == 0) {
      return str[max - 1];
    } else {
      return str[head - 1];
    }
  }

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int q = sc.nextInt();
    String s = "";
    int a = 0;
    int time = 0;
    for(int i = 0; i < n; i++) {
      s = sc.next();
      a = sc.nextInt();
      if(a <= q) {
        time += a;
        System.out.println(s + " " + time);
      } else {
        time += q;
        enqueue(a - q, s);
      }
    }
    while(!isEmpty()) {
      a = dequeue();
      s = destr();
      if(a <= q) {
        time += a;
        System.out.println(s + " " + time);
      } else {
        time += q;
        enqueue(a - q, s);
      }
    }
  }
}
 import java.util.*; util.* java public class Main {
  static int head = 0;
  static int tail = 0;
  static int max = 100000;
  static int[] queue = new int[max];
  static String[] str = new String[max];

  public static void initialize() {
    head = tail = 0;
  }
  public static boolean isEmpty() {
    return head == tail;
  }
  public static boolean isFull() {
    return head == (tail + 1) % max;
  }
  public static void enqueue(int x, String s) {
    if(isFull()) {
      throw new IllegalArgumentException("オーバーフロー");
    } else {
      queue[tail] = x;
      str[tail] = s;
      if(tail + 1 == max) {
        tail = 0;
      } else {
        tail++;
      }
    }
  }
  public static int dequeue() {
    if(isEmpty()) {
      throw new IllegalArgumentException("アンダーフロー");
    } else {
      int x = queue[head];
      if(head + 1 == max) {
        head = 0;
      } else {
        head++;
      }
      return x;
    }
  }
  public static String destr() {
    if(head == 0) {
      return str[max - 1];
    } else {
      return str[head - 1];
    }
  }

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int q = sc.nextInt();
    String s = "";
    int a = 0;
    int time = 0;
    for(int i = 0; i < n; i++) {
      s = sc.next();
      a = sc.nextInt();
      if(a <= q) {
        time += a;
        System.out.println(s + " " + time);
      } else {
        time += q;
        enqueue(a - q, s);
      }
    }
    while(!isEmpty()) {
      a = dequeue();
      s = destr();
      if(a <= q) {
        time += a;
        System.out.println(s + " " + time);
      } else {
        time += q;
        enqueue(a - q, s);
      }
    }
  }
} Main static int head = 0; head 0 static int tail = 0; tail 0 static int max = 100000; max 100000 static int[] queue = new int[max]; queue new int[max] max static String[] str = new String[max]; str new String[max] max public static void initialize() {
    head = tail = 0;
  } initialize {
    head = tail = 0;
  } head = tail = 0 head tail = 0 tail 0 public static boolean isEmpty() {
    return head == tail;
  } isEmpty {
    return head == tail;
  } return head == tail; head == tail head tail public static boolean isFull() {
    return head == (tail + 1) % max;
  } isFull {
    return head == (tail + 1) % max;
  } return head == (tail + 1) % max; head == (tail + 1) % max head (tail + 1) % max (tail + 1) tail 1 max public static void enqueue(int x, String s) {
    if(isFull()) {
      throw new IllegalArgumentException("オーバーフロー");
    } else {
      queue[tail] = x;
      str[tail] = s;
      if(tail + 1 == max) {
        tail = 0;
      } else {
        tail++;
      }
    }
  } enqueue {
    if(isFull()) {
      throw new IllegalArgumentException("オーバーフロー");
    } else {
      queue[tail] = x;
      str[tail] = s;
      if(tail + 1 == max) {
        tail = 0;
      } else {
        tail++;
      }
    }
  } if(isFull()) {
      throw new IllegalArgumentException("オーバーフロー");
    } else {
      queue[tail] = x;
      str[tail] = s;
      if(tail + 1 == max) {
        tail = 0;
      } else {
        tail++;
      }
    } isFull() isFull {
      throw new IllegalArgumentException("オーバーフロー");
    } throw new IllegalArgumentException("オーバーフロー"); new IllegalArgumentException("オーバーフロー") {
      queue[tail] = x;
      str[tail] = s;
      if(tail + 1 == max) {
        tail = 0;
      } else {
        tail++;
      }
    } queue[tail] = x queue[tail] queue tail x str[tail] = s str[tail] str tail s if(tail + 1 == max) {
        tail = 0;
      } else {
        tail++;
      } tail + 1 == max tail + 1 tail 1 max {
        tail = 0;
      } tail = 0 tail 0 {
        tail++;
      } tail++ tail int x x String s s public static int dequeue() {
    if(isEmpty()) {
      throw new IllegalArgumentException("アンダーフロー");
    } else {
      int x = queue[head];
      if(head + 1 == max) {
        head = 0;
      } else {
        head++;
      }
      return x;
    }
  } dequeue {
    if(isEmpty()) {
      throw new IllegalArgumentException("アンダーフロー");
    } else {
      int x = queue[head];
      if(head + 1 == max) {
        head = 0;
      } else {
        head++;
      }
      return x;
    }
  } if(isEmpty()) {
      throw new IllegalArgumentException("アンダーフロー");
    } else {
      int x = queue[head];
      if(head + 1 == max) {
        head = 0;
      } else {
        head++;
      }
      return x;
    } isEmpty() isEmpty {
      throw new IllegalArgumentException("アンダーフロー");
    } throw new IllegalArgumentException("アンダーフロー"); new IllegalArgumentException("アンダーフロー") {
      int x = queue[head];
      if(head + 1 == max) {
        head = 0;
      } else {
        head++;
      }
      return x;
    } int x = queue[head]; x queue[head] queue head if(head + 1 == max) {
        head = 0;
      } else {
        head++;
      } head + 1 == max head + 1 head 1 max {
        head = 0;
      } head = 0 head 0 {
        head++;
      } head++ head return x; x public static String destr() {
    if(head == 0) {
      return str[max - 1];
    } else {
      return str[head - 1];
    }
  } destr {
    if(head == 0) {
      return str[max - 1];
    } else {
      return str[head - 1];
    }
  } if(head == 0) {
      return str[max - 1];
    } else {
      return str[head - 1];
    } head == 0 head 0 {
      return str[max - 1];
    } return str[max - 1]; str[max - 1] str max - 1 max 1 {
      return str[head - 1];
    } return str[head - 1]; str[head - 1] str head - 1 head 1 public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int q = sc.nextInt();
    String s = "";
    int a = 0;
    int time = 0;
    for(int i = 0; i < n; i++) {
      s = sc.next();
      a = sc.nextInt();
      if(a <= q) {
        time += a;
        System.out.println(s + " " + time);
      } else {
        time += q;
        enqueue(a - q, s);
      }
    }
    while(!isEmpty()) {
      a = dequeue();
      s = destr();
      if(a <= q) {
        time += a;
        System.out.println(s + " " + time);
      } else {
        time += q;
        enqueue(a - q, s);
      }
    }
  } main {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int q = sc.nextInt();
    String s = "";
    int a = 0;
    int time = 0;
    for(int i = 0; i < n; i++) {
      s = sc.next();
      a = sc.nextInt();
      if(a <= q) {
        time += a;
        System.out.println(s + " " + time);
      } else {
        time += q;
        enqueue(a - q, s);
      }
    }
    while(!isEmpty()) {
      a = dequeue();
      s = destr();
      if(a <= q) {
        time += a;
        System.out.println(s + " " + time);
      } else {
        time += q;
        enqueue(a - q, s);
      }
    }
  } 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 String s = ""; s "" int a = 0; a 0 int time = 0; time 0 for(int i = 0; i < n; i++) {
      s = sc.next();
      a = sc.nextInt();
      if(a <= q) {
        time += a;
        System.out.println(s + " " + time);
      } else {
        time += q;
        enqueue(a - q, s);
      }
    } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
      s = sc.next();
      a = sc.nextInt();
      if(a <= q) {
        time += a;
        System.out.println(s + " " + time);
      } else {
        time += q;
        enqueue(a - q, s);
      }
    } {
      s = sc.next();
      a = sc.nextInt();
      if(a <= q) {
        time += a;
        System.out.println(s + " " + time);
      } else {
        time += q;
        enqueue(a - q, s);
      }
    } s = sc.next() s sc.next() sc.next sc a = sc.nextInt() a sc.nextInt() sc.nextInt sc if(a <= q) {
        time += a;
        System.out.println(s + " " + time);
      } else {
        time += q;
        enqueue(a - q, s);
      } a <= q a q {
        time += a;
        System.out.println(s + " " + time);
      } time += a time a System.out.println(s + " " + time) System.out.println System.out System System.out s + " " + time s + " " + time s " " time {
        time += q;
        enqueue(a - q, s);
      } time += q time q enqueue(a - q, s) enqueue a - q a q s while(!isEmpty()) {
      a = dequeue();
      s = destr();
      if(a <= q) {
        time += a;
        System.out.println(s + " " + time);
      } else {
        time += q;
        enqueue(a - q, s);
      }
    } !isEmpty() isEmpty() isEmpty {
      a = dequeue();
      s = destr();
      if(a <= q) {
        time += a;
        System.out.println(s + " " + time);
      } else {
        time += q;
        enqueue(a - q, s);
      }
    } a = dequeue() a dequeue() dequeue s = destr() s destr() destr if(a <= q) {
        time += a;
        System.out.println(s + " " + time);
      } else {
        time += q;
        enqueue(a - q, s);
      } a <= q a q {
        time += a;
        System.out.println(s + " " + time);
      } time += a time a System.out.println(s + " " + time) System.out.println System.out System System.out s + " " + time s + " " + time s " " time {
        time += q;
        enqueue(a - q, s);
      } time += q time q enqueue(a - q, s) enqueue a - q a q s String[] args args public class Main {
  static int head = 0;
  static int tail = 0;
  static int max = 100000;
  static int[] queue = new int[max];
  static String[] str = new String[max];

  public static void initialize() {
    head = tail = 0;
  }
  public static boolean isEmpty() {
    return head == tail;
  }
  public static boolean isFull() {
    return head == (tail + 1) % max;
  }
  public static void enqueue(int x, String s) {
    if(isFull()) {
      throw new IllegalArgumentException("オーバーフロー");
    } else {
      queue[tail] = x;
      str[tail] = s;
      if(tail + 1 == max) {
        tail = 0;
      } else {
        tail++;
      }
    }
  }
  public static int dequeue() {
    if(isEmpty()) {
      throw new IllegalArgumentException("アンダーフロー");
    } else {
      int x = queue[head];
      if(head + 1 == max) {
        head = 0;
      } else {
        head++;
      }
      return x;
    }
  }
  public static String destr() {
    if(head == 0) {
      return str[max - 1];
    } else {
      return str[head - 1];
    }
  }

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int q = sc.nextInt();
    String s = "";
    int a = 0;
    int time = 0;
    for(int i = 0; i < n; i++) {
      s = sc.next();
      a = sc.nextInt();
      if(a <= q) {
        time += a;
        System.out.println(s + " " + time);
      } else {
        time += q;
        enqueue(a - q, s);
      }
    }
    while(!isEmpty()) {
      a = dequeue();
      s = destr();
      if(a <= q) {
        time += a;
        System.out.println(s + " " + time);
      } else {
        time += q;
        enqueue(a - q, s);
      }
    }
  }
} public class Main {
  static int head = 0;
  static int tail = 0;
  static int max = 100000;
  static int[] queue = new int[max];
  static String[] str = new String[max];

  public static void initialize() {
    head = tail = 0;
  }
  public static boolean isEmpty() {
    return head == tail;
  }
  public static boolean isFull() {
    return head == (tail + 1) % max;
  }
  public static void enqueue(int x, String s) {
    if(isFull()) {
      throw new IllegalArgumentException("オーバーフロー");
    } else {
      queue[tail] = x;
      str[tail] = s;
      if(tail + 1 == max) {
        tail = 0;
      } else {
        tail++;
      }
    }
  }
  public static int dequeue() {
    if(isEmpty()) {
      throw new IllegalArgumentException("アンダーフロー");
    } else {
      int x = queue[head];
      if(head + 1 == max) {
        head = 0;
      } else {
        head++;
      }
      return x;
    }
  }
  public static String destr() {
    if(head == 0) {
      return str[max - 1];
    } else {
      return str[head - 1];
    }
  }

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int q = sc.nextInt();
    String s = "";
    int a = 0;
    int time = 0;
    for(int i = 0; i < n; i++) {
      s = sc.next();
      a = sc.nextInt();
      if(a <= q) {
        time += a;
        System.out.println(s + " " + time);
      } else {
        time += q;
        enqueue(a - q, s);
      }
    }
    while(!isEmpty()) {
      a = dequeue();
      s = destr();
      if(a <= q) {
        time += a;
        System.out.println(s + " " + time);
      } else {
        time += q;
        enqueue(a - q, s);
      }
    }
  }
} Main
import java.util.*;

public class Main {
  static int head = 0;
  static int tail = 0;
  static int max = 100000;
  static int[] queue = new int[max];
  static String[] str = new String[max];

  public static void initialize() {
    head = tail = 0;
  }
  public static boolean isEmpty() {
    return head == tail;
  }
  public static boolean isFull() {
    return head == (tail + 1) % max;
  }
  public static void enqueue(int x, String s) {
    if(isFull()) {
      throw new IllegalArgumentException("オーバーフロー");
    } else {
      queue[tail] = x;
      str[tail] = s;
      if(tail + 1 == max) {
        tail = 0;
      } else {
        tail++;
      }
    }
  }
  public static int dequeue() {
    if(isEmpty()) {
      throw new IllegalArgumentException("アンダーフロー");
    } else {
      int x = queue[head];
      if(head + 1 == max) {
        head = 0;
      } else {
        head++;
      }
      return x;
    }
  }
  public static String destr() {
    if(head == 0) {
      return str[max - 1];
    } else {
      return str[head - 1];
    }
  }

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int q = sc.nextInt();
    String s = "";
    int a = 0;
    int time = 0;
    for(int i = 0; i < n; i++) {
      s = sc.next();
      a = sc.nextInt();
      if(a <= q) {
        time += a;
        System.out.println(s + " " + time);
      } else {
        time += q;
        enqueue(a - q, s);
      }
    }
    while(!isEmpty()) {
      a = dequeue();
      s = destr();
      if(a <= q) {
        time += a;
        System.out.println(s + " " + time);
      } else {
        time += q;
        enqueue(a - q, s);
      }
    }
  }
}

