import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;


public class Main {
	public static void main(String[] args) throws NumberFormatException, IOException {
		//????????????????????????
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		
		//?????????
		String[] arrayString = bf.readLine().split(" ");
		
		int num=Integer.parseInt(arrayString[0]);
		int q=Integer.parseInt(arrayString[1]);
		
		ArrayList<Process> que=new ArrayList<Process>();
		ArrayList<Process> finlist=new ArrayList<Process>();
		
		String list;
		while((list=bf.readLine())!=null){
			String[] str=list.split(" ");
			Process process=new Process(str[0],Integer.parseInt(str[1]));
			que.add(process);
		}
		
		int time=0;
		while(que.size()!=0){
			Process process = que.get(0);
			if(process.getTime()<=q){
				time+=process.getTime();
				process.setFinishtime(time);
				finlist.add(process);
				que.remove(0);
			}
			else{
				time+=q;
				process.reduceTime(q);
				que.add(process);
				que.remove(0);
			}
		}
		
		for(Process pro:finlist){
			System.out.println(pro.getName() + " " + pro.getFinishtime());
		}
	}
}

class Process{
	private String name;
	private int time;
	private int finishtime;
	
	public Process(String name,int time){
		this.setName(name);
		this.setTime(time);
	}

	public void reduceTime(int q) {
		this.time-=q;

		
	}

	public int getTime() {
		return time;
	}

