import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int q = sc.nextInt();
    List<Map<String, Integer>> queue = new ArrayList<>();
    int second = 0;
    for(int i = 0; i < n; i++) {
        queue.add(new HashMap<>());
        queue.get(queue.size() - 1).put(sc.next(), sc.nextInt());
    }
    while(queue.size() > 0) {
      String s = "";
      for(String e : queue.get(0).keySet()) {
        s = e;
      }
      int a = queue.get(0).get(s);
      queue.remove(0);
      if(a <= q) {
        second += a;
        System.out.println(s + " " + second);
      } else {
        second += q;
        queue.add(new HashMap<>());
        queue.get(queue.size() - 1).put(s, a - q);
      }
    }
  }
}
 import java.util.*; util.* java public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int q = sc.nextInt();
    List<Map<String, Integer>> queue = new ArrayList<>();
    int second = 0;
    for(int i = 0; i < n; i++) {
        queue.add(new HashMap<>());
        queue.get(queue.size() - 1).put(sc.next(), sc.nextInt());
    }
    while(queue.size() > 0) {
      String s = "";
      for(String e : queue.get(0).keySet()) {
        s = e;
      }
      int a = queue.get(0).get(s);
      queue.remove(0);
      if(a <= q) {
        second += a;
        System.out.println(s + " " + second);
      } else {
        second += q;
        queue.add(new HashMap<>());
        queue.get(queue.size() - 1).put(s, a - q);
      }
    }
  }
} Main public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int q = sc.nextInt();
    List<Map<String, Integer>> queue = new ArrayList<>();
    int second = 0;
    for(int i = 0; i < n; i++) {
        queue.add(new HashMap<>());
        queue.get(queue.size() - 1).put(sc.next(), sc.nextInt());
    }
    while(queue.size() > 0) {
      String s = "";
      for(String e : queue.get(0).keySet()) {
        s = e;
      }
      int a = queue.get(0).get(s);
      queue.remove(0);
      if(a <= q) {
        second += a;
        System.out.println(s + " " + second);
      } else {
        second += q;
        queue.add(new HashMap<>());
        queue.get(queue.size() - 1).put(s, a - q);
      }
    }
  } main {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int q = sc.nextInt();
    List<Map<String, Integer>> queue = new ArrayList<>();
    int second = 0;
    for(int i = 0; i < n; i++) {
        queue.add(new HashMap<>());
        queue.get(queue.size() - 1).put(sc.next(), sc.nextInt());
    }
    while(queue.size() > 0) {
      String s = "";
      for(String e : queue.get(0).keySet()) {
        s = e;
      }
      int a = queue.get(0).get(s);
      queue.remove(0);
      if(a <= q) {
        second += a;
        System.out.println(s + " " + second);
      } else {
        second += q;
        queue.add(new HashMap<>());
        queue.get(queue.size() - 1).put(s, a - q);
      }
    }
  } 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 List<Map<String, Integer>> queue = new ArrayList<>(); queue new ArrayList<>() int second = 0; second 0 for(int i = 0; i < n; i++) {
        queue.add(new HashMap<>());
        queue.get(queue.size() - 1).put(sc.next(), sc.nextInt());
    } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
        queue.add(new HashMap<>());
        queue.get(queue.size() - 1).put(sc.next(), sc.nextInt());
    } {
        queue.add(new HashMap<>());
        queue.get(queue.size() - 1).put(sc.next(), sc.nextInt());
    } queue.add(new HashMap<>()) queue.add queue new HashMap<>() queue.get(queue.size() - 1).put(sc.next(), sc.nextInt()) queue.get(queue.size() - 1).put queue.get(queue.size() - 1) queue.get queue queue.size() - 1 queue.size() queue.size queue 1 sc.next() sc.next sc sc.nextInt() sc.nextInt sc while(queue.size() > 0) {
      String s = "";
      for(String e : queue.get(0).keySet()) {
        s = e;
      }
      int a = queue.get(0).get(s);
      queue.remove(0);
      if(a <= q) {
        second += a;
        System.out.println(s + " " + second);
      } else {
        second += q;
        queue.add(new HashMap<>());
        queue.get(queue.size() - 1).put(s, a - q);
      }
    } queue.size() > 0 queue.size() queue.size queue 0 {
      String s = "";
      for(String e : queue.get(0).keySet()) {
        s = e;
      }
      int a = queue.get(0).get(s);
      queue.remove(0);
      if(a <= q) {
        second += a;
        System.out.println(s + " " + second);
      } else {
        second += q;
        queue.add(new HashMap<>());
        queue.get(queue.size() - 1).put(s, a - q);
      }
    } String s = ""; s "" for(String e : queue.get(0).keySet()) {
        s = e;
      } String e queue.get(0).keySet() queue.get(0).keySet queue.get(0) queue.get queue 0 {
        s = e;
      } {
        s = e;
      } s = e s e int a = queue.get(0).get(s); a queue.get(0).get(s) queue.get(0).get queue.get(0) queue.get queue 0 s queue.remove(0) queue.remove queue 0 if(a <= q) {
        second += a;
        System.out.println(s + " " + second);
      } else {
        second += q;
        queue.add(new HashMap<>());
        queue.get(queue.size() - 1).put(s, a - q);
      } a <= q a q {
        second += a;
        System.out.println(s + " " + second);
      } second += a second a System.out.println(s + " " + second) System.out.println System.out System System.out s + " " + second s + " " + second s " " second {
        second += q;
        queue.add(new HashMap<>());
        queue.get(queue.size() - 1).put(s, a - q);
      } second += q second q queue.add(new HashMap<>()) queue.add queue new HashMap<>() queue.get(queue.size() - 1).put(s, a - q) queue.get(queue.size() - 1).put queue.get(queue.size() - 1) queue.get queue queue.size() - 1 queue.size() queue.size queue 1 s a - q a q String[] args args public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int q = sc.nextInt();
    List<Map<String, Integer>> queue = new ArrayList<>();
    int second = 0;
    for(int i = 0; i < n; i++) {
        queue.add(new HashMap<>());
        queue.get(queue.size() - 1).put(sc.next(), sc.nextInt());
    }
    while(queue.size() > 0) {
      String s = "";
      for(String e : queue.get(0).keySet()) {
        s = e;
      }
      int a = queue.get(0).get(s);
      queue.remove(0);
      if(a <= q) {
        second += a;
        System.out.println(s + " " + second);
      } else {
        second += q;
        queue.add(new HashMap<>());
        queue.get(queue.size() - 1).put(s, a - q);
      }
    }
  }
} public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int q = sc.nextInt();
    List<Map<String, Integer>> queue = new ArrayList<>();
    int second = 0;
    for(int i = 0; i < n; i++) {
        queue.add(new HashMap<>());
        queue.get(queue.size() - 1).put(sc.next(), sc.nextInt());
    }
    while(queue.size() > 0) {
      String s = "";
      for(String e : queue.get(0).keySet()) {
        s = e;
      }
      int a = queue.get(0).get(s);
      queue.remove(0);
      if(a <= q) {
        second += a;
        System.out.println(s + " " + second);
      } else {
        second += q;
        queue.add(new HashMap<>());
        queue.get(queue.size() - 1).put(s, a - q);
      }
    }
  }
} Main
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int q = sc.nextInt();
    List<Map<String, Integer>> queue = new ArrayList<>();
    int second = 0;
    for(int i = 0; i < n; i++) {
        queue.add(new HashMap<>());
        queue.get(queue.size() - 1).put(sc.next(), sc.nextInt());
    }
    while(queue.size() > 0) {
      String s = "";
      for(String e : queue.get(0).keySet()) {
        s = e;
      }
      int a = queue.get(0).get(s);
      queue.remove(0);
      if(a <= q) {
        second += a;
        System.out.println(s + " " + second);
      } else {
        second += q;
        queue.add(new HashMap<>());
        queue.get(queue.size() - 1).put(s, a - q);
      }
    }
  }
}

