import java.util.*;

public class Main {
    Scanner sc = new Scanner(System.in);
    
	int n = 100001 ; int total = 0 ;
	int[] time = new int[n];
	String[] name = new String[n];
	int topInt = 0 ,topString=0;  //キューの先頭
	int bottomInt = 0 ,bottomString=0;//キューの末尾 +1
	
	void enQueueInt(int m){
		time[bottomInt] = m ;
		if(bottomInt == n-1) bottomInt = 0;
		else bottomInt++ ;
	}
	void enQueueString(String m){
		name[bottomString] = m ;
		if(bottomString == n-1) bottomString = 0;
		else bottomString++ ;
	}
	
	
	int deQueueInt(){
		int x = time[topInt];
		if(topInt == n-1) topInt = 0;
		else topInt++;
		return x ;
	}
	String deQueueString(){
		String x = name[topString];
		if(topString == n-1) topString = 0;
		else topString++;
		return x ;
	}
	
	void run(){
	    int m = sc.nextInt();
	    int q = sc.nextInt();
	    
	    for(int i=0;i<m;i++){
	        enQueueString(sc.next());
	        enQueueInt(sc.nextInt());
	    }

	    int x ; String y ;
	    while(topInt != bottomInt){
	        x = deQueueInt();
	        y = deQueueString();
	        
	        if(x <= q){
	            total += x;
	            System.out.printf("%s %d\n",y,total);
	            continue;
	        }
	        
	        x -= q; enQueueInt(x); enQueueString(y); total+=q;
	    }
	}
	
