import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
import java.util.Scanner;

public class Main {
	
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		
		final int n = sc.nextInt();
		final int q = sc.nextInt();
		
		LinkedList<String>  name_queue = new LinkedList<String>();
		LinkedList<Integer> time_queue = new LinkedList<Integer>();
		
		for(int i = 0; i < n; i++){
			name_queue.add(sc.next());
			time_queue.add(sc.nextInt());
		}
		
		int total_time = 0;
		while(!time_queue.isEmpty()){
			final String name = name_queue.poll();
			final int time = time_queue.poll();
			
			if(time > q){
				total_time += q;
				name_queue.add(name);
				time_queue.add(time - q);
			}else{
				total_time += time;
				System.out.println(name + " " + total_time);
			}
			
		}
		
		
		
	}
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io import java.util.Arrays; Arrays java.util import java.util.HashMap; HashMap java.util import java.util.LinkedList; LinkedList java.util import java.util.Map; Map java.util import java.util.Scanner; Scanner java.util public class Main {
	
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		
		final int n = sc.nextInt();
		final int q = sc.nextInt();
		
		LinkedList<String>  name_queue = new LinkedList<String>();
		LinkedList<Integer> time_queue = new LinkedList<Integer>();
		
		for(int i = 0; i < n; i++){
			name_queue.add(sc.next());
			time_queue.add(sc.nextInt());
		}
		
		int total_time = 0;
		while(!time_queue.isEmpty()){
			final String name = name_queue.poll();
			final int time = time_queue.poll();
			
			if(time > q){
				total_time += q;
				name_queue.add(name);
				time_queue.add(time - q);
			}else{
				total_time += time;
				System.out.println(name + " " + total_time);
			}
			
		}
		
		
		
	}
} Main public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		
		final int n = sc.nextInt();
		final int q = sc.nextInt();
		
		LinkedList<String>  name_queue = new LinkedList<String>();
		LinkedList<Integer> time_queue = new LinkedList<Integer>();
		
		for(int i = 0; i < n; i++){
			name_queue.add(sc.next());
			time_queue.add(sc.nextInt());
		}
		
		int total_time = 0;
		while(!time_queue.isEmpty()){
			final String name = name_queue.poll();
			final int time = time_queue.poll();
			
			if(time > q){
				total_time += q;
				name_queue.add(name);
				time_queue.add(time - q);
			}else{
				total_time += time;
				System.out.println(name + " " + total_time);
			}
			
		}
		
		
		
	} main {
		Scanner sc = new Scanner(System.in);
		
		final int n = sc.nextInt();
		final int q = sc.nextInt();
		
		LinkedList<String>  name_queue = new LinkedList<String>();
		LinkedList<Integer> time_queue = new LinkedList<Integer>();
		
		for(int i = 0; i < n; i++){
			name_queue.add(sc.next());
			time_queue.add(sc.nextInt());
		}
		
		int total_time = 0;
		while(!time_queue.isEmpty()){
			final String name = name_queue.poll();
			final int time = time_queue.poll();
			
			if(time > q){
				total_time += q;
				name_queue.add(name);
				time_queue.add(time - q);
			}else{
				total_time += time;
				System.out.println(name + " " + total_time);
			}
			
		}
		
		
		
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) final int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc final int q = sc.nextInt(); q sc.nextInt() sc.nextInt sc LinkedList<String>  name_queue = new LinkedList<String>(); name_queue new LinkedList<String>() LinkedList<Integer> time_queue = new LinkedList<Integer>(); time_queue new LinkedList<Integer>() for(int i = 0; i < n; i++){
			name_queue.add(sc.next());
			time_queue.add(sc.nextInt());
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			name_queue.add(sc.next());
			time_queue.add(sc.nextInt());
		} {
			name_queue.add(sc.next());
			time_queue.add(sc.nextInt());
		} name_queue.add(sc.next()) name_queue.add name_queue sc.next() sc.next sc time_queue.add(sc.nextInt()) time_queue.add time_queue sc.nextInt() sc.nextInt sc int total_time = 0; total_time 0 while(!time_queue.isEmpty()){
			final String name = name_queue.poll();
			final int time = time_queue.poll();
			
			if(time > q){
				total_time += q;
				name_queue.add(name);
				time_queue.add(time - q);
			}else{
				total_time += time;
				System.out.println(name + " " + total_time);
			}
			
		} !time_queue.isEmpty() time_queue.isEmpty() time_queue.isEmpty time_queue {
			final String name = name_queue.poll();
			final int time = time_queue.poll();
			
			if(time > q){
				total_time += q;
				name_queue.add(name);
				time_queue.add(time - q);
			}else{
				total_time += time;
				System.out.println(name + " " + total_time);
			}
			
		} final String name = name_queue.poll(); name name_queue.poll() name_queue.poll name_queue final int time = time_queue.poll(); time time_queue.poll() time_queue.poll time_queue if(time > q){
				total_time += q;
				name_queue.add(name);
				time_queue.add(time - q);
			}else{
				total_time += time;
				System.out.println(name + " " + total_time);
			} time > q time q {
				total_time += q;
				name_queue.add(name);
				time_queue.add(time - q);
			} total_time += q total_time q name_queue.add(name) name_queue.add name_queue name time_queue.add(time - q) time_queue.add time_queue time - q time q {
				total_time += time;
				System.out.println(name + " " + total_time);
			} total_time += time total_time time System.out.println(name + " " + total_time) System.out.println System.out System System.out name + " " + total_time name + " " + total_time name " " total_time String args[] args public class Main {
	
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		
		final int n = sc.nextInt();
		final int q = sc.nextInt();
		
		LinkedList<String>  name_queue = new LinkedList<String>();
		LinkedList<Integer> time_queue = new LinkedList<Integer>();
		
		for(int i = 0; i < n; i++){
			name_queue.add(sc.next());
			time_queue.add(sc.nextInt());
		}
		
		int total_time = 0;
		while(!time_queue.isEmpty()){
			final String name = name_queue.poll();
			final int time = time_queue.poll();
			
			if(time > q){
				total_time += q;
				name_queue.add(name);
				time_queue.add(time - q);
			}else{
				total_time += time;
				System.out.println(name + " " + total_time);
			}
			
		}
		
		
		
	}
} public class Main {
	
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		
		final int n = sc.nextInt();
		final int q = sc.nextInt();
		
		LinkedList<String>  name_queue = new LinkedList<String>();
		LinkedList<Integer> time_queue = new LinkedList<Integer>();
		
		for(int i = 0; i < n; i++){
			name_queue.add(sc.next());
			time_queue.add(sc.nextInt());
		}
		
		int total_time = 0;
		while(!time_queue.isEmpty()){
			final String name = name_queue.poll();
			final int time = time_queue.poll();
			
			if(time > q){
				total_time += q;
				name_queue.add(name);
				time_queue.add(time - q);
			}else{
				total_time += time;
				System.out.println(name + " " + total_time);
			}
			
		}
		
		
		
	}
} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
import java.util.Scanner;

public class Main {
	
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		
		final int n = sc.nextInt();
		final int q = sc.nextInt();
		
		LinkedList<String>  name_queue = new LinkedList<String>();
		LinkedList<Integer> time_queue = new LinkedList<Integer>();
		
		for(int i = 0; i < n; i++){
			name_queue.add(sc.next());
			time_queue.add(sc.nextInt());
		}
		
		int total_time = 0;
		while(!time_queue.isEmpty()){
			final String name = name_queue.poll();
			final int time = time_queue.poll();
			
			if(time > q){
				total_time += q;
				name_queue.add(name);
				time_queue.add(time - q);
			}else{
				total_time += time;
				System.out.println(name + " " + total_time);
			}
			
		}
		
		
		
	}
}