import java.io.*;
import java.util.*;

public class Main {
	public static void main(String [] args) throws NumberFormatException, IOException{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		PrintWriter pr=new PrintWriter(System.out);
		ArrayList<task> ar=new ArrayList<task>();
		String[] s=br.readLine().split(" ");
		int n=Integer.parseInt(s[0]),q=Integer.parseInt(s[1]);
		for (int i=0;i<n;i++){
			ar.add(new task(br.readLine()));
		}
		int totaltime=0;
		while (!ar.isEmpty()){
			int tasktime=ar.get(0).gettime();
			if (tasktime>q){
				ar.get(0).timecut(q);
				ar.add(ar.get(0));
				ar.remove(0);
				totaltime+=q;
			}else {
				totaltime+=ar.get(0).gettime();
				pr.println(ar.get(0).getname()+" "+totaltime);
				ar.remove(0);
			}
		}
		pr.close();
	}
}

class task{
	private String name;
	private int time;
	public task(String str){
		String[] stmp=str.split(" ");
		this.name=stmp[0];
		this.time=Integer.parseInt(stmp[1]);
	}
	public String getname(){
		return this.name;
	}
	public int gettime(){
		return this.time;
	}
	public void timecut(int t){
		this.time-=t;
	}
} import java.io.*; io.* java import java.util.*; util.* java public class Main {
	public static void main(String [] args) throws NumberFormatException, IOException{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		PrintWriter pr=new PrintWriter(System.out);
		ArrayList<task> ar=new ArrayList<task>();
		String[] s=br.readLine().split(" ");
		int n=Integer.parseInt(s[0]),q=Integer.parseInt(s[1]);
		for (int i=0;i<n;i++){
			ar.add(new task(br.readLine()));
		}
		int totaltime=0;
		while (!ar.isEmpty()){
			int tasktime=ar.get(0).gettime();
			if (tasktime>q){
				ar.get(0).timecut(q);
				ar.add(ar.get(0));
				ar.remove(0);
				totaltime+=q;
			}else {
				totaltime+=ar.get(0).gettime();
				pr.println(ar.get(0).getname()+" "+totaltime);
				ar.remove(0);
			}
		}
		pr.close();
	}
} Main public static void main(String [] args) throws NumberFormatException, IOException{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		PrintWriter pr=new PrintWriter(System.out);
		ArrayList<task> ar=new ArrayList<task>();
		String[] s=br.readLine().split(" ");
		int n=Integer.parseInt(s[0]),q=Integer.parseInt(s[1]);
		for (int i=0;i<n;i++){
			ar.add(new task(br.readLine()));
		}
		int totaltime=0;
		while (!ar.isEmpty()){
			int tasktime=ar.get(0).gettime();
			if (tasktime>q){
				ar.get(0).timecut(q);
				ar.add(ar.get(0));
				ar.remove(0);
				totaltime+=q;
			}else {
				totaltime+=ar.get(0).gettime();
				pr.println(ar.get(0).getname()+" "+totaltime);
				ar.remove(0);
			}
		}
		pr.close();
	} main {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		PrintWriter pr=new PrintWriter(System.out);
		ArrayList<task> ar=new ArrayList<task>();
		String[] s=br.readLine().split(" ");
		int n=Integer.parseInt(s[0]),q=Integer.parseInt(s[1]);
		for (int i=0;i<n;i++){
			ar.add(new task(br.readLine()));
		}
		int totaltime=0;
		while (!ar.isEmpty()){
			int tasktime=ar.get(0).gettime();
			if (tasktime>q){
				ar.get(0).timecut(q);
				ar.add(ar.get(0));
				ar.remove(0);
				totaltime+=q;
			}else {
				totaltime+=ar.get(0).gettime();
				pr.println(ar.get(0).getname()+" "+totaltime);
				ar.remove(0);
			}
		}
		pr.close();
	} BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) PrintWriter pr=new PrintWriter(System.out); pr new PrintWriter(System.out) ArrayList<task> ar=new ArrayList<task>(); ar new ArrayList<task>() String[] s=br.readLine().split(" "); s br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " int n=Integer.parseInt(s[0]) n Integer.parseInt(s[0]) Integer.parseInt Integer s[0] s 0 q=Integer.parseInt(s[1]); q Integer.parseInt(s[1]) Integer.parseInt Integer s[1] s 1 for (int i=0;i<n;i++){
			ar.add(new task(br.readLine()));
		} int i=0; int i=0; i 0 i<n i n i++ i++ i {
			ar.add(new task(br.readLine()));
		} {
			ar.add(new task(br.readLine()));
		} ar.add(new task(br.readLine())) ar.add ar new task(br.readLine()) int totaltime=0; totaltime 0 while (!ar.isEmpty()){
			int tasktime=ar.get(0).gettime();
			if (tasktime>q){
				ar.get(0).timecut(q);
				ar.add(ar.get(0));
				ar.remove(0);
				totaltime+=q;
			}else {
				totaltime+=ar.get(0).gettime();
				pr.println(ar.get(0).getname()+" "+totaltime);
				ar.remove(0);
			}
		} !ar.isEmpty() ar.isEmpty() ar.isEmpty ar {
			int tasktime=ar.get(0).gettime();
			if (tasktime>q){
				ar.get(0).timecut(q);
				ar.add(ar.get(0));
				ar.remove(0);
				totaltime+=q;
			}else {
				totaltime+=ar.get(0).gettime();
				pr.println(ar.get(0).getname()+" "+totaltime);
				ar.remove(0);
			}
		} int tasktime=ar.get(0).gettime(); tasktime ar.get(0).gettime() ar.get(0).gettime ar.get(0) ar.get ar 0 if (tasktime>q){
				ar.get(0).timecut(q);
				ar.add(ar.get(0));
				ar.remove(0);
				totaltime+=q;
			}else {
				totaltime+=ar.get(0).gettime();
				pr.println(ar.get(0).getname()+" "+totaltime);
				ar.remove(0);
			} tasktime>q tasktime q {
				ar.get(0).timecut(q);
				ar.add(ar.get(0));
				ar.remove(0);
				totaltime+=q;
			} ar.get(0).timecut(q) ar.get(0).timecut ar.get(0) ar.get ar 0 q ar.add(ar.get(0)) ar.add ar ar.get(0) ar.get ar 0 ar.remove(0) ar.remove ar 0 totaltime+=q totaltime q {
				totaltime+=ar.get(0).gettime();
				pr.println(ar.get(0).getname()+" "+totaltime);
				ar.remove(0);
			} totaltime+=ar.get(0).gettime() totaltime ar.get(0).gettime() ar.get(0).gettime ar.get(0) ar.get ar 0 pr.println(ar.get(0).getname()+" "+totaltime) pr.println pr ar.get(0).getname()+" "+totaltime ar.get(0).getname()+" "+totaltime ar.get(0).getname() ar.get(0).getname ar.get(0) ar.get ar 0 " " totaltime ar.remove(0) ar.remove ar 0 pr.close() pr.close pr String [] args args class task{
	private String name;
	private int time;
	public task(String str){
		String[] stmp=str.split(" ");
		this.name=stmp[0];
		this.time=Integer.parseInt(stmp[1]);
	}
	public String getname(){
		return this.name;
	}
	public int gettime(){
		return this.time;
	}
	public void timecut(int t){
		this.time-=t;
	}
} task private String name; name private int time; time public task(String str){
		String[] stmp=str.split(" ");
		this.name=stmp[0];
		this.time=Integer.parseInt(stmp[1]);
	} task {
		String[] stmp=str.split(" ");
		this.name=stmp[0];
		this.time=Integer.parseInt(stmp[1]);
	} String[] stmp=str.split(" "); stmp str.split(" ") str.split str " " this.name=stmp[0] this.name this this.name stmp[0] stmp 0 this.time=Integer.parseInt(stmp[1]) this.time this this.time Integer.parseInt(stmp[1]) Integer.parseInt Integer stmp[1] stmp 1 String str str public String getname(){
		return this.name;
	} getname {
		return this.name;
	} return this.name; this.name this this.name public int gettime(){
		return this.time;
	} gettime {
		return this.time;
	} return this.time; this.time this this.time public void timecut(int t){
		this.time-=t;
	} timecut {
		this.time-=t;
	} this.time-=t this.time this this.time t int t t public class Main {
	public static void main(String [] args) throws NumberFormatException, IOException{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		PrintWriter pr=new PrintWriter(System.out);
		ArrayList<task> ar=new ArrayList<task>();
		String[] s=br.readLine().split(" ");
		int n=Integer.parseInt(s[0]),q=Integer.parseInt(s[1]);
		for (int i=0;i<n;i++){
			ar.add(new task(br.readLine()));
		}
		int totaltime=0;
		while (!ar.isEmpty()){
			int tasktime=ar.get(0).gettime();
			if (tasktime>q){
				ar.get(0).timecut(q);
				ar.add(ar.get(0));
				ar.remove(0);
				totaltime+=q;
			}else {
				totaltime+=ar.get(0).gettime();
				pr.println(ar.get(0).getname()+" "+totaltime);
				ar.remove(0);
			}
		}
		pr.close();
	}
} public class Main {
	public static void main(String [] args) throws NumberFormatException, IOException{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		PrintWriter pr=new PrintWriter(System.out);
		ArrayList<task> ar=new ArrayList<task>();
		String[] s=br.readLine().split(" ");
		int n=Integer.parseInt(s[0]),q=Integer.parseInt(s[1]);
		for (int i=0;i<n;i++){
			ar.add(new task(br.readLine()));
		}
		int totaltime=0;
		while (!ar.isEmpty()){
			int tasktime=ar.get(0).gettime();
			if (tasktime>q){
				ar.get(0).timecut(q);
				ar.add(ar.get(0));
				ar.remove(0);
				totaltime+=q;
			}else {
				totaltime+=ar.get(0).gettime();
				pr.println(ar.get(0).getname()+" "+totaltime);
				ar.remove(0);
			}
		}
		pr.close();
	}
} Main
import java.io.*;
import java.util.*;

public class Main {
	public static void main(String [] args) throws NumberFormatException, IOException{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		PrintWriter pr=new PrintWriter(System.out);
		ArrayList<task> ar=new ArrayList<task>();
		String[] s=br.readLine().split(" ");
		int n=Integer.parseInt(s[0]),q=Integer.parseInt(s[1]);
		for (int i=0;i<n;i++){
			ar.add(new task(br.readLine()));
		}
		int totaltime=0;
		while (!ar.isEmpty()){
			int tasktime=ar.get(0).gettime();
			if (tasktime>q){
				ar.get(0).timecut(q);
				ar.add(ar.get(0));
				ar.remove(0);
				totaltime+=q;
			}else {
				totaltime+=ar.get(0).gettime();
				pr.println(ar.get(0).getname()+" "+totaltime);
				ar.remove(0);
			}
		}
		pr.close();
	}
}

class task{
	private String name;
	private int time;
	public task(String str){
		String[] stmp=str.split(" ");
		this.name=stmp[0];
		this.time=Integer.parseInt(stmp[1]);
	}
	public String getname(){
		return this.name;
	}
	public int gettime(){
		return this.time;
	}
	public void timecut(int t){
		this.time-=t;
	}
}