    public static void main(String[] args) throws Exception {
        new Main().run();
    }
} import java.util.*; util.* java public class Main {
    Scanner sc = new Scanner(System.in);
    
	int n = 100001 ; int total = 0 ;
	int[] time = new int[n];
	String[] name = new String[n];
	int topInt = 0 ,topString=0;  //キューの先頭
	int bottomInt = 0 ,bottomString=0;//キューの末尾 +1
	
	void enQueueInt(int m){
		time[bottomInt] = m ;
		if(bottomInt == n-1) bottomInt = 0;
		else bottomInt++ ;
	}
	void enQueueString(String m){
		name[bottomString] = m ;
		if(bottomString == n-1) bottomString = 0;
		else bottomString++ ;
	}
	
	
	int deQueueInt(){
		int x = time[topInt];
		if(topInt == n-1) topInt = 0;
		else topInt++;
		return x ;
	}
	String deQueueString(){
		String x = name[topString];
		if(topString == n-1) topString = 0;
		else topString++;
		return x ;
	}
	
	void run(){
	    int m = sc.nextInt();
	    int q = sc.nextInt();
	    
	    for(int i=0;i<m;i++){
	        enQueueString(sc.next());
	        enQueueInt(sc.nextInt());
	    }

	    int x ; String y ;
	    while(topInt != bottomInt){
	        x = deQueueInt();
	        y = deQueueString();
	        
	        if(x <= q){
	            total += x;
	            System.out.printf("%s %d\n",y,total);
	            continue;
	        }
	        
	        x -= q; enQueueInt(x); enQueueString(y); total+=q;
	    }
	}
	
    public static void main(String[] args) throws Exception {
        new Main().run();
    }
} Main Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = 100001 ; n 100001 int total = 0 ; total 0 int[] time = new int[n]; time new int[n] n String[] name = new String[n]; name new String[n] n int topInt = 0 topInt 0 topString=0;  //キューの先頭 topString 0 int bottomInt = 0 bottomInt 0 bottomString=0;//キューの末尾 +1 bottomString 0 void enQueueInt(int m){
		time[bottomInt] = m ;
		if(bottomInt == n-1) bottomInt = 0;
		else bottomInt++ ;
	} enQueueInt {
		time[bottomInt] = m ;
		if(bottomInt == n-1) bottomInt = 0;
		else bottomInt++ ;
	} time[bottomInt] = m time[bottomInt] time bottomInt m if(bottomInt == n-1) bottomInt = 0;
		else bottomInt++ ; bottomInt == n-1 bottomInt n-1 n 1 bottomInt = 0 bottomInt 0 bottomInt++ bottomInt int m m void enQueueString(String m){
		name[bottomString] = m ;
		if(bottomString == n-1) bottomString = 0;
		else bottomString++ ;
	} enQueueString {
		name[bottomString] = m ;
		if(bottomString == n-1) bottomString = 0;
		else bottomString++ ;
	} name[bottomString] = m name[bottomString] name bottomString m if(bottomString == n-1) bottomString = 0;
		else bottomString++ ; bottomString == n-1 bottomString n-1 n 1 bottomString = 0 bottomString 0 bottomString++ bottomString String m m int deQueueInt(){
		int x = time[topInt];
		if(topInt == n-1) topInt = 0;
		else topInt++;
		return x ;
	} deQueueInt {
		int x = time[topInt];
		if(topInt == n-1) topInt = 0;
		else topInt++;
		return x ;
	} int x = time[topInt]; x time[topInt] time topInt if(topInt == n-1) topInt = 0;
		else topInt++; topInt == n-1 topInt n-1 n 1 topInt = 0 topInt 0 topInt++ topInt return x ; x String deQueueString(){
		String x = name[topString];
		if(topString == n-1) topString = 0;
		else topString++;
		return x ;
	} deQueueString {
		String x = name[topString];
		if(topString == n-1) topString = 0;
		else topString++;
		return x ;
	} String x = name[topString]; x name[topString] name topString if(topString == n-1) topString = 0;
		else topString++; topString == n-1 topString n-1 n 1 topString = 0 topString 0 topString++ topString return x ; x void run(){
	    int m = sc.nextInt();
	    int q = sc.nextInt();
	    
	    for(int i=0;i<m;i++){
	        enQueueString(sc.next());
	        enQueueInt(sc.nextInt());
	    }

	    int x ; String y ;
	    while(topInt != bottomInt){
	        x = deQueueInt();
	        y = deQueueString();
	        
	        if(x <= q){
	            total += x;
	            System.out.printf("%s %d\n",y,total);
	            continue;
	        }
	        
	        x -= q; enQueueInt(x); enQueueString(y); total+=q;
	    }
	} run {
	    int m = sc.nextInt();
	    int q = sc.nextInt();
	    
	    for(int i=0;i<m;i++){
	        enQueueString(sc.next());
	        enQueueInt(sc.nextInt());
	    }

	    int x ; String y ;
	    while(topInt != bottomInt){
	        x = deQueueInt();
	        y = deQueueString();
	        
	        if(x <= q){
	            total += x;
	            System.out.printf("%s %d\n",y,total);
	            continue;
	        }
	        
	        x -= q; enQueueInt(x); enQueueString(y); total+=q;
	    }
	} int m = sc.nextInt(); m sc.nextInt() sc.nextInt sc int q = sc.nextInt(); q sc.nextInt() sc.nextInt sc for(int i=0;i<m;i++){
	        enQueueString(sc.next());
	        enQueueInt(sc.nextInt());
	    } int i=0; int i=0; i 0 i<m i m i++ i++ i {
	        enQueueString(sc.next());
	        enQueueInt(sc.nextInt());
	    } {
	        enQueueString(sc.next());
	        enQueueInt(sc.nextInt());
	    } enQueueString(sc.next()) enQueueString sc.next() sc.next sc enQueueInt(sc.nextInt()) enQueueInt sc.nextInt() sc.nextInt sc int x ; x String y ; y while(topInt != bottomInt){
	        x = deQueueInt();
	        y = deQueueString();
	        
	        if(x <= q){
	            total += x;
	            System.out.printf("%s %d\n",y,total);
	            continue;
	        }
	        
	        x -= q; enQueueInt(x); enQueueString(y); total+=q;
	    } topInt != bottomInt topInt bottomInt {
	        x = deQueueInt();
	        y = deQueueString();
	        
	        if(x <= q){
	            total += x;
	            System.out.printf("%s %d\n",y,total);
	            continue;
	        }
	        
	        x -= q; enQueueInt(x); enQueueString(y); total+=q;
	    } x = deQueueInt() x deQueueInt() deQueueInt y = deQueueString() y deQueueString() deQueueString if(x <= q){
	            total += x;
	            System.out.printf("%s %d\n",y,total);
	            continue;
	        } x <= q x q {
	            total += x;
	            System.out.printf("%s %d\n",y,total);
	            continue;
	        } total += x total x System.out.printf("%s %d\n",y,total) System.out.printf System.out System System.out "%s %d\n" y total continue; x -= q x q enQueueInt(x) enQueueInt x enQueueString(y) enQueueString y total+=q total q public static void main(String[] args) throws Exception {
        new Main().run();
    } main {
        new Main().run();
    } new Main().run() new Main().run new Main() String[] args args public class Main {
    Scanner sc = new Scanner(System.in);
    
	int n = 100001 ; int total = 0 ;
	int[] time = new int[n];
	String[] name = new String[n];
	int topInt = 0 ,topString=0;  //キューの先頭
	int bottomInt = 0 ,bottomString=0;//キューの末尾 +1
	
	void enQueueInt(int m){
		time[bottomInt] = m ;
		if(bottomInt == n-1) bottomInt = 0;
		else bottomInt++ ;
	}
	void enQueueString(String m){
		name[bottomString] = m ;
		if(bottomString == n-1) bottomString = 0;
		else bottomString++ ;
	}
	
	
	int deQueueInt(){
		int x = time[topInt];
		if(topInt == n-1) topInt = 0;
		else topInt++;
		return x ;
	}
	String deQueueString(){
		String x = name[topString];
		if(topString == n-1) topString = 0;
		else topString++;
		return x ;
	}
	
	void run(){
	    int m = sc.nextInt();
	    int q = sc.nextInt();
	    
	    for(int i=0;i<m;i++){
	        enQueueString(sc.next());
	        enQueueInt(sc.nextInt());
	    }

	    int x ; String y ;
	    while(topInt != bottomInt){
	        x = deQueueInt();
	        y = deQueueString();
	        
	        if(x <= q){
	            total += x;
	            System.out.printf("%s %d\n",y,total);
	            continue;
	        }
	        
	        x -= q; enQueueInt(x); enQueueString(y); total+=q;
	    }
	}
	
    public static void main(String[] args) throws Exception {
        new Main().run();
    }
} public class Main {
    Scanner sc = new Scanner(System.in);
    
	int n = 100001 ; int total = 0 ;
	int[] time = new int[n];
	String[] name = new String[n];
	int topInt = 0 ,topString=0;  //キューの先頭
	int bottomInt = 0 ,bottomString=0;//キューの末尾 +1
	
	void enQueueInt(int m){
		time[bottomInt] = m ;
		if(bottomInt == n-1) bottomInt = 0;
		else bottomInt++ ;
	}
	void enQueueString(String m){
		name[bottomString] = m ;
		if(bottomString == n-1) bottomString = 0;
		else bottomString++ ;
	}
	
	
	int deQueueInt(){
		int x = time[topInt];
		if(topInt == n-1) topInt = 0;
		else topInt++;
		return x ;
	}
	String deQueueString(){
		String x = name[topString];
		if(topString == n-1) topString = 0;
		else topString++;
		return x ;
	}
	
	void run(){
	    int m = sc.nextInt();
	    int q = sc.nextInt();
	    
	    for(int i=0;i<m;i++){
	        enQueueString(sc.next());
	        enQueueInt(sc.nextInt());
	    }

	    int x ; String y ;
	    while(topInt != bottomInt){
	        x = deQueueInt();
	        y = deQueueString();
	        
	        if(x <= q){
	            total += x;
	            System.out.printf("%s %d\n",y,total);
	            continue;
	        }
	        
	        x -= q; enQueueInt(x); enQueueString(y); total+=q;
	    }
	}
	
    public static void main(String[] args) throws Exception {
        new Main().run();
    }
} Main
import java.util.*;

