import java.util.Scanner;
import java.util.Deque;
import java.util.ArrayDeque;

class Main {
  public static void main(String... args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int q = sc.nextInt();
    Deque<String> names = new ArrayDeque<String>(50000);
    Deque<Integer> times = new ArrayDeque<Integer>(50000);

    for (int i = 0; i < n; i++) {
      names.offerLast(sc.next());
      times.offerLast(sc.nextInt());
    }

    execution(q, names, times);
  }

  public static void execution(int q, Deque<String> names, Deque<Integer> times) {
    int time;
    String name;
    int currentTime = 0;

    while(true) {
      try {
        name = names.removeFirst();
        time = times.removeFirst();

        if (time - q <= 0) {
          currentTime += time;
          System.out.println(name + " " + currentTime);
          continue;
        }

        time -= q;
        currentTime += q;

        names.offerLast(name);
        times.offerLast(time);

      } catch (Exception e) {
        break;
      }
    }
  }
}
 import java.util.Scanner; Scanner java.util import java.util.Deque; Deque java.util import java.util.ArrayDeque; ArrayDeque java.util class Main {
  public static void main(String... args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int q = sc.nextInt();
    Deque<String> names = new ArrayDeque<String>(50000);
    Deque<Integer> times = new ArrayDeque<Integer>(50000);

    for (int i = 0; i < n; i++) {
      names.offerLast(sc.next());
      times.offerLast(sc.nextInt());
    }

    execution(q, names, times);
  }

  public static void execution(int q, Deque<String> names, Deque<Integer> times) {
    int time;
    String name;
    int currentTime = 0;

    while(true) {
      try {
        name = names.removeFirst();
        time = times.removeFirst();

        if (time - q <= 0) {
          currentTime += time;
          System.out.println(name + " " + currentTime);
          continue;
        }

        time -= q;
        currentTime += q;

        names.offerLast(name);
        times.offerLast(time);

      } catch (Exception e) {
        break;
      }
    }
  }
} Main public static void main(String... args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int q = sc.nextInt();
    Deque<String> names = new ArrayDeque<String>(50000);
    Deque<Integer> times = new ArrayDeque<Integer>(50000);

    for (int i = 0; i < n; i++) {
      names.offerLast(sc.next());
      times.offerLast(sc.nextInt());
    }

    execution(q, names, times);
  } main {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int q = sc.nextInt();
    Deque<String> names = new ArrayDeque<String>(50000);
    Deque<Integer> times = new ArrayDeque<Integer>(50000);

    for (int i = 0; i < n; i++) {
      names.offerLast(sc.next());
      times.offerLast(sc.nextInt());
    }

    execution(q, names, times);
  } 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 Deque<String> names = new ArrayDeque<String>(50000); names new ArrayDeque<String>(50000) Deque<Integer> times = new ArrayDeque<Integer>(50000); times new ArrayDeque<Integer>(50000) for (int i = 0; i < n; i++) {
      names.offerLast(sc.next());
      times.offerLast(sc.nextInt());
    } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
      names.offerLast(sc.next());
      times.offerLast(sc.nextInt());
    } {
      names.offerLast(sc.next());
      times.offerLast(sc.nextInt());
    } names.offerLast(sc.next()) names.offerLast names sc.next() sc.next sc times.offerLast(sc.nextInt()) times.offerLast times sc.nextInt() sc.nextInt sc execution(q, names, times) execution q names times String... args args public static void execution(int q, Deque<String> names, Deque<Integer> times) {
    int time;
    String name;
    int currentTime = 0;

    while(true) {
      try {
        name = names.removeFirst();
        time = times.removeFirst();

        if (time - q <= 0) {
          currentTime += time;
          System.out.println(name + " " + currentTime);
          continue;
        }

        time -= q;
        currentTime += q;

        names.offerLast(name);
        times.offerLast(time);

      } catch (Exception e) {
        break;
      }
    }
  } execution {
    int time;
    String name;
    int currentTime = 0;

    while(true) {
      try {
        name = names.removeFirst();
        time = times.removeFirst();

        if (time - q <= 0) {
          currentTime += time;
          System.out.println(name + " " + currentTime);
          continue;
        }

        time -= q;
        currentTime += q;

        names.offerLast(name);
        times.offerLast(time);

      } catch (Exception e) {
        break;
      }
    }
  } int time; time String name; name int currentTime = 0; currentTime 0 while(true) {
      try {
        name = names.removeFirst();
        time = times.removeFirst();

        if (time - q <= 0) {
          currentTime += time;
          System.out.println(name + " " + currentTime);
          continue;
        }

        time -= q;
        currentTime += q;

        names.offerLast(name);
        times.offerLast(time);

      } catch (Exception e) {
        break;
      }
    } true {
      try {
        name = names.removeFirst();
        time = times.removeFirst();

        if (time - q <= 0) {
          currentTime += time;
          System.out.println(name + " " + currentTime);
          continue;
        }

        time -= q;
        currentTime += q;

        names.offerLast(name);
        times.offerLast(time);

      } catch (Exception e) {
        break;
      }
    } try {
        name = names.removeFirst();
        time = times.removeFirst();

        if (time - q <= 0) {
          currentTime += time;
          System.out.println(name + " " + currentTime);
          continue;
        }

        time -= q;
        currentTime += q;

        names.offerLast(name);
        times.offerLast(time);

      } catch (Exception e) {
        break;
      } catch (Exception e) {
        break;
      } Exception e {
        break;
      } break; {
        name = names.removeFirst();
        time = times.removeFirst();

        if (time - q <= 0) {
          currentTime += time;
          System.out.println(name + " " + currentTime);
          continue;
        }

        time -= q;
        currentTime += q;

        names.offerLast(name);
        times.offerLast(time);

      } name = names.removeFirst() name names.removeFirst() names.removeFirst names time = times.removeFirst() time times.removeFirst() times.removeFirst times if (time - q <= 0) {
          currentTime += time;
          System.out.println(name + " " + currentTime);
          continue;
        } time - q <= 0 time - q time q 0 {
          currentTime += time;
          System.out.println(name + " " + currentTime);
          continue;
        } currentTime += time currentTime time System.out.println(name + " " + currentTime) System.out.println System.out System System.out name + " " + currentTime name + " " + currentTime name " " currentTime continue; time -= q time q currentTime += q currentTime q names.offerLast(name) names.offerLast names name times.offerLast(time) times.offerLast times time int q q Deque<String> names names Deque<Integer> times times
import java.util.Scanner;
import java.util.Deque;
import java.util.ArrayDeque;

class Main {
  public static void main(String... args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int q = sc.nextInt();
    Deque<String> names = new ArrayDeque<String>(50000);
    Deque<Integer> times = new ArrayDeque<Integer>(50000);

    for (int i = 0; i < n; i++) {
      names.offerLast(sc.next());
      times.offerLast(sc.nextInt());
    }

    execution(q, names, times);
  }

  public static void execution(int q, Deque<String> names, Deque<Integer> times) {
    int time;
    String name;
    int currentTime = 0;

    while(true) {
      try {
        name = names.removeFirst();
        time = times.removeFirst();

        if (time - q <= 0) {
          currentTime += time;
          System.out.println(name + " " + currentTime);
          continue;
        }

        time -= q;
        currentTime += q;

        names.offerLast(name);
        times.offerLast(time);

      } catch (Exception e) {
        break;
      }
    }
  }
}

