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

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub

		Scanner scan=new Scanner(System.in);
		int n=scan.nextInt();
		int tm=scan.nextInt();
		String stmp=scan.nextLine();
		Queue<Integer> q=new LinkedList<>();
		Queue<String> qstr=new LinkedList<>();
		
		for(int i=0;i<n;i++){
			String string=scan.nextLine();
			String[] str=string.split(" ");
			qstr.offer(str[0]);
			q.offer(Integer.parseInt(str[1]));
		}
		int round=0;
		int sum=0;
		while(!q.isEmpty()){
			int tmp=q.poll();
			if(tmp<=tm){
				sum+=tmp;
				System.out.print(qstr.poll()+" ");
				//System.out.println(round*tm+tmp%tm-com);
				System.out.println(sum);
			}
			else {
				q.offer(tmp-tm);
				qstr.offer(qstr.poll());
				sum+=tm;
			}
			round++;
		}
	}

}
 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) {
		// TODO Auto-generated method stub

		Scanner scan=new Scanner(System.in);
		int n=scan.nextInt();
		int tm=scan.nextInt();
		String stmp=scan.nextLine();
		Queue<Integer> q=new LinkedList<>();
		Queue<String> qstr=new LinkedList<>();
		
		for(int i=0;i<n;i++){
			String string=scan.nextLine();
			String[] str=string.split(" ");
			qstr.offer(str[0]);
			q.offer(Integer.parseInt(str[1]));
		}
		int round=0;
		int sum=0;
		while(!q.isEmpty()){
			int tmp=q.poll();
			if(tmp<=tm){
				sum+=tmp;
				System.out.print(qstr.poll()+" ");
				//System.out.println(round*tm+tmp%tm-com);
				System.out.println(sum);
			}
			else {
				q.offer(tmp-tm);
				qstr.offer(qstr.poll());
				sum+=tm;
			}
			round++;
		}
	}

} Main public static void main(String[] args) {
		// TODO Auto-generated method stub

		Scanner scan=new Scanner(System.in);
		int n=scan.nextInt();
		int tm=scan.nextInt();
		String stmp=scan.nextLine();
		Queue<Integer> q=new LinkedList<>();
		Queue<String> qstr=new LinkedList<>();
		
		for(int i=0;i<n;i++){
			String string=scan.nextLine();
			String[] str=string.split(" ");
			qstr.offer(str[0]);
			q.offer(Integer.parseInt(str[1]));
		}
		int round=0;
		int sum=0;
		while(!q.isEmpty()){
			int tmp=q.poll();
			if(tmp<=tm){
				sum+=tmp;
				System.out.print(qstr.poll()+" ");
				//System.out.println(round*tm+tmp%tm-com);
				System.out.println(sum);
			}
			else {
				q.offer(tmp-tm);
				qstr.offer(qstr.poll());
				sum+=tm;
			}
			round++;
		}
	} main {
		// TODO Auto-generated method stub

		Scanner scan=new Scanner(System.in);
		int n=scan.nextInt();
		int tm=scan.nextInt();
		String stmp=scan.nextLine();
		Queue<Integer> q=new LinkedList<>();
		Queue<String> qstr=new LinkedList<>();
		
		for(int i=0;i<n;i++){
			String string=scan.nextLine();
			String[] str=string.split(" ");
			qstr.offer(str[0]);
			q.offer(Integer.parseInt(str[1]));
		}
		int round=0;
		int sum=0;
		while(!q.isEmpty()){
			int tmp=q.poll();
			if(tmp<=tm){
				sum+=tmp;
				System.out.print(qstr.poll()+" ");
				//System.out.println(round*tm+tmp%tm-com);
				System.out.println(sum);
			}
			else {
				q.offer(tmp-tm);
				qstr.offer(qstr.poll());
				sum+=tm;
			}
			round++;
		}
	} Scanner scan=new Scanner(System.in); scan new Scanner(System.in) int n=scan.nextInt(); n scan.nextInt() scan.nextInt scan int tm=scan.nextInt(); tm scan.nextInt() scan.nextInt scan String stmp=scan.nextLine(); stmp scan.nextLine() scan.nextLine scan Queue<Integer> q=new LinkedList<>(); q new LinkedList<>() Queue<String> qstr=new LinkedList<>(); qstr new LinkedList<>() for(int i=0;i<n;i++){
			String string=scan.nextLine();
			String[] str=string.split(" ");
			qstr.offer(str[0]);
			q.offer(Integer.parseInt(str[1]));
		} int i=0; int i=0; i 0 i<n i n i++ i++ i {
			String string=scan.nextLine();
			String[] str=string.split(" ");
			qstr.offer(str[0]);
			q.offer(Integer.parseInt(str[1]));
		} {
			String string=scan.nextLine();
			String[] str=string.split(" ");
			qstr.offer(str[0]);
			q.offer(Integer.parseInt(str[1]));
		} String string=scan.nextLine(); string scan.nextLine() scan.nextLine scan String[] str=string.split(" "); str string.split(" ") string.split string " " qstr.offer(str[0]) qstr.offer qstr str[0] str 0 q.offer(Integer.parseInt(str[1])) q.offer q Integer.parseInt(str[1]) Integer.parseInt Integer str[1] str 1 int round=0; round 0 int sum=0; sum 0 while(!q.isEmpty()){
			int tmp=q.poll();
			if(tmp<=tm){
				sum+=tmp;
				System.out.print(qstr.poll()+" ");
				//System.out.println(round*tm+tmp%tm-com);
				System.out.println(sum);
			}
			else {
				q.offer(tmp-tm);
				qstr.offer(qstr.poll());
				sum+=tm;
			}
			round++;
		} !q.isEmpty() q.isEmpty() q.isEmpty q {
			int tmp=q.poll();
			if(tmp<=tm){
				sum+=tmp;
				System.out.print(qstr.poll()+" ");
				//System.out.println(round*tm+tmp%tm-com);
				System.out.println(sum);
			}
			else {
				q.offer(tmp-tm);
				qstr.offer(qstr.poll());
				sum+=tm;
			}
			round++;
		} int tmp=q.poll(); tmp q.poll() q.poll q if(tmp<=tm){
				sum+=tmp;
				System.out.print(qstr.poll()+" ");
				//System.out.println(round*tm+tmp%tm-com);
				System.out.println(sum);
			}
			else {
				q.offer(tmp-tm);
				qstr.offer(qstr.poll());
				sum+=tm;
			} tmp<=tm tmp tm {
				sum+=tmp;
				System.out.print(qstr.poll()+" ");
				//System.out.println(round*tm+tmp%tm-com);
				System.out.println(sum);
			} sum+=tmp sum tmp System.out.print(qstr.poll()+" ") System.out.print System.out System System.out qstr.poll()+" " qstr.poll() qstr.poll qstr " " System.out.println(sum) System.out.println System.out System System.out sum {
				q.offer(tmp-tm);
				qstr.offer(qstr.poll());
				sum+=tm;
			} q.offer(tmp-tm) q.offer q tmp-tm tmp tm qstr.offer(qstr.poll()) qstr.offer qstr qstr.poll() qstr.poll qstr sum+=tm sum tm round++ round String[] args args public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub

		Scanner scan=new Scanner(System.in);
		int n=scan.nextInt();
		int tm=scan.nextInt();
		String stmp=scan.nextLine();
		Queue<Integer> q=new LinkedList<>();
		Queue<String> qstr=new LinkedList<>();
		
		for(int i=0;i<n;i++){
			String string=scan.nextLine();
			String[] str=string.split(" ");
			qstr.offer(str[0]);
			q.offer(Integer.parseInt(str[1]));
		}
		int round=0;
		int sum=0;
		while(!q.isEmpty()){
			int tmp=q.poll();
			if(tmp<=tm){
				sum+=tmp;
				System.out.print(qstr.poll()+" ");
				//System.out.println(round*tm+tmp%tm-com);
				System.out.println(sum);
			}
			else {
				q.offer(tmp-tm);
				qstr.offer(qstr.poll());
				sum+=tm;
			}
			round++;
		}
	}

} public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub

		Scanner scan=new Scanner(System.in);
		int n=scan.nextInt();
		int tm=scan.nextInt();
		String stmp=scan.nextLine();
		Queue<Integer> q=new LinkedList<>();
		Queue<String> qstr=new LinkedList<>();
		
		for(int i=0;i<n;i++){
			String string=scan.nextLine();
			String[] str=string.split(" ");
			qstr.offer(str[0]);
			q.offer(Integer.parseInt(str[1]));
		}
		int round=0;
		int sum=0;
		while(!q.isEmpty()){
			int tmp=q.poll();
			if(tmp<=tm){
				sum+=tmp;
				System.out.print(qstr.poll()+" ");
				//System.out.println(round*tm+tmp%tm-com);
				System.out.println(sum);
			}
			else {
				q.offer(tmp-tm);
				qstr.offer(qstr.poll());
				sum+=tm;
			}
			round++;
		}
	}

} Main

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

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub

		Scanner scan=new Scanner(System.in);
		int n=scan.nextInt();
		int tm=scan.nextInt();
		String stmp=scan.nextLine();
		Queue<Integer> q=new LinkedList<>();
		Queue<String> qstr=new LinkedList<>();
		
		for(int i=0;i<n;i++){
			String string=scan.nextLine();
			String[] str=string.split(" ");
			qstr.offer(str[0]);
			q.offer(Integer.parseInt(str[1]));
		}
		int round=0;
		int sum=0;
		while(!q.isEmpty()){
			int tmp=q.poll();
			if(tmp<=tm){
				sum+=tmp;
				System.out.print(qstr.poll()+" ");
				//System.out.println(round*tm+tmp%tm-com);
				System.out.println(sum);
			}
			else {
				q.offer(tmp-tm);
				qstr.offer(qstr.poll());
				sum+=tm;
			}
			round++;
		}
	}

}