public class Main {
    Scanner sc = new Scanner(System.in);
    
	int n = 100001 ; int total = 0 ;
	int[] time = new int[n];
	String[] name = new String[n];
	int topInt = 0 ,topString=0;  //キューの先頭
	int bottomInt = 0 ,bottomString=0;//キューの末尾 +1
	
	void enQueueInt(int m){
		time[bottomInt] = m ;
		if(bottomInt == n-1) bottomInt = 0;
		else bottomInt++ ;
	}
	void enQueueString(String m){
		name[bottomString] = m ;
		if(bottomString == n-1) bottomString = 0;
		else bottomString++ ;
	}
	
	
	int deQueueInt(){
		int x = time[topInt];
		if(topInt == n-1) topInt = 0;
		else topInt++;
		return x ;
	}
	String deQueueString(){
		String x = name[topString];
		if(topString == n-1) topString = 0;
		else topString++;
		return x ;
	}
	
	void run(){
	    int m = sc.nextInt();
	    int q = sc.nextInt();
	    
	    for(int i=0;i<m;i++){
	        enQueueString(sc.next());
	        enQueueInt(sc.nextInt());
	    }

	    int x ; String y ;
	    while(topInt != bottomInt){
	        x = deQueueInt();
	        y = deQueueString();
	        
	        if(x <= q){
	            total += x;
	            System.out.printf("%s %d\n",y,total);
	            continue;
	        }
	        
	        x -= q; enQueueInt(x); enQueueString(y); total+=q;
	    }
	}
	
    public static void main(String[] args) throws Exception {
        new Main().run();
    }
}
