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

class Ps {
    String name;
    Integer t;
     
    public Ps( String name, Integer t )
    {
        this.name = name;
        this.t = t;
    }
}

class Main {
    public static void main(String[] args) {
        BufferedReader kb = new BufferedReader( new InputStreamReader( System.in ) );
        try {
  
            String[] str = kb.readLine().split( " " );
            int n = Integer.parseInt( str[0] );
            int q = Integer.parseInt( str[1] );
             
            LinkedList<Ps> queue = new LinkedList<Ps>();
             
            for( int i=0; i<n; i++ ) {
                str = kb.readLine().split( " " );
                queue.offer( new Ps( str[0], Integer.parseInt( str[1] ) ) );
            }
 
            StringBuilder output = new  StringBuilder( );   
            Ps ps;         
            int time;
           	time = 0;
            while( null != ( ps = queue.poll() ) ) {
            	
                if( ps.t <= q ) {
                    output.append( ps.name );
                    output.append( " " );
                    time += ps.t;    
                    output.append(  time );
                    output.append( "\n" );
          
                } else {
                	ps.t -= q;
                    queue.offer( ps );
                    time += q;           
                }
            }
            System.out.print( output );
              
        } catch( IOException e ) {
            System.err.println( e );
        }
    }
} import java.io.*; io.* java import java.util.*; util.* java class Ps {
    String name;
    Integer t;
     
    public Ps( String name, Integer t )
    {
        this.name = name;
        this.t = t;
    }
} Ps String name; name Integer t; t public Ps( String name, Integer t )
    {
        this.name = name;
        this.t = t;
    } Ps {
        this.name = name;
        this.t = t;
    } this.name = name this.name this this.name name this.t = t this.t this this.t t String name name Integer t t class Main {
    public static void main(String[] args) {
        BufferedReader kb = new BufferedReader( new InputStreamReader( System.in ) );
        try {
  
            String[] str = kb.readLine().split( " " );
            int n = Integer.parseInt( str[0] );
            int q = Integer.parseInt( str[1] );
             
            LinkedList<Ps> queue = new LinkedList<Ps>();
             
            for( int i=0; i<n; i++ ) {
                str = kb.readLine().split( " " );
                queue.offer( new Ps( str[0], Integer.parseInt( str[1] ) ) );
            }
 
            StringBuilder output = new  StringBuilder( );   
            Ps ps;         
            int time;
           	time = 0;
            while( null != ( ps = queue.poll() ) ) {
            	
                if( ps.t <= q ) {
                    output.append( ps.name );
                    output.append( " " );
                    time += ps.t;    
                    output.append(  time );
                    output.append( "\n" );
          
                } else {
                	ps.t -= q;
                    queue.offer( ps );
                    time += q;           
                }
            }
            System.out.print( output );
              
        } catch( IOException e ) {
            System.err.println( e );
        }
    }
} Main public static void main(String[] args) {
        BufferedReader kb = new BufferedReader( new InputStreamReader( System.in ) );
        try {
  
            String[] str = kb.readLine().split( " " );
            int n = Integer.parseInt( str[0] );
            int q = Integer.parseInt( str[1] );
             
            LinkedList<Ps> queue = new LinkedList<Ps>();
             
            for( int i=0; i<n; i++ ) {
                str = kb.readLine().split( " " );
                queue.offer( new Ps( str[0], Integer.parseInt( str[1] ) ) );
            }
 
            StringBuilder output = new  StringBuilder( );   
            Ps ps;         
            int time;
           	time = 0;
            while( null != ( ps = queue.poll() ) ) {
            	
                if( ps.t <= q ) {
                    output.append( ps.name );
                    output.append( " " );
                    time += ps.t;    
                    output.append(  time );
                    output.append( "\n" );
          
                } else {
                	ps.t -= q;
                    queue.offer( ps );
                    time += q;           
                }
            }
            System.out.print( output );
              
        } catch( IOException e ) {
            System.err.println( e );
        }
    } main {
        BufferedReader kb = new BufferedReader( new InputStreamReader( System.in ) );
        try {
  
            String[] str = kb.readLine().split( " " );
            int n = Integer.parseInt( str[0] );
            int q = Integer.parseInt( str[1] );
             
            LinkedList<Ps> queue = new LinkedList<Ps>();
             
            for( int i=0; i<n; i++ ) {
                str = kb.readLine().split( " " );
                queue.offer( new Ps( str[0], Integer.parseInt( str[1] ) ) );
            }
 
            StringBuilder output = new  StringBuilder( );   
            Ps ps;         
            int time;
           	time = 0;
            while( null != ( ps = queue.poll() ) ) {
            	
                if( ps.t <= q ) {
                    output.append( ps.name );
                    output.append( " " );
                    time += ps.t;    
                    output.append(  time );
                    output.append( "\n" );
          
                } else {
                	ps.t -= q;
                    queue.offer( ps );
                    time += q;           
                }
            }
            System.out.print( output );
              
        } catch( IOException e ) {
            System.err.println( e );
        }
    } BufferedReader kb = new BufferedReader( new InputStreamReader( System.in ) ); kb new BufferedReader( new InputStreamReader( System.in ) ) try {
  
            String[] str = kb.readLine().split( " " );
            int n = Integer.parseInt( str[0] );
            int q = Integer.parseInt( str[1] );
             
            LinkedList<Ps> queue = new LinkedList<Ps>();
             
            for( int i=0; i<n; i++ ) {
                str = kb.readLine().split( " " );
                queue.offer( new Ps( str[0], Integer.parseInt( str[1] ) ) );
            }
 
            StringBuilder output = new  StringBuilder( );   
            Ps ps;         
            int time;
           	time = 0;
            while( null != ( ps = queue.poll() ) ) {
            	
                if( ps.t <= q ) {
                    output.append( ps.name );
                    output.append( " " );
                    time += ps.t;    
                    output.append(  time );
                    output.append( "\n" );
          
                } else {
                	ps.t -= q;
                    queue.offer( ps );
                    time += q;           
                }
            }
            System.out.print( output );
              
        } catch( IOException e ) {
            System.err.println( e );
        } catch( IOException e ) {
            System.err.println( e );
        } IOException e {
            System.err.println( e );
        } System.err.println( e ) System.err.println System.err System System.err e {
  
            String[] str = kb.readLine().split( " " );
            int n = Integer.parseInt( str[0] );
            int q = Integer.parseInt( str[1] );
             
            LinkedList<Ps> queue = new LinkedList<Ps>();
             
            for( int i=0; i<n; i++ ) {
                str = kb.readLine().split( " " );
                queue.offer( new Ps( str[0], Integer.parseInt( str[1] ) ) );
            }
 
            StringBuilder output = new  StringBuilder( );   
            Ps ps;         
            int time;
           	time = 0;
            while( null != ( ps = queue.poll() ) ) {
            	
                if( ps.t <= q ) {
                    output.append( ps.name );
                    output.append( " " );
                    time += ps.t;    
                    output.append(  time );
                    output.append( "\n" );
          
                } else {
                	ps.t -= q;
                    queue.offer( ps );
                    time += q;           
                }
            }
            System.out.print( output );
              
        } String[] str = kb.readLine().split( " " ); str kb.readLine().split( " " ) kb.readLine().split kb.readLine() kb.readLine kb " " int n = Integer.parseInt( str[0] ); n Integer.parseInt( str[0] ) Integer.parseInt Integer str[0] str 0 int q = Integer.parseInt( str[1] ); q Integer.parseInt( str[1] ) Integer.parseInt Integer str[1] str 1 LinkedList<Ps> queue = new LinkedList<Ps>(); queue new LinkedList<Ps>() for( int i=0; i<n; i++ ) {
                str = kb.readLine().split( " " );
                queue.offer( new Ps( str[0], Integer.parseInt( str[1] ) ) );
            } int i=0; int i=0; i 0 i<n i n i++ i++ i {
                str = kb.readLine().split( " " );
                queue.offer( new Ps( str[0], Integer.parseInt( str[1] ) ) );
            } {
                str = kb.readLine().split( " " );
                queue.offer( new Ps( str[0], Integer.parseInt( str[1] ) ) );
            } str = kb.readLine().split( " " ) str kb.readLine().split( " " ) kb.readLine().split kb.readLine() kb.readLine kb " " queue.offer( new Ps( str[0], Integer.parseInt( str[1] ) ) ) queue.offer queue new Ps( str[0], Integer.parseInt( str[1] ) ) StringBuilder output = new  StringBuilder( ); output new  StringBuilder( ) Ps ps; ps int time; time time = 0 time 0 while( null != ( ps = queue.poll() ) ) {
            	
                if( ps.t <= q ) {
                    output.append( ps.name );
                    output.append( " " );
                    time += ps.t;    
                    output.append(  time );
                    output.append( "\n" );
          
                } else {
                	ps.t -= q;
                    queue.offer( ps );
                    time += q;           
                }
            } null != ( ps = queue.poll() ) null ( ps = queue.poll() ) ps queue.poll() queue.poll queue {
            	
                if( ps.t <= q ) {
                    output.append( ps.name );
                    output.append( " " );
                    time += ps.t;    
                    output.append(  time );
                    output.append( "\n" );
          
                } else {
                	ps.t -= q;
                    queue.offer( ps );
                    time += q;           
                }
            } if( ps.t <= q ) {
                    output.append( ps.name );
                    output.append( " " );
                    time += ps.t;    
                    output.append(  time );
                    output.append( "\n" );
          
                } else {
                	ps.t -= q;
                    queue.offer( ps );
                    time += q;           
                } ps.t <= q ps.t ps ps.t q {
                    output.append( ps.name );
                    output.append( " " );
                    time += ps.t;    
                    output.append(  time );
                    output.append( "\n" );
          
                } output.append( ps.name ) output.append output ps.name ps ps.name output.append( " " ) output.append output " " time += ps.t time ps.t ps ps.t output.append(  time ) output.append output time output.append( "\n" ) output.append output "\n" {
                	ps.t -= q;
                    queue.offer( ps );
                    time += q;           
                } ps.t -= q ps.t ps ps.t q queue.offer( ps ) queue.offer queue ps time += q time q System.out.print( output ) System.out.print System.out System System.out output String[] args args
