import java.util.Scanner;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    int q = sc.nextInt();

    int s = 0;
    int g = n-1;

    int tt = 0;

    String[] name = new String[n];
    int[] time = new int[n];

    for(int i=0; i<n; i++){
      name[i] = sc.next();
      time[i] = sc.nextInt();
    }

    while(true){
      if(time[s] > q){
        time[(g+1)%n] = time[s]-q;
        name[(g+1)%n] = name[s];
        tt = tt+q;
        g = (g+1)%n;
        s = (s+1)%n;
      }
      else{
        tt = tt+time[s];
        if(s == g){
          System.out.println(name[s]+" "+tt);
          break;
        }
        else{
          System.out.println(name[s]+" "+tt);
          s = (s+1)%n;
        }
      }
    }

  }
}


/tmp/hf-datasets-cache/medium/datasets/42704881117311-config-parquet-and-info-qiankunmu-Project_CodeNet-896c9d36/hub/datasets--qiankunmu--Project_CodeNet_Python800_and_Java250/snapshots/c899fde44a77ba1cc14973ed3de064e4ff3aadc7/Project_CodeNet_Java250.tar.gz