import java.io.*;
import java.util.*;
 
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<String> ps = new LinkedList<String>();
			LinkedList<Integer> times = new LinkedList<Integer>();
			
            for( int i=0; i<n; i++ ) {
                str = kb.readLine().split( " " );
                ps.offer( str[0] );
                times.offer( Integer.parseInt( str[1] ) );
            }

            StringBuilder output = new	StringBuilder( );	            
            String job;
            int time, t;
            t = 0;
            while( null != ( job = ps.peek() )) {
            	time = times.peek();
            	if( times.peek() <= q ) {
            		output.append( job );
            		output.append( " " );
            		output.append(  t + time );
            		output.append( "\n" );
            		t += time;          		
            	} else {
            		ps.offer( job );
	                times.offer( time - q );
	                t += q;           
            	}
            	ps.poll();
            	times.poll();
            }
            System.out.print( output );
             
        } catch( IOException e ) {
            System.err.println( e );
        }
    }
} import java.io.*; io.* java import java.util.*; util.* java 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<String> ps = new LinkedList<String>();
			LinkedList<Integer> times = new LinkedList<Integer>();
			
            for( int i=0; i<n; i++ ) {
                str = kb.readLine().split( " " );
                ps.offer( str[0] );
                times.offer( Integer.parseInt( str[1] ) );
            }

            StringBuilder output = new	StringBuilder( );	            
            String job;
            int time, t;
            t = 0;
            while( null != ( job = ps.peek() )) {
            	time = times.peek();
            	if( times.peek() <= q ) {
            		output.append( job );
            		output.append( " " );
            		output.append(  t + time );
            		output.append( "\n" );
            		t += time;          		
            	} else {
            		ps.offer( job );
	                times.offer( time - q );
	                t += q;           
            	}
            	ps.poll();
            	times.poll();
            }
            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<String> ps = new LinkedList<String>();
			LinkedList<Integer> times = new LinkedList<Integer>();
			
            for( int i=0; i<n; i++ ) {
                str = kb.readLine().split( " " );
                ps.offer( str[0] );
                times.offer( Integer.parseInt( str[1] ) );
            }

            StringBuilder output = new	StringBuilder( );	            
            String job;
            int time, t;
            t = 0;
            while( null != ( job = ps.peek() )) {
            	time = times.peek();
            	if( times.peek() <= q ) {
            		output.append( job );
            		output.append( " " );
            		output.append(  t + time );
            		output.append( "\n" );
            		t += time;          		
            	} else {
            		ps.offer( job );
	                times.offer( time - q );
	                t += q;           
            	}
            	ps.poll();
            	times.poll();
            }
            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<String> ps = new LinkedList<String>();
			LinkedList<Integer> times = new LinkedList<Integer>();
			
            for( int i=0; i<n; i++ ) {
                str = kb.readLine().split( " " );
                ps.offer( str[0] );
                times.offer( Integer.parseInt( str[1] ) );
            }

            StringBuilder output = new	StringBuilder( );	            
            String job;
            int time, t;
            t = 0;
            while( null != ( job = ps.peek() )) {
            	time = times.peek();
            	if( times.peek() <= q ) {
            		output.append( job );
            		output.append( " " );
            		output.append(  t + time );
            		output.append( "\n" );
            		t += time;          		
            	} else {
            		ps.offer( job );
	                times.offer( time - q );
	                t += q;           
            	}
            	ps.poll();
            	times.poll();
            }
            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<String> ps = new LinkedList<String>();
			LinkedList<Integer> times = new LinkedList<Integer>();
			
            for( int i=0; i<n; i++ ) {
                str = kb.readLine().split( " " );
                ps.offer( str[0] );
                times.offer( Integer.parseInt( str[1] ) );
            }

            StringBuilder output = new	StringBuilder( );	            
            String job;
            int time, t;
            t = 0;
            while( null != ( job = ps.peek() )) {
            	time = times.peek();
            	if( times.peek() <= q ) {
            		output.append( job );
            		output.append( " " );
            		output.append(  t + time );
            		output.append( "\n" );
            		t += time;          		
            	} else {
            		ps.offer( job );
	                times.offer( time - q );
	                t += q;           
            	}
            	ps.poll();
            	times.poll();
            }
            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<String> ps = new LinkedList<String>();
			LinkedList<Integer> times = new LinkedList<Integer>();
			
            for( int i=0; i<n; i++ ) {
                str = kb.readLine().split( " " );
                ps.offer( str[0] );
                times.offer( Integer.parseInt( str[1] ) );
            }

            StringBuilder output = new	StringBuilder( );	            
            String job;
            int time, t;
            t = 0;
            while( null != ( job = ps.peek() )) {
            	time = times.peek();
            	if( times.peek() <= q ) {
            		output.append( job );
            		output.append( " " );
            		output.append(  t + time );
            		output.append( "\n" );
            		t += time;          		
            	} else {
            		ps.offer( job );
	                times.offer( time - q );
	                t += q;           
            	}
            	ps.poll();
            	times.poll();
            }
            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<String> ps = new LinkedList<String>(); ps new LinkedList<String>() LinkedList<Integer> times = new LinkedList<Integer>(); times new LinkedList<Integer>() for( int i=0; i<n; i++ ) {
                str = kb.readLine().split( " " );
                ps.offer( str[0] );
                times.offer( Integer.parseInt( str[1] ) );
            } int i=0; int i=0; i 0 i<n i n i++ i++ i {
                str = kb.readLine().split( " " );
                ps.offer( str[0] );
                times.offer( Integer.parseInt( str[1] ) );
            } {
                str = kb.readLine().split( " " );
                ps.offer( str[0] );
                times.offer( Integer.parseInt( str[1] ) );
            } str = kb.readLine().split( " " ) str kb.readLine().split( " " ) kb.readLine().split kb.readLine() kb.readLine kb " " ps.offer( str[0] ) ps.offer ps str[0] str 0 times.offer( Integer.parseInt( str[1] ) ) times.offer times Integer.parseInt( str[1] ) Integer.parseInt Integer str[1] str 1 StringBuilder output = new	StringBuilder( ); output new	StringBuilder( ) String job; job int time time t; t t = 0 t 0 while( null != ( job = ps.peek() )) {
            	time = times.peek();
            	if( times.peek() <= q ) {
            		output.append( job );
            		output.append( " " );
            		output.append(  t + time );
            		output.append( "\n" );
            		t += time;          		
            	} else {
            		ps.offer( job );
	                times.offer( time - q );
	                t += q;           
            	}
            	ps.poll();
            	times.poll();
            } null != ( job = ps.peek() ) null ( job = ps.peek() ) job ps.peek() ps.peek ps {
            	time = times.peek();
            	if( times.peek() <= q ) {
            		output.append( job );
            		output.append( " " );
            		output.append(  t + time );
            		output.append( "\n" );
            		t += time;          		
            	} else {
            		ps.offer( job );
	                times.offer( time - q );
	                t += q;           
            	}
            	ps.poll();
            	times.poll();
            } time = times.peek() time times.peek() times.peek times if( times.peek() <= q ) {
            		output.append( job );
            		output.append( " " );
            		output.append(  t + time );
            		output.append( "\n" );
            		t += time;          		
            	} else {
            		ps.offer( job );
	                times.offer( time - q );
	                t += q;           
            	} times.peek() <= q times.peek() times.peek times q {
            		output.append( job );
            		output.append( " " );
            		output.append(  t + time );
            		output.append( "\n" );
            		t += time;          		
            	} output.append( job ) output.append output job output.append( " " ) output.append output " " output.append(  t + time ) output.append output t + time t time output.append( "\n" ) output.append output "\n" t += time t time {
            		ps.offer( job );
	                times.offer( time - q );
	                t += q;           
            	} ps.offer( job ) ps.offer ps job times.offer( time - q ) times.offer times time - q time q t += q t q ps.poll() ps.poll ps times.poll() times.poll times System.out.print( output ) System.out.print System.out System System.out output String[] args args
import java.io.*;
import java.util.*;
 
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<String> ps = new LinkedList<String>();
			LinkedList<Integer> times = new LinkedList<Integer>();
			
            for( int i=0; i<n; i++ ) {
                str = kb.readLine().split( " " );
                ps.offer( str[0] );
                times.offer( Integer.parseInt( str[1] ) );
            }

            StringBuilder output = new	StringBuilder( );	            
            String job;
            int time, t;
            t = 0;
            while( null != ( job = ps.peek() )) {
            	time = times.peek();
            	if( times.peek() <= q ) {
            		output.append( job );
            		output.append( " " );
            		output.append(  t + time );
            		output.append( "\n" );
            		t += time;          		
            	} else {
            		ps.offer( job );
	                times.offer( time - q );
	                t += q;           
            	}
            	ps.poll();
            	times.poll();
            }
            System.out.print( output );
             
        } catch( IOException e ) {
            System.err.println( e );
        }
    }
}