import java.io.*;
import java.util.*;
import java.lang.*;

class Main{
  public static void main(String[] args) throws IOException{
    Scanner scan=new Scanner(System.in);
    int n=Integer.parseInt(scan.next());
    int q=Integer.parseInt(scan.next());
    int sumTime=0;
    Queue<Process> queue=new ArrayDeque<Process>();

    for(int i=0;i<n;i++){
      String namae=scan.next();
      int Time=Integer.parseInt(scan.next());
      queue.add(new Process(namae,Time));
    }

    Queue<Process> ans=new ArrayDeque<>();
    while(!queue.isEmpty()){
      Process buf=queue.remove();
      if(buf.pTime-q<=0){
        int buf2=buf.pTime;
        buf.pTime+=sumTime;
        sumTime+=buf2;
        ans.add(buf);
      }else {
        buf.pTime-=q;
        queue.add(buf);
        sumTime+=q;
      }
    }
    for(Process p:ans){
      System.out.println(p.name+" "+p.pTime);
    }
  }
}
class Process{
  String name;
  int pTime;

  public Process(String name,int pTime){
    this.name=name;
    this.pTime=pTime;
  }
}
 import java.io.*; io.* java import java.util.*; util.* java import java.lang.*; lang.* java class Main{
  public static void main(String[] args) throws IOException{
    Scanner scan=new Scanner(System.in);
    int n=Integer.parseInt(scan.next());
    int q=Integer.parseInt(scan.next());
    int sumTime=0;
    Queue<Process> queue=new ArrayDeque<Process>();

    for(int i=0;i<n;i++){
      String namae=scan.next();
      int Time=Integer.parseInt(scan.next());
      queue.add(new Process(namae,Time));
    }

    Queue<Process> ans=new ArrayDeque<>();
    while(!queue.isEmpty()){
      Process buf=queue.remove();
      if(buf.pTime-q<=0){
        int buf2=buf.pTime;
        buf.pTime+=sumTime;
        sumTime+=buf2;
        ans.add(buf);
      }else {
        buf.pTime-=q;
        queue.add(buf);
        sumTime+=q;
      }
    }
    for(Process p:ans){
      System.out.println(p.name+" "+p.pTime);
    }
  }
} Main public static void main(String[] args) throws IOException{
    Scanner scan=new Scanner(System.in);
    int n=Integer.parseInt(scan.next());
    int q=Integer.parseInt(scan.next());
    int sumTime=0;
    Queue<Process> queue=new ArrayDeque<Process>();

    for(int i=0;i<n;i++){
      String namae=scan.next();
      int Time=Integer.parseInt(scan.next());
      queue.add(new Process(namae,Time));
    }

    Queue<Process> ans=new ArrayDeque<>();
    while(!queue.isEmpty()){
      Process buf=queue.remove();
      if(buf.pTime-q<=0){
        int buf2=buf.pTime;
        buf.pTime+=sumTime;
        sumTime+=buf2;
        ans.add(buf);
      }else {
        buf.pTime-=q;
        queue.add(buf);
        sumTime+=q;
      }
    }
    for(Process p:ans){
      System.out.println(p.name+" "+p.pTime);
    }
  } main {
    Scanner scan=new Scanner(System.in);
    int n=Integer.parseInt(scan.next());
    int q=Integer.parseInt(scan.next());
    int sumTime=0;
    Queue<Process> queue=new ArrayDeque<Process>();

    for(int i=0;i<n;i++){
      String namae=scan.next();
      int Time=Integer.parseInt(scan.next());
      queue.add(new Process(namae,Time));
    }

    Queue<Process> ans=new ArrayDeque<>();
    while(!queue.isEmpty()){
      Process buf=queue.remove();
      if(buf.pTime-q<=0){
        int buf2=buf.pTime;
        buf.pTime+=sumTime;
        sumTime+=buf2;
        ans.add(buf);
      }else {
        buf.pTime-=q;
        queue.add(buf);
        sumTime+=q;
      }
    }
    for(Process p:ans){
      System.out.println(p.name+" "+p.pTime);
    }
  } Scanner scan=new Scanner(System.in); scan new Scanner(System.in) int n=Integer.parseInt(scan.next()); n Integer.parseInt(scan.next()) Integer.parseInt Integer scan.next() scan.next scan int q=Integer.parseInt(scan.next()); q Integer.parseInt(scan.next()) Integer.parseInt Integer scan.next() scan.next scan int sumTime=0; sumTime 0 Queue<Process> queue=new ArrayDeque<Process>(); queue new ArrayDeque<Process>() for(int i=0;i<n;i++){
      String namae=scan.next();
      int Time=Integer.parseInt(scan.next());
      queue.add(new Process(namae,Time));
    } int i=0; int i=0; i 0 i<n i n i++ i++ i {
      String namae=scan.next();
      int Time=Integer.parseInt(scan.next());
      queue.add(new Process(namae,Time));
    } {
      String namae=scan.next();
      int Time=Integer.parseInt(scan.next());
      queue.add(new Process(namae,Time));
    } String namae=scan.next(); namae scan.next() scan.next scan int Time=Integer.parseInt(scan.next()); Time Integer.parseInt(scan.next()) Integer.parseInt Integer scan.next() scan.next scan queue.add(new Process(namae,Time)) queue.add queue new Process(namae,Time) Queue<Process> ans=new ArrayDeque<>(); ans new ArrayDeque<>() while(!queue.isEmpty()){
      Process buf=queue.remove();
      if(buf.pTime-q<=0){
        int buf2=buf.pTime;
        buf.pTime+=sumTime;
        sumTime+=buf2;
        ans.add(buf);
      }else {
        buf.pTime-=q;
        queue.add(buf);
        sumTime+=q;
      }
    } !queue.isEmpty() queue.isEmpty() queue.isEmpty queue {
      Process buf=queue.remove();
      if(buf.pTime-q<=0){
        int buf2=buf.pTime;
        buf.pTime+=sumTime;
        sumTime+=buf2;
        ans.add(buf);
      }else {
        buf.pTime-=q;
        queue.add(buf);
        sumTime+=q;
      }
    } Process buf=queue.remove(); buf queue.remove() queue.remove queue if(buf.pTime-q<=0){
        int buf2=buf.pTime;
        buf.pTime+=sumTime;
        sumTime+=buf2;
        ans.add(buf);
      }else {
        buf.pTime-=q;
        queue.add(buf);
        sumTime+=q;
      } buf.pTime-q<=0 buf.pTime-q buf.pTime buf buf.pTime q 0 {
        int buf2=buf.pTime;
        buf.pTime+=sumTime;
        sumTime+=buf2;
        ans.add(buf);
      } int buf2=buf.pTime; buf2 buf.pTime buf buf.pTime buf.pTime+=sumTime buf.pTime buf buf.pTime sumTime sumTime+=buf2 sumTime buf2 ans.add(buf) ans.add ans buf {
        buf.pTime-=q;
        queue.add(buf);
        sumTime+=q;
      } buf.pTime-=q buf.pTime buf buf.pTime q queue.add(buf) queue.add queue buf sumTime+=q sumTime q for(Process p:ans){
      System.out.println(p.name+" "+p.pTime);
    } Process p ans {
      System.out.println(p.name+" "+p.pTime);
    } {
      System.out.println(p.name+" "+p.pTime);
    } System.out.println(p.name+" "+p.pTime) System.out.println System.out System System.out p.name+" "+p.pTime p.name+" "+p.pTime p.name p p.name " " p.pTime p p.pTime String[] args args class Process{
  String name;
  int pTime;

  public Process(String name,int pTime){
    this.name=name;
    this.pTime=pTime;
  }
} Process String name; name int pTime; pTime public Process(String name,int pTime){
    this.name=name;
    this.pTime=pTime;
  } Process {
    this.name=name;
    this.pTime=pTime;
  } this.name=name this.name this this.name name this.pTime=pTime this.pTime this this.pTime pTime String name name int pTime pTime
import java.io.*;
import java.util.*;
import java.lang.*;

class Main{
  public static void main(String[] args) throws IOException{
    Scanner scan=new Scanner(System.in);
    int n=Integer.parseInt(scan.next());
    int q=Integer.parseInt(scan.next());
    int sumTime=0;
    Queue<Process> queue=new ArrayDeque<Process>();

    for(int i=0;i<n;i++){
      String namae=scan.next();
      int Time=Integer.parseInt(scan.next());
      queue.add(new Process(namae,Time));
    }

    Queue<Process> ans=new ArrayDeque<>();
    while(!queue.isEmpty()){
      Process buf=queue.remove();
      if(buf.pTime-q<=0){
        int buf2=buf.pTime;
        buf.pTime+=sumTime;
        sumTime+=buf2;
        ans.add(buf);
      }else {
        buf.pTime-=q;
        queue.add(buf);
        sumTime+=q;
      }
    }
    for(Process p:ans){
      System.out.println(p.name+" "+p.pTime);
    }
  }
}
class Process{
  String name;
  int pTime;

  public Process(String name,int pTime){
    this.name=name;
    this.pTime=pTime;
  }
}

