import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayDeque;

public class Main {

	public static void main(String[] args) throws Exception {
        // TODO ?????????????????????????????????????????????
       // System.out.println("0".compareTo("1"));
		ArrayDeque<String> queue1 = new ArrayDeque<String>();
		ArrayDeque<Integer> queue2 = new ArrayDeque<Integer>();
		
		try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
            String line;
            int n=0,tam=0,i=0;
            boolean first=true;
            while ((line = br.readLine()) != null) {
            	String[] str=line.split(" ");
            	if(first){
            		n=Integer.parseInt(str[0]);
            		tam=Integer.parseInt(str[1]);
            		first=false;
            	}else{
            		queue1.add(str[0]);
            		queue2.add(Integer.parseInt(str[1]));
            		i++;
            		if(i==n){
            			break;
            		}
            	}           	
            }
            int store=0;
            while(!queue1.isEmpty()){
            	String str="";
            	while(true){
            		int a=queue2.poll();
            		str=queue1.poll();
            		if(a<=tam){
            			store+=a;
            			break;
            		}else{
            			store+=tam;
            			queue1.add(str);
            			queue2.add(a-tam);
            		}
            	}
            	System.out.println(str+" "+store);
            }
        }
	}


} import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io import java.util.ArrayDeque; ArrayDeque java.util public class Main {

	public static void main(String[] args) throws Exception {
        // TODO ?????????????????????????????????????????????
       // System.out.println("0".compareTo("1"));
		ArrayDeque<String> queue1 = new ArrayDeque<String>();
		ArrayDeque<Integer> queue2 = new ArrayDeque<Integer>();
		
		try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
            String line;
            int n=0,tam=0,i=0;
            boolean first=true;
            while ((line = br.readLine()) != null) {
            	String[] str=line.split(" ");
            	if(first){
            		n=Integer.parseInt(str[0]);
            		tam=Integer.parseInt(str[1]);
            		first=false;
            	}else{
            		queue1.add(str[0]);
            		queue2.add(Integer.parseInt(str[1]));
            		i++;
            		if(i==n){
            			break;
            		}
            	}           	
            }
            int store=0;
            while(!queue1.isEmpty()){
            	String str="";
            	while(true){
            		int a=queue2.poll();
            		str=queue1.poll();
            		if(a<=tam){
            			store+=a;
            			break;
            		}else{
            			store+=tam;
            			queue1.add(str);
            			queue2.add(a-tam);
            		}
            	}
            	System.out.println(str+" "+store);
            }
        }
	}


} Main public static void main(String[] args) throws Exception {
        // TODO ?????????????????????????????????????????????
       // System.out.println("0".compareTo("1"));
		ArrayDeque<String> queue1 = new ArrayDeque<String>();
		ArrayDeque<Integer> queue2 = new ArrayDeque<Integer>();
		
		try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
            String line;
            int n=0,tam=0,i=0;
            boolean first=true;
            while ((line = br.readLine()) != null) {
            	String[] str=line.split(" ");
            	if(first){
            		n=Integer.parseInt(str[0]);
            		tam=Integer.parseInt(str[1]);
            		first=false;
            	}else{
            		queue1.add(str[0]);
            		queue2.add(Integer.parseInt(str[1]));
            		i++;
            		if(i==n){
            			break;
            		}
            	}           	
            }
            int store=0;
            while(!queue1.isEmpty()){
            	String str="";
            	while(true){
            		int a=queue2.poll();
            		str=queue1.poll();
            		if(a<=tam){
            			store+=a;
            			break;
            		}else{
            			store+=tam;
            			queue1.add(str);
            			queue2.add(a-tam);
            		}
            	}
            	System.out.println(str+" "+store);
            }
        }
	} main {
        // TODO ?????????????????????????????????????????????
       // System.out.println("0".compareTo("1"));
		ArrayDeque<String> queue1 = new ArrayDeque<String>();
		ArrayDeque<Integer> queue2 = new ArrayDeque<Integer>();
		
		try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
            String line;
            int n=0,tam=0,i=0;
            boolean first=true;
            while ((line = br.readLine()) != null) {
            	String[] str=line.split(" ");
            	if(first){
            		n=Integer.parseInt(str[0]);
            		tam=Integer.parseInt(str[1]);
            		first=false;
            	}else{
            		queue1.add(str[0]);
            		queue2.add(Integer.parseInt(str[1]));
            		i++;
            		if(i==n){
            			break;
            		}
            	}           	
            }
            int store=0;
            while(!queue1.isEmpty()){
            	String str="";
            	while(true){
            		int a=queue2.poll();
            		str=queue1.poll();
            		if(a<=tam){
            			store+=a;
            			break;
            		}else{
            			store+=tam;
            			queue1.add(str);
            			queue2.add(a-tam);
            		}
            	}
            	System.out.println(str+" "+store);
            }
        }
	} ArrayDeque<String> queue1 = new ArrayDeque<String>(); queue1 new ArrayDeque<String>() ArrayDeque<Integer> queue2 = new ArrayDeque<Integer>(); queue2 new ArrayDeque<Integer>() try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
            String line;
            int n=0,tam=0,i=0;
            boolean first=true;
            while ((line = br.readLine()) != null) {
            	String[] str=line.split(" ");
            	if(first){
            		n=Integer.parseInt(str[0]);
            		tam=Integer.parseInt(str[1]);
            		first=false;
            	}else{
            		queue1.add(str[0]);
            		queue2.add(Integer.parseInt(str[1]));
            		i++;
            		if(i==n){
            			break;
            		}
            	}           	
            }
            int store=0;
            while(!queue1.isEmpty()){
            	String str="";
            	while(true){
            		int a=queue2.poll();
            		str=queue1.poll();
            		if(a<=tam){
            			store+=a;
            			break;
            		}else{
            			store+=tam;
            			queue1.add(str);
            			queue2.add(a-tam);
            		}
            	}
            	System.out.println(str+" "+store);
            }
        } {
            String line;
            int n=0,tam=0,i=0;
            boolean first=true;
            while ((line = br.readLine()) != null) {
            	String[] str=line.split(" ");
            	if(first){
            		n=Integer.parseInt(str[0]);
            		tam=Integer.parseInt(str[1]);
            		first=false;
            	}else{
            		queue1.add(str[0]);
            		queue2.add(Integer.parseInt(str[1]));
            		i++;
            		if(i==n){
            			break;
            		}
            	}           	
            }
            int store=0;
            while(!queue1.isEmpty()){
            	String str="";
            	while(true){
            		int a=queue2.poll();
            		str=queue1.poll();
            		if(a<=tam){
            			store+=a;
            			break;
            		}else{
            			store+=tam;
            			queue1.add(str);
            			queue2.add(a-tam);
            		}
            	}
            	System.out.println(str+" "+store);
            }
        } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)) BufferedReader br = new BufferedReader(new InputStreamReader(System.in)) new BufferedReader(new InputStreamReader(System.in)) String line; line int n=0 n 0 tam=0 tam 0 i=0; i 0 boolean first=true; first true while ((line = br.readLine()) != null) {
            	String[] str=line.split(" ");
            	if(first){
            		n=Integer.parseInt(str[0]);
            		tam=Integer.parseInt(str[1]);
            		first=false;
            	}else{
            		queue1.add(str[0]);
            		queue2.add(Integer.parseInt(str[1]));
            		i++;
            		if(i==n){
            			break;
            		}
            	}           	
            } (line = br.readLine()) != null (line = br.readLine()) line br.readLine() br.readLine br null {
            	String[] str=line.split(" ");
            	if(first){
            		n=Integer.parseInt(str[0]);
            		tam=Integer.parseInt(str[1]);
            		first=false;
            	}else{
            		queue1.add(str[0]);
            		queue2.add(Integer.parseInt(str[1]));
            		i++;
            		if(i==n){
            			break;
            		}
            	}           	
            } String[] str=line.split(" "); str line.split(" ") line.split line " " if(first){
            		n=Integer.parseInt(str[0]);
            		tam=Integer.parseInt(str[1]);
            		first=false;
            	}else{
            		queue1.add(str[0]);
            		queue2.add(Integer.parseInt(str[1]));
            		i++;
            		if(i==n){
            			break;
            		}
            	} first {
            		n=Integer.parseInt(str[0]);
            		tam=Integer.parseInt(str[1]);
            		first=false;
            	} n=Integer.parseInt(str[0]) n Integer.parseInt(str[0]) Integer.parseInt Integer str[0] str 0 tam=Integer.parseInt(str[1]) tam Integer.parseInt(str[1]) Integer.parseInt Integer str[1] str 1 first=false first false {
            		queue1.add(str[0]);
            		queue2.add(Integer.parseInt(str[1]));
            		i++;
            		if(i==n){
            			break;
            		}
            	} queue1.add(str[0]) queue1.add queue1 str[0] str 0 queue2.add(Integer.parseInt(str[1])) queue2.add queue2 Integer.parseInt(str[1]) Integer.parseInt Integer str[1] str 1 i++ i if(i==n){
            			break;
            		} i==n i n {
            			break;
            		} break; int store=0; store 0 while(!queue1.isEmpty()){
            	String str="";
            	while(true){
            		int a=queue2.poll();
            		str=queue1.poll();
            		if(a<=tam){
            			store+=a;
            			break;
            		}else{
            			store+=tam;
            			queue1.add(str);
            			queue2.add(a-tam);
            		}
            	}
            	System.out.println(str+" "+store);
            } !queue1.isEmpty() queue1.isEmpty() queue1.isEmpty queue1 {
            	String str="";
            	while(true){
            		int a=queue2.poll();
            		str=queue1.poll();
            		if(a<=tam){
            			store+=a;
            			break;
            		}else{
            			store+=tam;
            			queue1.add(str);
            			queue2.add(a-tam);
            		}
            	}
            	System.out.println(str+" "+store);
            } String str=""; str "" while(true){
            		int a=queue2.poll();
            		str=queue1.poll();
            		if(a<=tam){
            			store+=a;
            			break;
            		}else{
            			store+=tam;
            			queue1.add(str);
            			queue2.add(a-tam);
            		}
            	} true {
            		int a=queue2.poll();
            		str=queue1.poll();
            		if(a<=tam){
            			store+=a;
            			break;
            		}else{
            			store+=tam;
            			queue1.add(str);
            			queue2.add(a-tam);
            		}
            	} int a=queue2.poll(); a queue2.poll() queue2.poll queue2 str=queue1.poll() str queue1.poll() queue1.poll queue1 if(a<=tam){
            			store+=a;
            			break;
            		}else{
            			store+=tam;
            			queue1.add(str);
            			queue2.add(a-tam);
            		} a<=tam a tam {
            			store+=a;
            			break;
            		} store+=a store a break; {
            			store+=tam;
            			queue1.add(str);
            			queue2.add(a-tam);
            		} store+=tam store tam queue1.add(str) queue1.add queue1 str queue2.add(a-tam) queue2.add queue2 a-tam a tam System.out.println(str+" "+store) System.out.println System.out System System.out str+" "+store str+" "+store str " " store String[] args args public class Main {

	public static void main(String[] args) throws Exception {
        // TODO ?????????????????????????????????????????????
       // System.out.println("0".compareTo("1"));
		ArrayDeque<String> queue1 = new ArrayDeque<String>();
		ArrayDeque<Integer> queue2 = new ArrayDeque<Integer>();
		
		try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
            String line;
            int n=0,tam=0,i=0;
            boolean first=true;
            while ((line = br.readLine()) != null) {
            	String[] str=line.split(" ");
            	if(first){
            		n=Integer.parseInt(str[0]);
            		tam=Integer.parseInt(str[1]);
            		first=false;
            	}else{
            		queue1.add(str[0]);
            		queue2.add(Integer.parseInt(str[1]));
            		i++;
            		if(i==n){
            			break;
            		}
            	}           	
            }
            int store=0;
            while(!queue1.isEmpty()){
            	String str="";
            	while(true){
            		int a=queue2.poll();
            		str=queue1.poll();
            		if(a<=tam){
            			store+=a;
            			break;
            		}else{
            			store+=tam;
            			queue1.add(str);
            			queue2.add(a-tam);
            		}
            	}
            	System.out.println(str+" "+store);
            }
        }
	}


} public class Main {

	public static void main(String[] args) throws Exception {
        // TODO ?????????????????????????????????????????????
       // System.out.println("0".compareTo("1"));
		ArrayDeque<String> queue1 = new ArrayDeque<String>();
		ArrayDeque<Integer> queue2 = new ArrayDeque<Integer>();
		
		try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
            String line;
            int n=0,tam=0,i=0;
            boolean first=true;
            while ((line = br.readLine()) != null) {
            	String[] str=line.split(" ");
            	if(first){
            		n=Integer.parseInt(str[0]);
            		tam=Integer.parseInt(str[1]);
            		first=false;
            	}else{
            		queue1.add(str[0]);
            		queue2.add(Integer.parseInt(str[1]));
            		i++;
            		if(i==n){
            			break;
            		}
            	}           	
            }
            int store=0;
            while(!queue1.isEmpty()){
            	String str="";
            	while(true){
            		int a=queue2.poll();
            		str=queue1.poll();
            		if(a<=tam){
            			store+=a;
            			break;
            		}else{
            			store+=tam;
            			queue1.add(str);
            			queue2.add(a-tam);
            		}
            	}
            	System.out.println(str+" "+store);
            }
        }
	}


} Main
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayDeque;

public class Main {

	public static void main(String[] args) throws Exception {
        // TODO ?????????????????????????????????????????????
       // System.out.println("0".compareTo("1"));
		ArrayDeque<String> queue1 = new ArrayDeque<String>();
		ArrayDeque<Integer> queue2 = new ArrayDeque<Integer>();
		
		try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
            String line;
            int n=0,tam=0,i=0;
            boolean first=true;
            while ((line = br.readLine()) != null) {
            	String[] str=line.split(" ");
            	if(first){
            		n=Integer.parseInt(str[0]);
            		tam=Integer.parseInt(str[1]);
            		first=false;
            	}else{
            		queue1.add(str[0]);
            		queue2.add(Integer.parseInt(str[1]));
            		i++;
            		if(i==n){
            			break;
            		}
            	}           	
            }
            int store=0;
            while(!queue1.isEmpty()){
            	String str="";
            	while(true){
            		int a=queue2.poll();
            		str=queue1.poll();
            		if(a<=tam){
            			store+=a;
            			break;
            		}else{
            			store+=tam;
            			queue1.add(str);
            			queue2.add(a-tam);
            		}
            	}
            	System.out.println(str+" "+store);
            }
        }
	}


}