	public void setTime(int time) {
		this.time = time;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getFinishtime() {
		return finishtime;
	}

	public void setFinishtime(int finishtime) {
		this.finishtime = finishtime;
	}
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io import java.util.ArrayList; ArrayList java.util public class Main {
	public static void main(String[] args) throws NumberFormatException, IOException {
		//????????????????????????
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		
		//?????????
		String[] arrayString = bf.readLine().split(" ");
		
		int num=Integer.parseInt(arrayString[0]);
		int q=Integer.parseInt(arrayString[1]);
		
		ArrayList<Process> que=new ArrayList<Process>();
		ArrayList<Process> finlist=new ArrayList<Process>();
		
		String list;
		while((list=bf.readLine())!=null){
			String[] str=list.split(" ");
			Process process=new Process(str[0],Integer.parseInt(str[1]));
			que.add(process);
		}
		
		int time=0;
		while(que.size()!=0){
			Process process = que.get(0);
			if(process.getTime()<=q){
				time+=process.getTime();
				process.setFinishtime(time);
				finlist.add(process);
				que.remove(0);
			}
			else{
				time+=q;
				process.reduceTime(q);
				que.add(process);
				que.remove(0);
			}
		}
		
		for(Process pro:finlist){
			System.out.println(pro.getName() + " " + pro.getFinishtime());
		}
	}
} Main public static void main(String[] args) throws NumberFormatException, IOException {
		//????????????????????????
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		
		//?????????
		String[] arrayString = bf.readLine().split(" ");
		
		int num=Integer.parseInt(arrayString[0]);
		int q=Integer.parseInt(arrayString[1]);
		
		ArrayList<Process> que=new ArrayList<Process>();
		ArrayList<Process> finlist=new ArrayList<Process>();
		
		String list;
		while((list=bf.readLine())!=null){
			String[] str=list.split(" ");
			Process process=new Process(str[0],Integer.parseInt(str[1]));
			que.add(process);
		}
		
		int time=0;
		while(que.size()!=0){
			Process process = que.get(0);
			if(process.getTime()<=q){
				time+=process.getTime();
				process.setFinishtime(time);
				finlist.add(process);
				que.remove(0);
			}
			else{
				time+=q;
				process.reduceTime(q);
				que.add(process);
				que.remove(0);
			}
		}
		
		for(Process pro:finlist){
			System.out.println(pro.getName() + " " + pro.getFinishtime());
		}
	} main {
		//????????????????????????
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		
		//?????????
		String[] arrayString = bf.readLine().split(" ");
		
		int num=Integer.parseInt(arrayString[0]);
		int q=Integer.parseInt(arrayString[1]);
		
		ArrayList<Process> que=new ArrayList<Process>();
		ArrayList<Process> finlist=new ArrayList<Process>();
		
		String list;
		while((list=bf.readLine())!=null){
			String[] str=list.split(" ");
			Process process=new Process(str[0],Integer.parseInt(str[1]));
			que.add(process);
		}
		
		int time=0;
		while(que.size()!=0){
			Process process = que.get(0);
			if(process.getTime()<=q){
				time+=process.getTime();
				process.setFinishtime(time);
				finlist.add(process);
				que.remove(0);
			}
			else{
				time+=q;
				process.reduceTime(q);
				que.add(process);
				que.remove(0);
			}
		}
		
		for(Process pro:finlist){
			System.out.println(pro.getName() + " " + pro.getFinishtime());
		}
	} BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); bf new BufferedReader(new InputStreamReader(System.in)) String[] arrayString = bf.readLine().split(" "); arrayString bf.readLine().split(" ") bf.readLine().split bf.readLine() bf.readLine bf " " int num=Integer.parseInt(arrayString[0]); num Integer.parseInt(arrayString[0]) Integer.parseInt Integer arrayString[0] arrayString 0 int q=Integer.parseInt(arrayString[1]); q Integer.parseInt(arrayString[1]) Integer.parseInt Integer arrayString[1] arrayString 1 ArrayList<Process> que=new ArrayList<Process>(); que new ArrayList<Process>() ArrayList<Process> finlist=new ArrayList<Process>(); finlist new ArrayList<Process>() String list; list while((list=bf.readLine())!=null){
			String[] str=list.split(" ");
			Process process=new Process(str[0],Integer.parseInt(str[1]));
			que.add(process);
		} (list=bf.readLine())!=null (list=bf.readLine()) list bf.readLine() bf.readLine bf null {
			String[] str=list.split(" ");
			Process process=new Process(str[0],Integer.parseInt(str[1]));
			que.add(process);
		} String[] str=list.split(" "); str list.split(" ") list.split list " " Process process=new Process(str[0],Integer.parseInt(str[1])); process new Process(str[0],Integer.parseInt(str[1])) que.add(process) que.add que process int time=0; time 0 while(que.size()!=0){
			Process process = que.get(0);
			if(process.getTime()<=q){
				time+=process.getTime();
				process.setFinishtime(time);
				finlist.add(process);
				que.remove(0);
			}
			else{
				time+=q;
				process.reduceTime(q);
				que.add(process);
				que.remove(0);
			}
		} que.size()!=0 que.size() que.size que 0 {
			Process process = que.get(0);
			if(process.getTime()<=q){
				time+=process.getTime();
				process.setFinishtime(time);
				finlist.add(process);
				que.remove(0);
			}
			else{
				time+=q;
				process.reduceTime(q);
				que.add(process);
				que.remove(0);
			}
		} Process process = que.get(0); process que.get(0) que.get que 0 if(process.getTime()<=q){
				time+=process.getTime();
				process.setFinishtime(time);
				finlist.add(process);
				que.remove(0);
			}
			else{
				time+=q;
				process.reduceTime(q);
				que.add(process);
				que.remove(0);
			} process.getTime()<=q process.getTime() process.getTime process q {
				time+=process.getTime();
				process.setFinishtime(time);
				finlist.add(process);
				que.remove(0);
			} time+=process.getTime() time process.getTime() process.getTime process process.setFinishtime(time) process.setFinishtime process time finlist.add(process) finlist.add finlist process que.remove(0) que.remove que 0 {
				time+=q;
				process.reduceTime(q);
				que.add(process);
				que.remove(0);
			} time+=q time q process.reduceTime(q) process.reduceTime process q que.add(process) que.add que process que.remove(0) que.remove que 0 for(Process pro:finlist){
			System.out.println(pro.getName() + " " + pro.getFinishtime());
		} Process pro finlist {
			System.out.println(pro.getName() + " " + pro.getFinishtime());
		} {
			System.out.println(pro.getName() + " " + pro.getFinishtime());
		} System.out.println(pro.getName() + " " + pro.getFinishtime()) System.out.println System.out System System.out pro.getName() + " " + pro.getFinishtime() pro.getName() + " " + pro.getFinishtime() pro.getName() pro.getName pro " " pro.getFinishtime() pro.getFinishtime pro String[] args args class Process{
	private String name;
	private int time;
	private int finishtime;
	
	public Process(String name,int time){
		this.setName(name);
		this.setTime(time);
	}

	public void reduceTime(int q) {
		this.time-=q;

		
	}

	public int getTime() {
		return time;
	}

	public void setTime(int time) {
		this.time = time;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getFinishtime() {
		return finishtime;
	}

	public void setFinishtime(int finishtime) {
		this.finishtime = finishtime;
	}
} Process private String name; name private int time; time private int finishtime; finishtime public Process(String name,int time){
		this.setName(name);
		this.setTime(time);
	} Process {
		this.setName(name);
		this.setTime(time);
	} this.setName(name) this.setName this name this.setTime(time) this.setTime this time String name name int time time public void reduceTime(int q) {
		this.time-=q;

		
	} reduceTime {
		this.time-=q;

		
	} this.time-=q this.time this this.time q int q q public int getTime() {
		return time;
	} getTime {
		return time;
	} return time; time public void setTime(int time) {
		this.time = time;
	} setTime {
		this.time = time;
	} this.time = time this.time this this.time time int time time public String getName() {
		return name;
	} getName {
		return name;
	} return name; name public void setName(String name) {
		this.name = name;
	} setName {
		this.name = name;
	} this.name = name this.name this this.name name String name name public int getFinishtime() {
		return finishtime;
	} getFinishtime {
		return finishtime;
	} return finishtime; finishtime public void setFinishtime(int finishtime) {
		this.finishtime = finishtime;
	} setFinishtime {
		this.finishtime = finishtime;
	} this.finishtime = finishtime this.finishtime this this.finishtime finishtime int finishtime finishtime public class Main {
	public static void main(String[] args) throws NumberFormatException, IOException {
		//????????????????????????
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		
		//?????????
		String[] arrayString = bf.readLine().split(" ");
		
		int num=Integer.parseInt(arrayString[0]);
		int q=Integer.parseInt(arrayString[1]);
		
		ArrayList<Process> que=new ArrayList<Process>();
		ArrayList<Process> finlist=new ArrayList<Process>();
		
		String list;
		while((list=bf.readLine())!=null){
			String[] str=list.split(" ");
			Process process=new Process(str[0],Integer.parseInt(str[1]));
			que.add(process);
		}
		
		int time=0;
		while(que.size()!=0){
			Process process = que.get(0);
			if(process.getTime()<=q){
				time+=process.getTime();
				process.setFinishtime(time);
				finlist.add(process);
				que.remove(0);
			}
			else{
				time+=q;
				process.reduceTime(q);
				que.add(process);
				que.remove(0);
			}
		}
		
		for(Process pro:finlist){
			System.out.println(pro.getName() + " " + pro.getFinishtime());
		}
	}
} public class Main {
	public static void main(String[] args) throws NumberFormatException, IOException {
		//????????????????????????
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		
		//?????????
		String[] arrayString = bf.readLine().split(" ");
		
		int num=Integer.parseInt(arrayString[0]);
		int q=Integer.parseInt(arrayString[1]);
		
		ArrayList<Process> que=new ArrayList<Process>();
		ArrayList<Process> finlist=new ArrayList<Process>();
		
		String list;
		while((list=bf.readLine())!=null){
			String[] str=list.split(" ");
			Process process=new Process(str[0],Integer.parseInt(str[1]));
			que.add(process);
		}
		
		int time=0;
		while(que.size()!=0){
			Process process = que.get(0);
			if(process.getTime()<=q){
				time+=process.getTime();
				process.setFinishtime(time);
				finlist.add(process);
				que.remove(0);
			}
			else{
				time+=q;
				process.reduceTime(q);
				que.add(process);
				que.remove(0);
			}
		}
		
		for(Process pro:finlist){
			System.out.println(pro.getName() + " " + pro.getFinishtime());
		}
	}
} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;


public class Main {
	public static void main(String[] args) throws NumberFormatException, IOException {
		//????????????????????????
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		
		//?????????
		String[] arrayString = bf.readLine().split(" ");
		
		int num=Integer.parseInt(arrayString[0]);
		int q=Integer.parseInt(arrayString[1]);
		
		ArrayList<Process> que=new ArrayList<Process>();
		ArrayList<Process> finlist=new ArrayList<Process>();
		
		String list;
		while((list=bf.readLine())!=null){
			String[] str=list.split(" ");
			Process process=new Process(str[0],Integer.parseInt(str[1]));
			que.add(process);
		}
		
		int time=0;
		while(que.size()!=0){
			Process process = que.get(0);
			if(process.getTime()<=q){
				time+=process.getTime();
				process.setFinishtime(time);
				finlist.add(process);
				que.remove(0);
			}
			else{
				time+=q;
				process.reduceTime(q);
				que.add(process);
				que.remove(0);
			}
		}
		
		for(Process pro:finlist){
			System.out.println(pro.getName() + " " + pro.getFinishtime());
		}
	}
}

class Process{
	private String name;
	private int time;
	private int finishtime;
	
	public Process(String name,int time){
		this.setName(name);
		this.setTime(time);
	}

	public void reduceTime(int q) {
		this.time-=q;

		
	}

	public int getTime() {
		return time;
	}

	public void setTime(int time) {
		this.time = time;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getFinishtime() {
		return finishtime;
	}

	public void setFinishtime(int finishtime) {
		this.finishtime = finishtime;
	}
}