import java.util.*;
public class Main{
	public static void main(String args[]){
	    Scanner input = new Scanner(System.in);
	    
	    Queue<Integer>num = new LinkedList<Integer>();
	    Queue<String> p = new LinkedList<String>();
	    int number = input.nextInt();
	    int time = input.nextInt();
	    int timer = 0;
	    for(int i = 0; i < number; i++ ){
	    	p.add(input.next());
	        num.add(input.nextInt());
	    }//for
	    
	    while(!num.isEmpty()){
	    	String test2 = p.remove();
	        int test = num.remove();
	        if(test - time <= 0 ){
	            timer += test;
	            System.out.println(test2 +  " " +(timer));
	        }//if
	        if(test - time > 0){
	        	p.add(test2);
	            num.add(test - time);
	            timer += time;
	        }//if
	        
	    }//while
	    
}//main
}//main import java.util.*; util.* java public class Main{
	public static void main(String args[]){
	    Scanner input = new Scanner(System.in);
	    
	    Queue<Integer>num = new LinkedList<Integer>();
	    Queue<String> p = new LinkedList<String>();
	    int number = input.nextInt();
	    int time = input.nextInt();
	    int timer = 0;
	    for(int i = 0; i < number; i++ ){
	    	p.add(input.next());
	        num.add(input.nextInt());
	    }//for
	    
	    while(!num.isEmpty()){
	    	String test2 = p.remove();
	        int test = num.remove();
	        if(test - time <= 0 ){
	            timer += test;
	            System.out.println(test2 +  " " +(timer));
	        }//if
	        if(test - time > 0){
	        	p.add(test2);
	            num.add(test - time);
	            timer += time;
	        }//if
	        
	    }//while
	    
}//main
}//main Main public static void main(String args[]){
	    Scanner input = new Scanner(System.in);
	    
	    Queue<Integer>num = new LinkedList<Integer>();
	    Queue<String> p = new LinkedList<String>();
	    int number = input.nextInt();
	    int time = input.nextInt();
	    int timer = 0;
	    for(int i = 0; i < number; i++ ){
	    	p.add(input.next());
	        num.add(input.nextInt());
	    }//for
	    
	    while(!num.isEmpty()){
	    	String test2 = p.remove();
	        int test = num.remove();
	        if(test - time <= 0 ){
	            timer += test;
	            System.out.println(test2 +  " " +(timer));
	        }//if
	        if(test - time > 0){
	        	p.add(test2);
	            num.add(test - time);
	            timer += time;
	        }//if
	        
	    }//while
	    
}//main main {
	    Scanner input = new Scanner(System.in);
	    
	    Queue<Integer>num = new LinkedList<Integer>();
	    Queue<String> p = new LinkedList<String>();
	    int number = input.nextInt();
	    int time = input.nextInt();
	    int timer = 0;
	    for(int i = 0; i < number; i++ ){
	    	p.add(input.next());
	        num.add(input.nextInt());
	    }//for
	    
	    while(!num.isEmpty()){
	    	String test2 = p.remove();
	        int test = num.remove();
	        if(test - time <= 0 ){
	            timer += test;
	            System.out.println(test2 +  " " +(timer));
	        }//if
	        if(test - time > 0){
	        	p.add(test2);
	            num.add(test - time);
	            timer += time;
	        }//if
	        
	    }//while
	    
} Scanner input = new Scanner(System.in); input new Scanner(System.in) Queue<Integer>num = new LinkedList<Integer>(); num new LinkedList<Integer>() Queue<String> p = new LinkedList<String>(); p new LinkedList<String>() int number = input.nextInt(); number input.nextInt() input.nextInt input int time = input.nextInt(); time input.nextInt() input.nextInt input int timer = 0; timer 0 for(int i = 0; i < number; i++ ){
	    	p.add(input.next());
	        num.add(input.nextInt());
	    }//for int i = 0; int i = 0; i 0 i < number i number i++ i++ i {
	    	p.add(input.next());
	        num.add(input.nextInt());
	    }//for {
	    	p.add(input.next());
	        num.add(input.nextInt());
	    } p.add(input.next()) p.add p input.next() input.next input num.add(input.nextInt()) num.add num input.nextInt() input.nextInt input while(!num.isEmpty()){
	    	String test2 = p.remove();
	        int test = num.remove();
	        if(test - time <= 0 ){
	            timer += test;
	            System.out.println(test2 +  " " +(timer));
	        }//if
	        if(test - time > 0){
	        	p.add(test2);
	            num.add(test - time);
	            timer += time;
	        }//if
	        
	    }//while !num.isEmpty() num.isEmpty() num.isEmpty num {
	    	String test2 = p.remove();
	        int test = num.remove();
	        if(test - time <= 0 ){
	            timer += test;
	            System.out.println(test2 +  " " +(timer));
	        }//if
	        if(test - time > 0){
	        	p.add(test2);
	            num.add(test - time);
	            timer += time;
	        }//if
	        
	    } String test2 = p.remove(); test2 p.remove() p.remove p int test = num.remove(); test num.remove() num.remove num if(test - time <= 0 ){
	            timer += test;
	            System.out.println(test2 +  " " +(timer));
	        }//if test - time <= 0 test - time test time 0 {
	            timer += test;
	            System.out.println(test2 +  " " +(timer));
	        } timer += test timer test System.out.println(test2 +  " " +(timer)) System.out.println System.out System System.out test2 +  " " +(timer) test2 +  " " +(timer) test2 " " (timer) if(test - time > 0){
	        	p.add(test2);
	            num.add(test - time);
	            timer += time;
	        }//if test - time > 0 test - time test time 0 {
	        	p.add(test2);
	            num.add(test - time);
	            timer += time;
	        } p.add(test2) p.add p test2 num.add(test - time) num.add num test - time test time timer += time timer time String args[] args public class Main{
	public static void main(String args[]){
	    Scanner input = new Scanner(System.in);
	    
	    Queue<Integer>num = new LinkedList<Integer>();
	    Queue<String> p = new LinkedList<String>();
	    int number = input.nextInt();
	    int time = input.nextInt();
	    int timer = 0;
	    for(int i = 0; i < number; i++ ){
	    	p.add(input.next());
	        num.add(input.nextInt());
	    }//for
	    
	    while(!num.isEmpty()){
	    	String test2 = p.remove();
	        int test = num.remove();
	        if(test - time <= 0 ){
	            timer += test;
	            System.out.println(test2 +  " " +(timer));
	        }//if
	        if(test - time > 0){
	        	p.add(test2);
	            num.add(test - time);
	            timer += time;
	        }//if
	        
	    }//while
	    
}//main
}//main public class Main{
	public static void main(String args[]){
	    Scanner input = new Scanner(System.in);
	    
	    Queue<Integer>num = new LinkedList<Integer>();
	    Queue<String> p = new LinkedList<String>();
	    int number = input.nextInt();
	    int time = input.nextInt();
	    int timer = 0;
	    for(int i = 0; i < number; i++ ){
	    	p.add(input.next());
	        num.add(input.nextInt());
	    }//for
	    
	    while(!num.isEmpty()){
	    	String test2 = p.remove();
	        int test = num.remove();
	        if(test - time <= 0 ){
	            timer += test;
	            System.out.println(test2 +  " " +(timer));
	        }//if
	        if(test - time > 0){
	        	p.add(test2);
	            num.add(test - time);
	            timer += time;
	        }//if
	        
	    }//while
	    
}//main
}//main Main
import java.util.*;
public class Main{
	public static void main(String args[]){
	    Scanner input = new Scanner(System.in);
	    
	    Queue<Integer>num = new LinkedList<Integer>();
	    Queue<String> p = new LinkedList<String>();
	    int number = input.nextInt();
	    int time = input.nextInt();
	    int timer = 0;
	    for(int i = 0; i < number; i++ ){
	    	p.add(input.next());
	        num.add(input.nextInt());
	    }//for
	    
	    while(!num.isEmpty()){
	    	String test2 = p.remove();
	        int test = num.remove();
	        if(test - time <= 0 ){
	            timer += test;
	            System.out.println(test2 +  " " +(timer));
	        }//if
	        if(test - time > 0){
	        	p.add(test2);
	            num.add(test - time);
	            timer += time;
	        }//if
	        
	    }//while
	    
}//main
}//main
