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

class Main{
    public static void main(String[] args) throws IOException{
	Scanner scan = new Scanner(System.in);
	int n = scan.nextInt();
	int reg = scan.nextInt();
	Queue<String> method = new LinkedList<String>();
	Queue<Integer> time = new LinkedList<Integer>();
	int i;
	int time0=0;
	for(i=0 ; i<n ; i++){
	    method.add(scan.next());
	    time.add(scan.nextInt());
	}

	while(method.size()>0){
	    if(time.peek() - reg>0){
		method.add(method.poll());
		time.add(time.poll() - reg);
		time0+=reg;
	    }

	    
	    else{
		time0+=time.poll();
		System.out.println(method.poll() + " " +time0);
	    }
	}
    }
}
		
	    
 import java.util.*; util.* java import java.io.*; io.* java class Main{
    public static void main(String[] args) throws IOException{
	Scanner scan = new Scanner(System.in);
	int n = scan.nextInt();
	int reg = scan.nextInt();
	Queue<String> method = new LinkedList<String>();
	Queue<Integer> time = new LinkedList<Integer>();
	int i;
	int time0=0;
	for(i=0 ; i<n ; i++){
	    method.add(scan.next());
	    time.add(scan.nextInt());
	}

	while(method.size()>0){
	    if(time.peek() - reg>0){
		method.add(method.poll());
		time.add(time.poll() - reg);
		time0+=reg;
	    }

	    
	    else{
		time0+=time.poll();
		System.out.println(method.poll() + " " +time0);
	    }
	}
    }
} Main public static void main(String[] args) throws IOException{
	Scanner scan = new Scanner(System.in);
	int n = scan.nextInt();
	int reg = scan.nextInt();
	Queue<String> method = new LinkedList<String>();
	Queue<Integer> time = new LinkedList<Integer>();
	int i;
	int time0=0;
	for(i=0 ; i<n ; i++){
	    method.add(scan.next());
	    time.add(scan.nextInt());
	}

	while(method.size()>0){
	    if(time.peek() - reg>0){
		method.add(method.poll());
		time.add(time.poll() - reg);
		time0+=reg;
	    }

	    
	    else{
		time0+=time.poll();
		System.out.println(method.poll() + " " +time0);
	    }
	}
    } main {
	Scanner scan = new Scanner(System.in);
	int n = scan.nextInt();
	int reg = scan.nextInt();
	Queue<String> method = new LinkedList<String>();
	Queue<Integer> time = new LinkedList<Integer>();
	int i;
	int time0=0;
	for(i=0 ; i<n ; i++){
	    method.add(scan.next());
	    time.add(scan.nextInt());
	}

	while(method.size()>0){
	    if(time.peek() - reg>0){
		method.add(method.poll());
		time.add(time.poll() - reg);
		time0+=reg;
	    }

	    
	    else{
		time0+=time.poll();
		System.out.println(method.poll() + " " +time0);
	    }
	}
    } Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int n = scan.nextInt(); n scan.nextInt() scan.nextInt scan int reg = scan.nextInt(); reg scan.nextInt() scan.nextInt scan Queue<String> method = new LinkedList<String>(); method new LinkedList<String>() Queue<Integer> time = new LinkedList<Integer>(); time new LinkedList<Integer>() int i; i int time0=0; time0 0 for(i=0 ; i<n ; i++){
	    method.add(scan.next());
	    time.add(scan.nextInt());
	} i=0 ; i=0 i 0 i<n i n i++ i++ i {
	    method.add(scan.next());
	    time.add(scan.nextInt());
	} {
	    method.add(scan.next());
	    time.add(scan.nextInt());
	} method.add(scan.next()) method.add method scan.next() scan.next scan time.add(scan.nextInt()) time.add time scan.nextInt() scan.nextInt scan while(method.size()>0){
	    if(time.peek() - reg>0){
		method.add(method.poll());
		time.add(time.poll() - reg);
		time0+=reg;
	    }

	    
	    else{
		time0+=time.poll();
		System.out.println(method.poll() + " " +time0);
	    }
	} method.size()>0 method.size() method.size method 0 {
	    if(time.peek() - reg>0){
		method.add(method.poll());
		time.add(time.poll() - reg);
		time0+=reg;
	    }

	    
	    else{
		time0+=time.poll();
		System.out.println(method.poll() + " " +time0);
	    }
	} if(time.peek() - reg>0){
		method.add(method.poll());
		time.add(time.poll() - reg);
		time0+=reg;
	    }

	    
	    else{
		time0+=time.poll();
		System.out.println(method.poll() + " " +time0);
	    } time.peek() - reg>0 time.peek() - reg time.peek() time.peek time reg 0 {
		method.add(method.poll());
		time.add(time.poll() - reg);
		time0+=reg;
	    } method.add(method.poll()) method.add method method.poll() method.poll method time.add(time.poll() - reg) time.add time time.poll() - reg time.poll() time.poll time reg time0+=reg time0 reg {
		time0+=time.poll();
		System.out.println(method.poll() + " " +time0);
	    } time0+=time.poll() time0 time.poll() time.poll time System.out.println(method.poll() + " " +time0) System.out.println System.out System System.out method.poll() + " " +time0 method.poll() + " " +time0 method.poll() method.poll method " " time0 String[] args args
import java.util.*;
import java.io.*;

class Main{
    public static void main(String[] args) throws IOException{
	Scanner scan = new Scanner(System.in);
	int n = scan.nextInt();
	int reg = scan.nextInt();
	Queue<String> method = new LinkedList<String>();
	Queue<Integer> time = new LinkedList<Integer>();
	int i;
	int time0=0;
	for(i=0 ; i<n ; i++){
	    method.add(scan.next());
	    time.add(scan.nextInt());
	}

	while(method.size()>0){
	    if(time.peek() - reg>0){
		method.add(method.poll());
		time.add(time.poll() - reg);
		time0+=reg;
	    }

	    
	    else{
		time0+=time.poll();
		System.out.println(method.poll() + " " +time0);
	    }
	}
    }
}
		
	    

