import java.io.*;
import java.util.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Stack;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.Queue;
import java.util.ArrayDeque;
import java.util.Map;
import java.util.LinkedList;

public class Main{
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String[] line = br.readLine().split(" ");
    int n = Integer.parseInt(line[0]);
    int q = Integer.parseInt(line[1]);
    LinkedList<String> queue = new LinkedList<String>();
    int time = 0;
    int cnt = n;
    Map<String, Integer> map = new HashMap<>();

    for(int i = 0; i < n; i++){
      line = br.readLine().split(" ");
      map.put(line[0], Integer.parseInt(line[1]));
      queue.add(line[0]);
    }

    while(true){
      String x = queue.poll();
      if(map.get(x) > q){
        time += q;
        map.put(x, map.get(x) - q);
        queue.add(x);
      }else{
        time += map.get(x);
        map.put(x, time);
        System.out.println(x + " " + map.get(x));
        n--;
      }
      if(n == 0)  break;
    }
  }
} import java.io.*; io.* java import java.util.*; util.* java import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io import java.util.Stack; Stack java.util import java.util.regex.Matcher; Matcher java.util.regex import java.util.regex.Pattern; Pattern java.util.regex import java.util.Queue; Queue java.util import java.util.ArrayDeque; ArrayDeque java.util import java.util.Map; Map java.util import java.util.LinkedList; LinkedList java.util public class Main{
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String[] line = br.readLine().split(" ");
    int n = Integer.parseInt(line[0]);
    int q = Integer.parseInt(line[1]);
    LinkedList<String> queue = new LinkedList<String>();
    int time = 0;
    int cnt = n;
    Map<String, Integer> map = new HashMap<>();

    for(int i = 0; i < n; i++){
      line = br.readLine().split(" ");
      map.put(line[0], Integer.parseInt(line[1]));
      queue.add(line[0]);
    }

    while(true){
      String x = queue.poll();
      if(map.get(x) > q){
        time += q;
        map.put(x, map.get(x) - q);
        queue.add(x);
      }else{
        time += map.get(x);
        map.put(x, time);
        System.out.println(x + " " + map.get(x));
        n--;
      }
      if(n == 0)  break;
    }
  }
} Main public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String[] line = br.readLine().split(" ");
    int n = Integer.parseInt(line[0]);
    int q = Integer.parseInt(line[1]);
    LinkedList<String> queue = new LinkedList<String>();
    int time = 0;
    int cnt = n;
    Map<String, Integer> map = new HashMap<>();

    for(int i = 0; i < n; i++){
      line = br.readLine().split(" ");
      map.put(line[0], Integer.parseInt(line[1]));
      queue.add(line[0]);
    }

    while(true){
      String x = queue.poll();
      if(map.get(x) > q){
        time += q;
        map.put(x, map.get(x) - q);
        queue.add(x);
      }else{
        time += map.get(x);
        map.put(x, time);
        System.out.println(x + " " + map.get(x));
        n--;
      }
      if(n == 0)  break;
    }
  } main {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String[] line = br.readLine().split(" ");
    int n = Integer.parseInt(line[0]);
    int q = Integer.parseInt(line[1]);
    LinkedList<String> queue = new LinkedList<String>();
    int time = 0;
    int cnt = n;
    Map<String, Integer> map = new HashMap<>();

    for(int i = 0; i < n; i++){
      line = br.readLine().split(" ");
      map.put(line[0], Integer.parseInt(line[1]));
      queue.add(line[0]);
    }

    while(true){
      String x = queue.poll();
      if(map.get(x) > q){
        time += q;
        map.put(x, map.get(x) - q);
        queue.add(x);
      }else{
        time += map.get(x);
        map.put(x, time);
        System.out.println(x + " " + map.get(x));
        n--;
      }
      if(n == 0)  break;
    }
  } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) String[] line = br.readLine().split(" "); line br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " int n = Integer.parseInt(line[0]); n Integer.parseInt(line[0]) Integer.parseInt Integer line[0] line 0 int q = Integer.parseInt(line[1]); q Integer.parseInt(line[1]) Integer.parseInt Integer line[1] line 1 LinkedList<String> queue = new LinkedList<String>(); queue new LinkedList<String>() int time = 0; time 0 int cnt = n; cnt n Map<String, Integer> map = new HashMap<>(); map new HashMap<>() for(int i = 0; i < n; i++){
      line = br.readLine().split(" ");
      map.put(line[0], Integer.parseInt(line[1]));
      queue.add(line[0]);
    } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
      line = br.readLine().split(" ");
      map.put(line[0], Integer.parseInt(line[1]));
      queue.add(line[0]);
    } {
      line = br.readLine().split(" ");
      map.put(line[0], Integer.parseInt(line[1]));
      queue.add(line[0]);
    } line = br.readLine().split(" ") line br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " map.put(line[0], Integer.parseInt(line[1])) map.put map line[0] line 0 Integer.parseInt(line[1]) Integer.parseInt Integer line[1] line 1 queue.add(line[0]) queue.add queue line[0] line 0 while(true){
      String x = queue.poll();
      if(map.get(x) > q){
        time += q;
        map.put(x, map.get(x) - q);
        queue.add(x);
      }else{
        time += map.get(x);
        map.put(x, time);
        System.out.println(x + " " + map.get(x));
        n--;
      }
      if(n == 0)  break;
    } true {
      String x = queue.poll();
      if(map.get(x) > q){
        time += q;
        map.put(x, map.get(x) - q);
        queue.add(x);
      }else{
        time += map.get(x);
        map.put(x, time);
        System.out.println(x + " " + map.get(x));
        n--;
      }
      if(n == 0)  break;
    } String x = queue.poll(); x queue.poll() queue.poll queue if(map.get(x) > q){
        time += q;
        map.put(x, map.get(x) - q);
        queue.add(x);
      }else{
        time += map.get(x);
        map.put(x, time);
        System.out.println(x + " " + map.get(x));
        n--;
      } map.get(x) > q map.get(x) map.get map x q {
        time += q;
        map.put(x, map.get(x) - q);
        queue.add(x);
      } time += q time q map.put(x, map.get(x) - q) map.put map x map.get(x) - q map.get(x) map.get map x q queue.add(x) queue.add queue x {
        time += map.get(x);
        map.put(x, time);
        System.out.println(x + " " + map.get(x));
        n--;
      } time += map.get(x) time map.get(x) map.get map x map.put(x, time) map.put map x time System.out.println(x + " " + map.get(x)) System.out.println System.out System System.out x + " " + map.get(x) x + " " + map.get(x) x " " map.get(x) map.get map x n-- n if(n == 0)  break; n == 0 n 0 break; String[] args args public class Main{
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String[] line = br.readLine().split(" ");
    int n = Integer.parseInt(line[0]);
    int q = Integer.parseInt(line[1]);
    LinkedList<String> queue = new LinkedList<String>();
    int time = 0;
    int cnt = n;
    Map<String, Integer> map = new HashMap<>();

    for(int i = 0; i < n; i++){
      line = br.readLine().split(" ");
      map.put(line[0], Integer.parseInt(line[1]));
      queue.add(line[0]);
    }

    while(true){
      String x = queue.poll();
      if(map.get(x) > q){
        time += q;
        map.put(x, map.get(x) - q);
        queue.add(x);
      }else{
        time += map.get(x);
        map.put(x, time);
        System.out.println(x + " " + map.get(x));
        n--;
      }
      if(n == 0)  break;
    }
  }
} public class Main{
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String[] line = br.readLine().split(" ");
    int n = Integer.parseInt(line[0]);
    int q = Integer.parseInt(line[1]);
    LinkedList<String> queue = new LinkedList<String>();
    int time = 0;
    int cnt = n;
    Map<String, Integer> map = new HashMap<>();

    for(int i = 0; i < n; i++){
      line = br.readLine().split(" ");
      map.put(line[0], Integer.parseInt(line[1]));
      queue.add(line[0]);
    }

    while(true){
      String x = queue.poll();
      if(map.get(x) > q){
        time += q;
        map.put(x, map.get(x) - q);
        queue.add(x);
      }else{
        time += map.get(x);
        map.put(x, time);
        System.out.println(x + " " + map.get(x));
        n--;
      }
      if(n == 0)  break;
    }
  }
} Main
import java.io.*;
import java.util.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Stack;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.Queue;
import java.util.ArrayDeque;
import java.util.Map;
import java.util.LinkedList;

public class Main{
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String[] line = br.readLine().split(" ");
    int n = Integer.parseInt(line[0]);
    int q = Integer.parseInt(line[1]);
    LinkedList<String> queue = new LinkedList<String>();
    int time = 0;
    int cnt = n;
    Map<String, Integer> map = new HashMap<>();

    for(int i = 0; i < n; i++){
      line = br.readLine().split(" ");
      map.put(line[0], Integer.parseInt(line[1]));
      queue.add(line[0]);
    }

    while(true){
      String x = queue.poll();
      if(map.get(x) > q){
        time += q;
        map.put(x, map.get(x) - q);
        queue.add(x);
      }else{
        time += map.get(x);
        map.put(x, time);
        System.out.println(x + " " + map.get(x));
        n--;
      }
      if(n == 0)  break;
    }
  }
}