import java.util.*;
import java.io.*;
class Main{
	public static void main(String[]args){
		Scanner in=new Scanner(System.in);
		PrintWriter out=new PrintWriter(System.out, true);
		String str[]=in.nextLine().split(" ");
		int n=Integer.parseInt(str[0]);
		int q=Integer.parseInt(str[1]);
		HashMap<String, Integer> map=new HashMap<>();
		Queue<String> queue=new LinkedList<>();
		for(int i=0;i<n;i++){
			str=in.nextLine().split(" ");
			String pid=str[0];
			int ptime=Integer.parseInt(str[1]);
			map.put(pid, ptime);
			queue.add(pid);
		}
		int time=0;
		ArrayList<String> list=new ArrayList<>();
		HashMap<String, Integer> map_2=new HashMap<>();
		
		while(true){
		       String pid=queue.poll();
		       int ptime=map.get(pid);
		       time+=Math.min(q, ptime);
		       ptime=Math.max(0, ptime-q);
		       map.put(pid, ptime);
		       if(ptime==0){
			       list.add(pid);
			       map_2.put(pid, time);
			       if(list.size()==n)
				       break;
		       }else{
			       queue.add(pid);
		       }
		}
		for(int i=0;i<list.size();i++){
			out.println(list.get(i)+" "+map_2.get(list.get(i)));
		}
	}

} import java.util.*; util.* java import java.io.*; io.* java class Main{
	public static void main(String[]args){
		Scanner in=new Scanner(System.in);
		PrintWriter out=new PrintWriter(System.out, true);
		String str[]=in.nextLine().split(" ");
		int n=Integer.parseInt(str[0]);
		int q=Integer.parseInt(str[1]);
		HashMap<String, Integer> map=new HashMap<>();
		Queue<String> queue=new LinkedList<>();
		for(int i=0;i<n;i++){
			str=in.nextLine().split(" ");
			String pid=str[0];
			int ptime=Integer.parseInt(str[1]);
			map.put(pid, ptime);
			queue.add(pid);
		}
		int time=0;
		ArrayList<String> list=new ArrayList<>();
		HashMap<String, Integer> map_2=new HashMap<>();
		
		while(true){
		       String pid=queue.poll();
		       int ptime=map.get(pid);
		       time+=Math.min(q, ptime);
		       ptime=Math.max(0, ptime-q);
		       map.put(pid, ptime);
		       if(ptime==0){
			       list.add(pid);
			       map_2.put(pid, time);
			       if(list.size()==n)
				       break;
		       }else{
			       queue.add(pid);
		       }
		}
		for(int i=0;i<list.size();i++){
			out.println(list.get(i)+" "+map_2.get(list.get(i)));
		}
	}

} Main public static void main(String[]args){
		Scanner in=new Scanner(System.in);
		PrintWriter out=new PrintWriter(System.out, true);
		String str[]=in.nextLine().split(" ");
		int n=Integer.parseInt(str[0]);
		int q=Integer.parseInt(str[1]);
		HashMap<String, Integer> map=new HashMap<>();
		Queue<String> queue=new LinkedList<>();
		for(int i=0;i<n;i++){
			str=in.nextLine().split(" ");
			String pid=str[0];
			int ptime=Integer.parseInt(str[1]);
			map.put(pid, ptime);
			queue.add(pid);
		}
		int time=0;
		ArrayList<String> list=new ArrayList<>();
		HashMap<String, Integer> map_2=new HashMap<>();
		
		while(true){
		       String pid=queue.poll();
		       int ptime=map.get(pid);
		       time+=Math.min(q, ptime);
		       ptime=Math.max(0, ptime-q);
		       map.put(pid, ptime);
		       if(ptime==0){
			       list.add(pid);
			       map_2.put(pid, time);
			       if(list.size()==n)
				       break;
		       }else{
			       queue.add(pid);
		       }
		}
		for(int i=0;i<list.size();i++){
			out.println(list.get(i)+" "+map_2.get(list.get(i)));
		}
	} main {
		Scanner in=new Scanner(System.in);
		PrintWriter out=new PrintWriter(System.out, true);
		String str[]=in.nextLine().split(" ");
		int n=Integer.parseInt(str[0]);
		int q=Integer.parseInt(str[1]);
		HashMap<String, Integer> map=new HashMap<>();
		Queue<String> queue=new LinkedList<>();
		for(int i=0;i<n;i++){
			str=in.nextLine().split(" ");
			String pid=str[0];
			int ptime=Integer.parseInt(str[1]);
			map.put(pid, ptime);
			queue.add(pid);
		}
		int time=0;
		ArrayList<String> list=new ArrayList<>();
		HashMap<String, Integer> map_2=new HashMap<>();
		
		while(true){
		       String pid=queue.poll();
		       int ptime=map.get(pid);
		       time+=Math.min(q, ptime);
		       ptime=Math.max(0, ptime-q);
		       map.put(pid, ptime);
		       if(ptime==0){
			       list.add(pid);
			       map_2.put(pid, time);
			       if(list.size()==n)
				       break;
		       }else{
			       queue.add(pid);
		       }
		}
		for(int i=0;i<list.size();i++){
			out.println(list.get(i)+" "+map_2.get(list.get(i)));
		}
	} Scanner in=new Scanner(System.in); in new Scanner(System.in) PrintWriter out=new PrintWriter(System.out, true); out new PrintWriter(System.out, true) String str[]=in.nextLine().split(" "); str in.nextLine().split(" ") in.nextLine().split in.nextLine() in.nextLine in " " int n=Integer.parseInt(str[0]); n Integer.parseInt(str[0]) Integer.parseInt Integer str[0] str 0 int q=Integer.parseInt(str[1]); q Integer.parseInt(str[1]) Integer.parseInt Integer str[1] str 1 HashMap<String, Integer> map=new HashMap<>(); map new HashMap<>() Queue<String> queue=new LinkedList<>(); queue new LinkedList<>() for(int i=0;i<n;i++){
			str=in.nextLine().split(" ");
			String pid=str[0];
			int ptime=Integer.parseInt(str[1]);
			map.put(pid, ptime);
			queue.add(pid);
		} int i=0; int i=0; i 0 i<n i n i++ i++ i {
			str=in.nextLine().split(" ");
			String pid=str[0];
			int ptime=Integer.parseInt(str[1]);
			map.put(pid, ptime);
			queue.add(pid);
		} {
			str=in.nextLine().split(" ");
			String pid=str[0];
			int ptime=Integer.parseInt(str[1]);
			map.put(pid, ptime);
			queue.add(pid);
		} str=in.nextLine().split(" ") str in.nextLine().split(" ") in.nextLine().split in.nextLine() in.nextLine in " " String pid=str[0]; pid str[0] str 0 int ptime=Integer.parseInt(str[1]); ptime Integer.parseInt(str[1]) Integer.parseInt Integer str[1] str 1 map.put(pid, ptime) map.put map pid ptime queue.add(pid) queue.add queue pid int time=0; time 0 ArrayList<String> list=new ArrayList<>(); list new ArrayList<>() HashMap<String, Integer> map_2=new HashMap<>(); map_2 new HashMap<>() while(true){
		       String pid=queue.poll();
		       int ptime=map.get(pid);
		       time+=Math.min(q, ptime);
		       ptime=Math.max(0, ptime-q);
		       map.put(pid, ptime);
		       if(ptime==0){
			       list.add(pid);
			       map_2.put(pid, time);
			       if(list.size()==n)
				       break;
		       }else{
			       queue.add(pid);
		       }
		} true {
		       String pid=queue.poll();
		       int ptime=map.get(pid);
		       time+=Math.min(q, ptime);
		       ptime=Math.max(0, ptime-q);
		       map.put(pid, ptime);
		       if(ptime==0){
			       list.add(pid);
			       map_2.put(pid, time);
			       if(list.size()==n)
				       break;
		       }else{
			       queue.add(pid);
		       }
		} String pid=queue.poll(); pid queue.poll() queue.poll queue int ptime=map.get(pid); ptime map.get(pid) map.get map pid time+=Math.min(q, ptime) time Math.min(q, ptime) Math.min Math q ptime ptime=Math.max(0, ptime-q) ptime Math.max(0, ptime-q) Math.max Math 0 ptime-q ptime q map.put(pid, ptime) map.put map pid ptime if(ptime==0){
			       list.add(pid);
			       map_2.put(pid, time);
			       if(list.size()==n)
				       break;
		       }else{
			       queue.add(pid);
		       } ptime==0 ptime 0 {
			       list.add(pid);
			       map_2.put(pid, time);
			       if(list.size()==n)
				       break;
		       } list.add(pid) list.add list pid map_2.put(pid, time) map_2.put map_2 pid time if(list.size()==n)
				       break; list.size()==n list.size() list.size list n break; {
			       queue.add(pid);
		       } queue.add(pid) queue.add queue pid for(int i=0;i<list.size();i++){
			out.println(list.get(i)+" "+map_2.get(list.get(i)));
		} int i=0; int i=0; i 0 i<list.size() i list.size() list.size list i++ i++ i {
			out.println(list.get(i)+" "+map_2.get(list.get(i)));
		} {
			out.println(list.get(i)+" "+map_2.get(list.get(i)));
		} out.println(list.get(i)+" "+map_2.get(list.get(i))) out.println out list.get(i)+" "+map_2.get(list.get(i)) list.get(i)+" "+map_2.get(list.get(i)) list.get(i) list.get list i " " map_2.get(list.get(i)) map_2.get map_2 list.get(i) list.get list i String[]args args
