
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Queue <String> N = new LinkedList<>();
		Queue <Integer> Q = new LinkedList<>();
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
		int task = sc.nextInt();	

		for(int i = 0; i < n; i++) {
			N.add(sc.next());
			Q.add(sc.nextInt());
		}
		sc.close();
		
		Queue <String> N_ans = new LinkedList<>();
		Queue <Integer> Q_ans = new LinkedList<>();
		
		
		int time = 0;
		int R = 0;
		String S = "";
		while (!Q.isEmpty()) {
			R = Q.poll();
			S = N.poll();
			if (R>task){
				R-=task;
				Q.add(R);
				N.add(S);
				time+=task;
			}
			else {
				time+=R;
				Q_ans.add(time);
				N_ans.add(S);
			}
		}
		for(int i = 0; i < n; i++) {
			System.out.print(N_ans.poll() + " ");
			System.out.println(Q_ans.poll());
		}
	}

}
 import java.util.LinkedList; LinkedList java.util import java.util.Queue; Queue java.util import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		Queue <String> N = new LinkedList<>();
		Queue <Integer> Q = new LinkedList<>();
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
		int task = sc.nextInt();	

		for(int i = 0; i < n; i++) {
			N.add(sc.next());
			Q.add(sc.nextInt());
		}
		sc.close();
		
		Queue <String> N_ans = new LinkedList<>();
		Queue <Integer> Q_ans = new LinkedList<>();
		
		
		int time = 0;
		int R = 0;
		String S = "";
		while (!Q.isEmpty()) {
			R = Q.poll();
			S = N.poll();
			if (R>task){
				R-=task;
				Q.add(R);
				N.add(S);
				time+=task;
			}
			else {
				time+=R;
				Q_ans.add(time);
				N_ans.add(S);
			}
		}
		for(int i = 0; i < n; i++) {
			System.out.print(N_ans.poll() + " ");
			System.out.println(Q_ans.poll());
		}
	}

} Main public static void main(String[] args) {
		Queue <String> N = new LinkedList<>();
		Queue <Integer> Q = new LinkedList<>();
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
		int task = sc.nextInt();	

		for(int i = 0; i < n; i++) {
			N.add(sc.next());
			Q.add(sc.nextInt());
		}
		sc.close();
		
		Queue <String> N_ans = new LinkedList<>();
		Queue <Integer> Q_ans = new LinkedList<>();
		
		
		int time = 0;
		int R = 0;
		String S = "";
		while (!Q.isEmpty()) {
			R = Q.poll();
			S = N.poll();
			if (R>task){
				R-=task;
				Q.add(R);
				N.add(S);
				time+=task;
			}
			else {
				time+=R;
				Q_ans.add(time);
				N_ans.add(S);
			}
		}
		for(int i = 0; i < n; i++) {
			System.out.print(N_ans.poll() + " ");
			System.out.println(Q_ans.poll());
		}
	} main {
		Queue <String> N = new LinkedList<>();
		Queue <Integer> Q = new LinkedList<>();
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
		int task = sc.nextInt();	

		for(int i = 0; i < n; i++) {
			N.add(sc.next());
			Q.add(sc.nextInt());
		}
		sc.close();
		
		Queue <String> N_ans = new LinkedList<>();
		Queue <Integer> Q_ans = new LinkedList<>();
		
		
		int time = 0;
		int R = 0;
		String S = "";
		while (!Q.isEmpty()) {
			R = Q.poll();
			S = N.poll();
			if (R>task){
				R-=task;
				Q.add(R);
				N.add(S);
				time+=task;
			}
			else {
				time+=R;
				Q_ans.add(time);
				N_ans.add(S);
			}
		}
		for(int i = 0; i < n; i++) {
			System.out.print(N_ans.poll() + " ");
			System.out.println(Q_ans.poll());
		}
	} Queue <String> N = new LinkedList<>(); N new LinkedList<>() Queue <Integer> Q = new LinkedList<>(); Q new LinkedList<>() Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int task = sc.nextInt(); task sc.nextInt() sc.nextInt sc for(int i = 0; i < n; i++) {
			N.add(sc.next());
			Q.add(sc.nextInt());
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			N.add(sc.next());
			Q.add(sc.nextInt());
		} {
			N.add(sc.next());
			Q.add(sc.nextInt());
		} N.add(sc.next()) N.add N sc.next() sc.next sc Q.add(sc.nextInt()) Q.add Q sc.nextInt() sc.nextInt sc sc.close() sc.close sc Queue <String> N_ans = new LinkedList<>(); N_ans new LinkedList<>() Queue <Integer> Q_ans = new LinkedList<>(); Q_ans new LinkedList<>() int time = 0; time 0 int R = 0; R 0 String S = ""; S "" while (!Q.isEmpty()) {
			R = Q.poll();
			S = N.poll();
			if (R>task){
				R-=task;
				Q.add(R);
				N.add(S);
				time+=task;
			}
			else {
				time+=R;
				Q_ans.add(time);
				N_ans.add(S);
			}
		} !Q.isEmpty() Q.isEmpty() Q.isEmpty Q {
			R = Q.poll();
			S = N.poll();
			if (R>task){
				R-=task;
				Q.add(R);
				N.add(S);
				time+=task;
			}
			else {
				time+=R;
				Q_ans.add(time);
				N_ans.add(S);
			}
		} R = Q.poll() R Q.poll() Q.poll Q S = N.poll() S N.poll() N.poll N if (R>task){
				R-=task;
				Q.add(R);
				N.add(S);
				time+=task;
			}
			else {
				time+=R;
				Q_ans.add(time);
				N_ans.add(S);
			} R>task R task {
				R-=task;
				Q.add(R);
				N.add(S);
				time+=task;
			} R-=task R task Q.add(R) Q.add Q R N.add(S) N.add N S time+=task time task {
				time+=R;
				Q_ans.add(time);
				N_ans.add(S);
			} time+=R time R Q_ans.add(time) Q_ans.add Q_ans time N_ans.add(S) N_ans.add N_ans S for(int i = 0; i < n; i++) {
			System.out.print(N_ans.poll() + " ");
			System.out.println(Q_ans.poll());
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			System.out.print(N_ans.poll() + " ");
			System.out.println(Q_ans.poll());
		} {
			System.out.print(N_ans.poll() + " ");
			System.out.println(Q_ans.poll());
		} System.out.print(N_ans.poll() + " ") System.out.print System.out System System.out N_ans.poll() + " " N_ans.poll() N_ans.poll N_ans " " System.out.println(Q_ans.poll()) System.out.println System.out System System.out Q_ans.poll() Q_ans.poll Q_ans String[] args args public class Main {

	public static void main(String[] args) {
		Queue <String> N = new LinkedList<>();
		Queue <Integer> Q = new LinkedList<>();
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
		int task = sc.nextInt();	

		for(int i = 0; i < n; i++) {
			N.add(sc.next());
			Q.add(sc.nextInt());
		}
		sc.close();
		
		Queue <String> N_ans = new LinkedList<>();
		Queue <Integer> Q_ans = new LinkedList<>();
		
		
		int time = 0;
		int R = 0;
		String S = "";
		while (!Q.isEmpty()) {
			R = Q.poll();
			S = N.poll();
			if (R>task){
				R-=task;
				Q.add(R);
				N.add(S);
				time+=task;
			}
			else {
				time+=R;
				Q_ans.add(time);
				N_ans.add(S);
			}
		}
		for(int i = 0; i < n; i++) {
			System.out.print(N_ans.poll() + " ");
			System.out.println(Q_ans.poll());
		}
	}

} public class Main {

	public static void main(String[] args) {
		Queue <String> N = new LinkedList<>();
		Queue <Integer> Q = new LinkedList<>();
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
		int task = sc.nextInt();	

		for(int i = 0; i < n; i++) {
			N.add(sc.next());
			Q.add(sc.nextInt());
		}
		sc.close();
		
		Queue <String> N_ans = new LinkedList<>();
		Queue <Integer> Q_ans = new LinkedList<>();
		
		
		int time = 0;
		int R = 0;
		String S = "";
		while (!Q.isEmpty()) {
			R = Q.poll();
			S = N.poll();
			if (R>task){
				R-=task;
				Q.add(R);
				N.add(S);
				time+=task;
			}
			else {
				time+=R;
				Q_ans.add(time);
				N_ans.add(S);
			}
		}
		for(int i = 0; i < n; i++) {
			System.out.print(N_ans.poll() + " ");
			System.out.println(Q_ans.poll());
		}
	}

} Main

import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Queue <String> N = new LinkedList<>();
		Queue <Integer> Q = new LinkedList<>();
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
		int task = sc.nextInt();	

		for(int i = 0; i < n; i++) {
			N.add(sc.next());
			Q.add(sc.nextInt());
		}
		sc.close();
		
		Queue <String> N_ans = new LinkedList<>();
		Queue <Integer> Q_ans = new LinkedList<>();
		
		
		int time = 0;
		int R = 0;
		String S = "";
		while (!Q.isEmpty()) {
			R = Q.poll();
			S = N.poll();
			if (R>task){
				R-=task;
				Q.add(R);
				N.add(S);
				time+=task;
			}
			else {
				time+=R;
				Q_ans.add(time);
				N_ans.add(S);
			}
		}
		for(int i = 0; i < n; i++) {
			System.out.print(N_ans.poll() + " ");
			System.out.println(Q_ans.poll());
		}
	}

}

