import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		new Main().run();
	}
	public void run(){
		Scanner scan = new Scanner(System.in);
		while(scan.hasNext()){
			int n = scan.nextInt();
			int sTime = scan.nextInt();
			Process[] schedule = new Process[n];
			int count = n;
			int j = 0;
			int sumTime = 0;
			for(int i = 0;i < n;i++){
				schedule[i] = new Process(scan.next(),scan.nextInt());
			}
			int a = 0;
			int len = schedule.length;
			while(count > 1){
				if(count < len/2 && j == len && count > 1000){
					Process[] newSchedule = new Process[count];
					int k = 0;
					for(int i = 0;i < len;i++){
						if(schedule[i].getTime() == 0){
							continue;
						}
						newSchedule[k] = new Process(schedule[i].getName(),schedule[i].getTime());
						k++;
					}
					schedule = newSchedule;
					len = schedule.length;
					j = 0;
				}
				if(j >= len){
					j %= len;
				}
				a = schedule[j].getTime();
				if(a == 0){
					j++;
					continue;
				}else if(a <= sTime){
					sumTime += a;
					System.out.println(schedule[j].getName() + " " + sumTime);
					schedule[j++].setTime(0);
					count--;
					continue;
				}
				sumTime += sTime;
				schedule[j++].minusTime(sTime);
			}
			for(int i = 0;i < len;i++){
				if(schedule[i].getTime() == 0){
					continue;
				}
				System.out.println(schedule[i].getName() + " " +(sumTime+schedule[i].getTime()));
				break;
			}
		}
	}
	class Process{
		String name;
		int time;
		public Process(){
		}
		public Process(String name,int time){
			this.name = name;
			this.time = time;
		}
		public int getTime(){
			return this.time;
		}
		public void setTime(int time){
			this.time = time;
		}
		public String getName(){
			return this.name;
		}
		public void minusTime(int time){
			this.time -= time;
		}
		public void setName(String name){
			this.name = name;
		}
	}
} import java.util.Scanner; Scanner java.util public class Main{
	public static void main(String[] args){
		new Main().run();
	}
	public void run(){
		Scanner scan = new Scanner(System.in);
		while(scan.hasNext()){
			int n = scan.nextInt();
			int sTime = scan.nextInt();
			Process[] schedule = new Process[n];
			int count = n;
			int j = 0;
			int sumTime = 0;
			for(int i = 0;i < n;i++){
				schedule[i] = new Process(scan.next(),scan.nextInt());
			}
			int a = 0;
			int len = schedule.length;
			while(count > 1){
				if(count < len/2 && j == len && count > 1000){
					Process[] newSchedule = new Process[count];
					int k = 0;
					for(int i = 0;i < len;i++){
						if(schedule[i].getTime() == 0){
							continue;
						}
						newSchedule[k] = new Process(schedule[i].getName(),schedule[i].getTime());
						k++;
					}
					schedule = newSchedule;
					len = schedule.length;
					j = 0;
				}
				if(j >= len){
					j %= len;
				}
				a = schedule[j].getTime();
				if(a == 0){
					j++;
					continue;
				}else if(a <= sTime){
					sumTime += a;
					System.out.println(schedule[j].getName() + " " + sumTime);
					schedule[j++].setTime(0);
					count--;
					continue;
				}
				sumTime += sTime;
				schedule[j++].minusTime(sTime);
			}
			for(int i = 0;i < len;i++){
				if(schedule[i].getTime() == 0){
					continue;
				}
				System.out.println(schedule[i].getName() + " " +(sumTime+schedule[i].getTime()));
				break;
			}
		}
	}
	class Process{
		String name;
		int time;
		public Process(){
		}
		public Process(String name,int time){
			this.name = name;
			this.time = time;
		}
		public int getTime(){
			return this.time;
		}
		public void setTime(int time){
			this.time = time;
		}
		public String getName(){
			return this.name;
		}
		public void minusTime(int time){
			this.time -= time;
		}
		public void setName(String name){
			this.name = name;
		}
	}
} Main public static void main(String[] args){
		new Main().run();
	} main {
		new Main().run();
	} new Main().run() new Main().run new Main() String[] args args public void run(){
		Scanner scan = new Scanner(System.in);
		while(scan.hasNext()){
			int n = scan.nextInt();
			int sTime = scan.nextInt();
			Process[] schedule = new Process[n];
			int count = n;
			int j = 0;
			int sumTime = 0;
			for(int i = 0;i < n;i++){
				schedule[i] = new Process(scan.next(),scan.nextInt());
			}
			int a = 0;
			int len = schedule.length;
			while(count > 1){
				if(count < len/2 && j == len && count > 1000){
					Process[] newSchedule = new Process[count];
					int k = 0;
					for(int i = 0;i < len;i++){
						if(schedule[i].getTime() == 0){
							continue;
						}
						newSchedule[k] = new Process(schedule[i].getName(),schedule[i].getTime());
						k++;
					}
					schedule = newSchedule;
					len = schedule.length;
					j = 0;
				}
				if(j >= len){
					j %= len;
				}
				a = schedule[j].getTime();
				if(a == 0){
					j++;
					continue;
				}else if(a <= sTime){
					sumTime += a;
					System.out.println(schedule[j].getName() + " " + sumTime);
					schedule[j++].setTime(0);
					count--;
					continue;
				}
				sumTime += sTime;
				schedule[j++].minusTime(sTime);
			}
			for(int i = 0;i < len;i++){
				if(schedule[i].getTime() == 0){
					continue;
				}
				System.out.println(schedule[i].getName() + " " +(sumTime+schedule[i].getTime()));
				break;
			}
		}
	} run {
		Scanner scan = new Scanner(System.in);
		while(scan.hasNext()){
			int n = scan.nextInt();
			int sTime = scan.nextInt();
			Process[] schedule = new Process[n];
			int count = n;
			int j = 0;
			int sumTime = 0;
			for(int i = 0;i < n;i++){
				schedule[i] = new Process(scan.next(),scan.nextInt());
			}
			int a = 0;
			int len = schedule.length;
			while(count > 1){
				if(count < len/2 && j == len && count > 1000){
					Process[] newSchedule = new Process[count];
					int k = 0;
					for(int i = 0;i < len;i++){
						if(schedule[i].getTime() == 0){
							continue;
						}
						newSchedule[k] = new Process(schedule[i].getName(),schedule[i].getTime());
						k++;
					}
					schedule = newSchedule;
					len = schedule.length;
					j = 0;
				}
				if(j >= len){
					j %= len;
				}
				a = schedule[j].getTime();
				if(a == 0){
					j++;
					continue;
				}else if(a <= sTime){
					sumTime += a;
					System.out.println(schedule[j].getName() + " " + sumTime);
					schedule[j++].setTime(0);
					count--;
					continue;
				}
				sumTime += sTime;
				schedule[j++].minusTime(sTime);
			}
			for(int i = 0;i < len;i++){
				if(schedule[i].getTime() == 0){
					continue;
				}
				System.out.println(schedule[i].getName() + " " +(sumTime+schedule[i].getTime()));
				break;
			}
		}
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) while(scan.hasNext()){
			int n = scan.nextInt();
			int sTime = scan.nextInt();
			Process[] schedule = new Process[n];
			int count = n;
			int j = 0;
			int sumTime = 0;
			for(int i = 0;i < n;i++){
				schedule[i] = new Process(scan.next(),scan.nextInt());
			}
			int a = 0;
			int len = schedule.length;
			while(count > 1){
				if(count < len/2 && j == len && count > 1000){
					Process[] newSchedule = new Process[count];
					int k = 0;
					for(int i = 0;i < len;i++){
						if(schedule[i].getTime() == 0){
							continue;
						}
						newSchedule[k] = new Process(schedule[i].getName(),schedule[i].getTime());
						k++;
					}
					schedule = newSchedule;
					len = schedule.length;
					j = 0;
				}
				if(j >= len){
					j %= len;
				}
				a = schedule[j].getTime();
				if(a == 0){
					j++;
					continue;
				}else if(a <= sTime){
					sumTime += a;
					System.out.println(schedule[j].getName() + " " + sumTime);
					schedule[j++].setTime(0);
					count--;
					continue;
				}
				sumTime += sTime;
				schedule[j++].minusTime(sTime);
			}
			for(int i = 0;i < len;i++){
				if(schedule[i].getTime() == 0){
					continue;
				}
				System.out.println(schedule[i].getName() + " " +(sumTime+schedule[i].getTime()));
				break;
			}
		} scan.hasNext() scan.hasNext scan {
			int n = scan.nextInt();
			int sTime = scan.nextInt();
			Process[] schedule = new Process[n];
			int count = n;
			int j = 0;
			int sumTime = 0;
			for(int i = 0;i < n;i++){
				schedule[i] = new Process(scan.next(),scan.nextInt());
			}
			int a = 0;
			int len = schedule.length;
			while(count > 1){
				if(count < len/2 && j == len && count > 1000){
					Process[] newSchedule = new Process[count];
					int k = 0;
					for(int i = 0;i < len;i++){
						if(schedule[i].getTime() == 0){
							continue;
						}
						newSchedule[k] = new Process(schedule[i].getName(),schedule[i].getTime());
						k++;
					}
					schedule = newSchedule;
					len = schedule.length;
					j = 0;
				}
				if(j >= len){
					j %= len;
				}
				a = schedule[j].getTime();
				if(a == 0){
					j++;
					continue;
				}else if(a <= sTime){
					sumTime += a;
					System.out.println(schedule[j].getName() + " " + sumTime);
					schedule[j++].setTime(0);
					count--;
					continue;
				}
				sumTime += sTime;
				schedule[j++].minusTime(sTime);
			}
			for(int i = 0;i < len;i++){
				if(schedule[i].getTime() == 0){
					continue;
				}
				System.out.println(schedule[i].getName() + " " +(sumTime+schedule[i].getTime()));
				break;
			}
		} int n = scan.nextInt(); n scan.nextInt() scan.nextInt scan int sTime = scan.nextInt(); sTime scan.nextInt() scan.nextInt scan Process[] schedule = new Process[n]; schedule new Process[n] n int count = n; count n int j = 0; j 0 int sumTime = 0; sumTime 0 for(int i = 0;i < n;i++){
				schedule[i] = new Process(scan.next(),scan.nextInt());
			} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
				schedule[i] = new Process(scan.next(),scan.nextInt());
			} {
				schedule[i] = new Process(scan.next(),scan.nextInt());
			} schedule[i] = new Process(scan.next(),scan.nextInt()) schedule[i] schedule i new Process(scan.next(),scan.nextInt()) int a = 0; a 0 int len = schedule.length; len schedule.length schedule schedule.length while(count > 1){
				if(count < len/2 && j == len && count > 1000){
					Process[] newSchedule = new Process[count];
					int k = 0;
					for(int i = 0;i < len;i++){
						if(schedule[i].getTime() == 0){
							continue;
						}
						newSchedule[k] = new Process(schedule[i].getName(),schedule[i].getTime());
						k++;
					}
					schedule = newSchedule;
					len = schedule.length;
					j = 0;
				}
				if(j >= len){
					j %= len;
				}
				a = schedule[j].getTime();
				if(a == 0){
					j++;
					continue;
				}else if(a <= sTime){
					sumTime += a;
					System.out.println(schedule[j].getName() + " " + sumTime);
					schedule[j++].setTime(0);
					count--;
					continue;
				}
				sumTime += sTime;
				schedule[j++].minusTime(sTime);
			} count > 1 count 1 {
				if(count < len/2 && j == len && count > 1000){
					Process[] newSchedule = new Process[count];
					int k = 0;
					for(int i = 0;i < len;i++){
						if(schedule[i].getTime() == 0){
							continue;
						}
						newSchedule[k] = new Process(schedule[i].getName(),schedule[i].getTime());
						k++;
					}
					schedule = newSchedule;
					len = schedule.length;
					j = 0;
				}
				if(j >= len){
					j %= len;
				}
				a = schedule[j].getTime();
				if(a == 0){
					j++;
					continue;
				}else if(a <= sTime){
					sumTime += a;
					System.out.println(schedule[j].getName() + " " + sumTime);
					schedule[j++].setTime(0);
					count--;
					continue;
				}
				sumTime += sTime;
				schedule[j++].minusTime(sTime);
			} if(count < len/2 && j == len && count > 1000){
					Process[] newSchedule = new Process[count];
					int k = 0;
					for(int i = 0;i < len;i++){
						if(schedule[i].getTime() == 0){
							continue;
						}
						newSchedule[k] = new Process(schedule[i].getName(),schedule[i].getTime());
						k++;
					}
					schedule = newSchedule;
					len = schedule.length;
					j = 0;
				} count < len/2 && j == len && count > 1000 count < len/2 && j == len && count > 1000 count < len/2 count len/2 len 2 j == len j len count > 1000 count 1000 {
					Process[] newSchedule = new Process[count];
					int k = 0;
					for(int i = 0;i < len;i++){
						if(schedule[i].getTime() == 0){
							continue;
						}
						newSchedule[k] = new Process(schedule[i].getName(),schedule[i].getTime());
						k++;
					}
					schedule = newSchedule;
					len = schedule.length;
					j = 0;
				} Process[] newSchedule = new Process[count]; newSchedule new Process[count] count int k = 0; k 0 for(int i = 0;i < len;i++){
						if(schedule[i].getTime() == 0){
							continue;
						}
						newSchedule[k] = new Process(schedule[i].getName(),schedule[i].getTime());
						k++;
					} int i = 0; int i = 0; i 0 i < len i len i++ i++ i {
						if(schedule[i].getTime() == 0){
							continue;
						}
						newSchedule[k] = new Process(schedule[i].getName(),schedule[i].getTime());
						k++;
					} {
						if(schedule[i].getTime() == 0){
							continue;
						}
						newSchedule[k] = new Process(schedule[i].getName(),schedule[i].getTime());
						k++;
					} if(schedule[i].getTime() == 0){
							continue;
						} schedule[i].getTime() == 0 schedule[i].getTime() schedule[i].getTime schedule[i] schedule i 0 {
							continue;
						} continue; newSchedule[k] = new Process(schedule[i].getName(),schedule[i].getTime()) newSchedule[k] newSchedule k new Process(schedule[i].getName(),schedule[i].getTime()) k++ k schedule = newSchedule schedule newSchedule len = schedule.length len schedule.length schedule schedule.length j = 0 j 0 if(j >= len){
					j %= len;
				} j >= len j len {
					j %= len;
				} j %= len j len a = schedule[j].getTime() a schedule[j].getTime() schedule[j].getTime schedule[j] schedule j if(a == 0){
					j++;
					continue;
				}else if(a <= sTime){
					sumTime += a;
					System.out.println(schedule[j].getName() + " " + sumTime);
					schedule[j++].setTime(0);
					count--;
					continue;
				} a == 0 a 0 {
					j++;
					continue;
				} j++ j continue; if(a <= sTime){
					sumTime += a;
					System.out.println(schedule[j].getName() + " " + sumTime);
					schedule[j++].setTime(0);
					count--;
					continue;
				} a <= sTime a sTime {
					sumTime += a;
					System.out.println(schedule[j].getName() + " " + sumTime);
					schedule[j++].setTime(0);
					count--;
					continue;
				} sumTime += a sumTime a System.out.println(schedule[j].getName() + " " + sumTime) System.out.println System.out System System.out schedule[j].getName() + " " + sumTime schedule[j].getName() + " " + sumTime schedule[j].getName() schedule[j].getName schedule[j] schedule j " " sumTime schedule[j++].setTime(0) schedule[j++].setTime schedule[j++] schedule j++ j 0 count-- count continue; sumTime += sTime sumTime sTime schedule[j++].minusTime(sTime) schedule[j++].minusTime schedule[j++] schedule j++ j sTime for(int i = 0;i < len;i++){
				if(schedule[i].getTime() == 0){
					continue;
				}
				System.out.println(schedule[i].getName() + " " +(sumTime+schedule[i].getTime()));
				break;
			} int i = 0; int i = 0; i 0 i < len i len i++ i++ i {
				if(schedule[i].getTime() == 0){
					continue;
				}
				System.out.println(schedule[i].getName() + " " +(sumTime+schedule[i].getTime()));
				break;
			} {
				if(schedule[i].getTime() == 0){
					continue;
				}
				System.out.println(schedule[i].getName() + " " +(sumTime+schedule[i].getTime()));
				break;
			} if(schedule[i].getTime() == 0){
					continue;
				} schedule[i].getTime() == 0 schedule[i].getTime() schedule[i].getTime schedule[i] schedule i 0 {
					continue;
				} continue; System.out.println(schedule[i].getName() + " " +(sumTime+schedule[i].getTime())) System.out.println System.out System System.out schedule[i].getName() + " " +(sumTime+schedule[i].getTime()) schedule[i].getName() + " " +(sumTime+schedule[i].getTime()) schedule[i].getName() schedule[i].getName schedule[i] schedule i " " (sumTime+schedule[i].getTime()) sumTime schedule[i].getTime() schedule[i].getTime schedule[i] schedule i break; class Process{
		String name;
		int time;
		public Process(){
		}
		public Process(String name,int time){
			this.name = name;
			this.time = time;
		}
		public int getTime(){
			return this.time;
		}
		public void setTime(int time){
			this.time = time;
		}
		public String getName(){
			return this.name;
		}
		public void minusTime(int time){
			this.time -= time;
		}
		public void setName(String name){
			this.name = name;
		}
	} Process String name; name int time; time public Process(){
		} Process {
		} public Process(String name,int time){
			this.name = name;
			this.time = time;
		} Process {
			this.name = name;
			this.time = time;
		} this.name = name this.name this this.name name this.time = time this.time this this.time time String name name int time time public int getTime(){
			return this.time;
		} getTime {
			return this.time;
		} return this.time; this.time this this.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 this.name;
		} getName {
			return this.name;
		} return this.name; this.name this this.name public void minusTime(int time){
			this.time -= time;
		} minusTime {
			this.time -= time;
		} this.time -= time this.time this this.time time int time time 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 class Main{
	public static void main(String[] args){
		new Main().run();
	}
	public void run(){
		Scanner scan = new Scanner(System.in);
		while(scan.hasNext()){
			int n = scan.nextInt();
			int sTime = scan.nextInt();
			Process[] schedule = new Process[n];
			int count = n;
			int j = 0;
			int sumTime = 0;
			for(int i = 0;i < n;i++){
				schedule[i] = new Process(scan.next(),scan.nextInt());
			}
			int a = 0;
			int len = schedule.length;
			while(count > 1){
				if(count < len/2 && j == len && count > 1000){
					Process[] newSchedule = new Process[count];
					int k = 0;
					for(int i = 0;i < len;i++){
						if(schedule[i].getTime() == 0){
							continue;
						}
						newSchedule[k] = new Process(schedule[i].getName(),schedule[i].getTime());
						k++;
					}
					schedule = newSchedule;
					len = schedule.length;
					j = 0;
				}
				if(j >= len){
					j %= len;
				}
				a = schedule[j].getTime();
				if(a == 0){
					j++;
					continue;
				}else if(a <= sTime){
					sumTime += a;
					System.out.println(schedule[j].getName() + " " + sumTime);
					schedule[j++].setTime(0);
					count--;
					continue;
				}
				sumTime += sTime;
				schedule[j++].minusTime(sTime);
			}
			for(int i = 0;i < len;i++){
				if(schedule[i].getTime() == 0){
					continue;
				}
				System.out.println(schedule[i].getName() + " " +(sumTime+schedule[i].getTime()));
				break;
			}
		}
	}
	class Process{
		String name;
		int time;
		public Process(){
		}
		public Process(String name,int time){
			this.name = name;
			this.time = time;
		}
		public int getTime(){
			return this.time;
		}
		public void setTime(int time){
			this.time = time;
		}
		public String getName(){
			return this.name;
		}
		public void minusTime(int time){
			this.time -= time;
		}
		public void setName(String name){
			this.name = name;
		}
	}
} public class Main{
	public static void main(String[] args){
		new Main().run();
	}
	public void run(){
		Scanner scan = new Scanner(System.in);
		while(scan.hasNext()){
			int n = scan.nextInt();
			int sTime = scan.nextInt();
			Process[] schedule = new Process[n];
			int count = n;
			int j = 0;
			int sumTime = 0;
			for(int i = 0;i < n;i++){
				schedule[i] = new Process(scan.next(),scan.nextInt());
			}
			int a = 0;
			int len = schedule.length;
			while(count > 1){
				if(count < len/2 && j == len && count > 1000){
					Process[] newSchedule = new Process[count];
					int k = 0;
					for(int i = 0;i < len;i++){
						if(schedule[i].getTime() == 0){
							continue;
						}
						newSchedule[k] = new Process(schedule[i].getName(),schedule[i].getTime());
						k++;
					}
					schedule = newSchedule;
					len = schedule.length;
					j = 0;
				}
				if(j >= len){
					j %= len;
				}
				a = schedule[j].getTime();
				if(a == 0){
					j++;
					continue;
				}else if(a <= sTime){
					sumTime += a;
					System.out.println(schedule[j].getName() + " " + sumTime);
					schedule[j++].setTime(0);
					count--;
					continue;
				}
				sumTime += sTime;
				schedule[j++].minusTime(sTime);
			}
			for(int i = 0;i < len;i++){
				if(schedule[i].getTime() == 0){
					continue;
				}
				System.out.println(schedule[i].getName() + " " +(sumTime+schedule[i].getTime()));
				break;
			}
		}
	}
	class Process{
		String name;
		int time;
		public Process(){
		}
		public Process(String name,int time){
			this.name = name;
			this.time = time;
		}
		public int getTime(){
			return this.time;
		}
		public void setTime(int time){
			this.time = time;
		}
		public String getName(){
			return this.name;
		}
		public void minusTime(int time){
			this.time -= time;
		}
		public void setName(String name){
			this.name = name;
		}
	}
} Main
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		new Main().run();
	}
	public void run(){
		Scanner scan = new Scanner(System.in);
		while(scan.hasNext()){
			int n = scan.nextInt();
			int sTime = scan.nextInt();
			Process[] schedule = new Process[n];
			int count = n;
			int j = 0;
			int sumTime = 0;
			for(int i = 0;i < n;i++){
				schedule[i] = new Process(scan.next(),scan.nextInt());
			}
			int a = 0;
			int len = schedule.length;
			while(count > 1){
				if(count < len/2 && j == len && count > 1000){
					Process[] newSchedule = new Process[count];
					int k = 0;
					for(int i = 0;i < len;i++){
						if(schedule[i].getTime() == 0){
							continue;
						}
						newSchedule[k] = new Process(schedule[i].getName(),schedule[i].getTime());
						k++;
					}
					schedule = newSchedule;
					len = schedule.length;
					j = 0;
				}
				if(j >= len){
					j %= len;
				}
				a = schedule[j].getTime();
				if(a == 0){
					j++;
					continue;
				}else if(a <= sTime){
					sumTime += a;
					System.out.println(schedule[j].getName() + " " + sumTime);
					schedule[j++].setTime(0);
					count--;
					continue;
				}
				sumTime += sTime;
				schedule[j++].minusTime(sTime);
			}
			for(int i = 0;i < len;i++){
				if(schedule[i].getTime() == 0){
					continue;
				}
				System.out.println(schedule[i].getName() + " " +(sumTime+schedule[i].getTime()));
				break;
			}
		}
	}
	class Process{
		String name;
		int time;
		public Process(){
		}
		public Process(String name,int time){
			this.name = name;
			this.time = time;
		}
		public int getTime(){
			return this.time;
		}
		public void setTime(int time){
			this.time = time;
		}
		public String getName(){
			return this.name;
		}
		public void minusTime(int time){
			this.time -= time;
		}
		public void setName(String name){
			this.name = name;
		}
	}
}