import java.io.*;

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] );
			
			
			final int LEN = 100005;
			Ps[] queue = new Ps[LEN];
			int head = 0, tail = n-1;				
            for( int i=0; i<n; i++ ) {
                str = kb.readLine().split( " " );
                queue[i] = new Ps( str[0], Integer.parseInt( str[1] ) );
            }

            StringBuilder output = new	StringBuilder( );
			String name;
            int time, t;
           	time = 0;
            while( 0 != n ) {
	           	name = queue[ head ].name;
            	t = queue[ head ].t;
            	if( t <= q ) {
            		queue[ head ] = null;
            		n--;
            		output.append( name );
            		output.append( " " );
            		output.append(  time + t );
            		output.append( "\n" );
            		time += t;          		
            	} else {
            		tail++;
            		if( LEN == tail ) { tail = 0; }
	           		queue[tail] = new Ps( name, t - q );
	                time += q;        
            	}
          		head++;
          		if( LEN == head ) { head = 0; }
            }
            System.out.print( output );
             
        } catch( IOException e ) {
            System.err.println( e );
        }
    }
} import java.io.*; io.* 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] );
			
			
			final int LEN = 100005;
			Ps[] queue = new Ps[LEN];
			int head = 0, tail = n-1;				
            for( int i=0; i<n; i++ ) {
                str = kb.readLine().split( " " );
                queue[i] = new Ps( str[0], Integer.parseInt( str[1] ) );
            }

            StringBuilder output = new	StringBuilder( );
			String name;
            int time, t;
           	time = 0;
            while( 0 != n ) {
	           	name = queue[ head ].name;
            	t = queue[ head ].t;
            	if( t <= q ) {
            		queue[ head ] = null;
            		n--;
            		output.append( name );
            		output.append( " " );
            		output.append(  time + t );
            		output.append( "\n" );
            		time += t;          		
            	} else {
            		tail++;
            		if( LEN == tail ) { tail = 0; }
	           		queue[tail] = new Ps( name, t - q );
	                time += q;        
            	}
          		head++;
          		if( LEN == head ) { head = 0; }
            }
            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] );
			
			
			final int LEN = 100005;
			Ps[] queue = new Ps[LEN];
			int head = 0, tail = n-1;				
            for( int i=0; i<n; i++ ) {
                str = kb.readLine().split( " " );
                queue[i] = new Ps( str[0], Integer.parseInt( str[1] ) );
            }

            StringBuilder output = new	StringBuilder( );
			String name;
            int time, t;
           	time = 0;
            while( 0 != n ) {
	           	name = queue[ head ].name;
            	t = queue[ head ].t;
            	if( t <= q ) {
            		queue[ head ] = null;
            		n--;
            		output.append( name );
            		output.append( " " );
            		output.append(  time + t );
            		output.append( "\n" );
            		time += t;          		
            	} else {
            		tail++;
            		if( LEN == tail ) { tail = 0; }
	           		queue[tail] = new Ps( name, t - q );
	                time += q;        
            	}
          		head++;
          		if( LEN == head ) { head = 0; }
            }
            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] );
			
			
			final int LEN = 100005;
			Ps[] queue = new Ps[LEN];
			int head = 0, tail = n-1;				
            for( int i=0; i<n; i++ ) {
                str = kb.readLine().split( " " );
                queue[i] = new Ps( str[0], Integer.parseInt( str[1] ) );
            }

            StringBuilder output = new	StringBuilder( );
			String name;
            int time, t;
           	time = 0;
            while( 0 != n ) {
	           	name = queue[ head ].name;
            	t = queue[ head ].t;
            	if( t <= q ) {
            		queue[ head ] = null;
            		n--;
            		output.append( name );
            		output.append( " " );
            		output.append(  time + t );
            		output.append( "\n" );
            		time += t;          		
            	} else {
            		tail++;
            		if( LEN == tail ) { tail = 0; }
	           		queue[tail] = new Ps( name, t - q );
	                time += q;        
            	}
          		head++;
          		if( LEN == head ) { head = 0; }
            }
            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] );
			
			
			final int LEN = 100005;
			Ps[] queue = new Ps[LEN];
			int head = 0, tail = n-1;				
            for( int i=0; i<n; i++ ) {
                str = kb.readLine().split( " " );
                queue[i] = new Ps( str[0], Integer.parseInt( str[1] ) );
            }

            StringBuilder output = new	StringBuilder( );
			String name;
            int time, t;
           	time = 0;
            while( 0 != n ) {
	           	name = queue[ head ].name;
            	t = queue[ head ].t;
            	if( t <= q ) {
            		queue[ head ] = null;
            		n--;
            		output.append( name );
            		output.append( " " );
            		output.append(  time + t );
            		output.append( "\n" );
            		time += t;          		
            	} else {
            		tail++;
            		if( LEN == tail ) { tail = 0; }
	           		queue[tail] = new Ps( name, t - q );
	                time += q;        
            	}
          		head++;
          		if( LEN == head ) { head = 0; }
            }
            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] );
			
			
			final int LEN = 100005;
			Ps[] queue = new Ps[LEN];
			int head = 0, tail = n-1;				
            for( int i=0; i<n; i++ ) {
                str = kb.readLine().split( " " );
                queue[i] = new Ps( str[0], Integer.parseInt( str[1] ) );
            }

            StringBuilder output = new	StringBuilder( );
			String name;
            int time, t;
           	time = 0;
            while( 0 != n ) {
	           	name = queue[ head ].name;
            	t = queue[ head ].t;
            	if( t <= q ) {
            		queue[ head ] = null;
            		n--;
            		output.append( name );
            		output.append( " " );
            		output.append(  time + t );
            		output.append( "\n" );
            		time += t;          		
            	} else {
            		tail++;
            		if( LEN == tail ) { tail = 0; }
	           		queue[tail] = new Ps( name, t - q );
	                time += q;        
            	}
          		head++;
          		if( LEN == head ) { head = 0; }
            }
            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 final int LEN = 100005; LEN 100005 Ps[] queue = new Ps[LEN]; queue new Ps[LEN] LEN int head = 0 head 0 tail = n-1; tail n-1 n 1 for( int i=0; i<n; i++ ) {
                str = kb.readLine().split( " " );
                queue[i] = 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[i] = new Ps( str[0], Integer.parseInt( str[1] ) );
            } {
                str = kb.readLine().split( " " );
                queue[i] = 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[i] = new Ps( str[0], Integer.parseInt( str[1] ) ) queue[i] queue i new Ps( str[0], Integer.parseInt( str[1] ) ) StringBuilder output = new	StringBuilder( ); output new	StringBuilder( ) String name; name int time time t; t time = 0 time 0 while( 0 != n ) {
	           	name = queue[ head ].name;
            	t = queue[ head ].t;
            	if( t <= q ) {
            		queue[ head ] = null;
            		n--;
            		output.append( name );
            		output.append( " " );
            		output.append(  time + t );
            		output.append( "\n" );
            		time += t;          		
            	} else {
            		tail++;
            		if( LEN == tail ) { tail = 0; }
	           		queue[tail] = new Ps( name, t - q );
	                time += q;        
            	}
          		head++;
          		if( LEN == head ) { head = 0; }
            } 0 != n 0 n {
	           	name = queue[ head ].name;
            	t = queue[ head ].t;
            	if( t <= q ) {
            		queue[ head ] = null;
            		n--;
            		output.append( name );
            		output.append( " " );
            		output.append(  time + t );
            		output.append( "\n" );
            		time += t;          		
            	} else {
            		tail++;
            		if( LEN == tail ) { tail = 0; }
	           		queue[tail] = new Ps( name, t - q );
	                time += q;        
            	}
          		head++;
          		if( LEN == head ) { head = 0; }
            } name = queue[ head ].name name queue[ head ].name queue[ head ] queue head queue[ head ].name t = queue[ head ].t t queue[ head ].t queue[ head ] queue head queue[ head ].t if( t <= q ) {
            		queue[ head ] = null;
            		n--;
            		output.append( name );
            		output.append( " " );
            		output.append(  time + t );
            		output.append( "\n" );
            		time += t;          		
            	} else {
            		tail++;
            		if( LEN == tail ) { tail = 0; }
	           		queue[tail] = new Ps( name, t - q );
	                time += q;        
            	} t <= q t q {
            		queue[ head ] = null;
            		n--;
            		output.append( name );
            		output.append( " " );
            		output.append(  time + t );
            		output.append( "\n" );
            		time += t;          		
            	} queue[ head ] = null queue[ head ] queue head null n-- n output.append( name ) output.append output name output.append( " " ) output.append output " " output.append(  time + t ) output.append output time + t time t output.append( "\n" ) output.append output "\n" time += t time t {
            		tail++;
            		if( LEN == tail ) { tail = 0; }
	           		queue[tail] = new Ps( name, t - q );
	                time += q;        
            	} tail++ tail if( LEN == tail ) { tail = 0; } LEN == tail LEN tail { tail = 0; } tail = 0 tail 0 queue[tail] = new Ps( name, t - q ) queue[tail] queue tail new Ps( name, t - q ) time += q time q head++ head if( LEN == head ) { head = 0; } LEN == head LEN head { head = 0; } head = 0 head 0 System.out.print( output ) System.out.print System.out System System.out output String[] args args
import java.io.*;

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] );
			
			
			final int LEN = 100005;
			Ps[] queue = new Ps[LEN];
			int head = 0, tail = n-1;				
            for( int i=0; i<n; i++ ) {
                str = kb.readLine().split( " " );
                queue[i] = new Ps( str[0], Integer.parseInt( str[1] ) );
            }

            StringBuilder output = new	StringBuilder( );
			String name;
            int time, t;
           	time = 0;
            while( 0 != n ) {
	           	name = queue[ head ].name;
            	t = queue[ head ].t;
            	if( t <= q ) {
            		queue[ head ] = null;
            		n--;
            		output.append( name );
            		output.append( " " );
            		output.append(  time + t );
            		output.append( "\n" );
            		time += t;          		
            	} else {
            		tail++;
            		if( LEN == tail ) { tail = 0; }
	           		queue[tail] = new Ps( name, t - q );
	                time += q;        
            	}
          		head++;
          		if( LEN == head ) { head = 0; }
            }
            System.out.print( output );
             
        } catch( IOException e ) {
            System.err.println( e );
        }
    }
}