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;
        }
      }
    }

  }
}
 import java.util.Scanner; Scanner java.util 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;
        }
      }
    }

  }
} 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;
        }
      }
    }

  } main {
    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;
        }
      }
    }

  } 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 int s = 0; s 0 int g = n-1; g n-1 n 1 int tt = 0; tt 0 String[] name = new String[n]; name new String[n] n int[] time = new int[n]; time new int[n] n for(int i=0; i<n; i++){
      name[i] = sc.next();
      time[i] = sc.nextInt();
    } int i=0; int i=0; i 0 i<n i n i++ i++ i {
      name[i] = sc.next();
      time[i] = sc.nextInt();
    } {
      name[i] = sc.next();
      time[i] = sc.nextInt();
    } name[i] = sc.next() name[i] name i sc.next() sc.next sc time[i] = sc.nextInt() time[i] time i sc.nextInt() sc.nextInt sc 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;
        }
      }
    } 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;
        }
      }
    } 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;
        }
      } time[s] > q time[s] 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;
      } time[(g+1)%n] = time[s]-q time[(g+1)%n] time (g+1)%n (g+1) g 1 n time[s]-q time[s] time s q name[(g+1)%n] = name[s] name[(g+1)%n] name (g+1)%n (g+1) g 1 n name[s] name s tt = tt+q tt tt+q tt q g = (g+1)%n g (g+1)%n (g+1) g 1 n s = (s+1)%n s (s+1)%n (s+1) s 1 n {
        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;
        }
      } tt = tt+time[s] tt tt+time[s] tt time[s] time s if(s == g){
          System.out.println(name[s]+" "+tt);
          break;
        }
        else{
          System.out.println(name[s]+" "+tt);
          s = (s+1)%n;
        } s == g s g {
          System.out.println(name[s]+" "+tt);
          break;
        } System.out.println(name[s]+" "+tt) System.out.println System.out System System.out name[s]+" "+tt name[s]+" "+tt name[s] name s " " tt break; {
          System.out.println(name[s]+" "+tt);
          s = (s+1)%n;
        } System.out.println(name[s]+" "+tt) System.out.println System.out System System.out name[s]+" "+tt name[s]+" "+tt name[s] name s " " tt s = (s+1)%n s (s+1)%n (s+1) s 1 n String[] args args
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;
        }
      }
    }

  }
}