import java.util.*;
import java.io.*;
class Main{
	public static void main(String[]args){
		Scanner in=new Scanner(System.in);
		PrintWriter out=new PrintWriter(System.out, true);
		String str[]=in.nextLine().split(" ");
		int n=Integer.parseInt(str[0]);
		int q=Integer.parseInt(str[1]);
		HashMap<String, Integer> map=new HashMap<>();
		Queue<String> queue=new LinkedList<>();
		for(int i=0;i<n;i++){
			str=in.nextLine().split(" ");
			String pid=str[0];
			int ptime=Integer.parseInt(str[1]);
			map.put(pid, ptime);
			queue.add(pid);
		}
		int time=0;
		ArrayList<String> list=new ArrayList<>();
		HashMap<String, Integer> map_2=new HashMap<>();
		
		while(true){
		       String pid=queue.poll();
		       int ptime=map.get(pid);
		       time+=Math.min(q, ptime);
		       ptime=Math.max(0, ptime-q);
		       map.put(pid, ptime);
		       if(ptime==0){
			       list.add(pid);
			       map_2.put(pid, time);
			       if(list.size()==n)
				       break;
		       }else{
			       queue.add(pid);
		       }
		}
		for(int i=0;i<list.size();i++){
			out.println(list.get(i)+" "+map_2.get(list.get(i)));
		}
	}

}