import java.io.*;
import java.util.*;

class Ps {
    String name;
    Integer t;
     
    public Ps( String name, Integer t )
    {
        this.name = name;
        this.t = t;
    }
}

class Main {
    public static void main(String[] args) {
        BufferedReader kb = new BufferedReader( new InputStreamReader( System.in ) );
        try {
  
            String[] str = kb.readLine().split( " " );
            int n = Integer.parseInt( str[0] );
            int q = Integer.parseInt( str[1] );
             
            LinkedList<Ps> queue = new LinkedList<Ps>();
             
            for( int i=0; i<n; i++ ) {
                str = kb.readLine().split( " " );
                queue.offer( new Ps( str[0], Integer.parseInt( str[1] ) ) );
            }
 
            StringBuilder output = new  StringBuilder( );   
            Ps ps;         
            int time;
           	time = 0;
            while( null != ( ps = queue.poll() ) ) {
            	
                if( ps.t <= q ) {
                    output.append( ps.name );
                    output.append( " " );
                    time += ps.t;    
                    output.append(  time );
                    output.append( "\n" );
          
                } else {
                	ps.t -= q;
                    queue.offer( ps );
                    time += q;           
                }
            }
            System.out.print( output );
              
        } catch( IOException e ) {
            System.err.println( e );
        }
    }
}