
import java.util.LinkedList; 
import java.util.Queue;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Queue<String> qu = new LinkedList<>();
		Scanner scan = new Scanner(System.in);

		int amt = scan.nextInt();
		int quant = scan.nextInt();
		
		for(int i=0; i<amt; i++){
			qu.add(scan.next() + " " + scan.next());
			
		}
		
		int timer = 0;
		int q = quant;
		int i=0;
		String[] results = new String[amt];
		while(qu.size() > 0) {
			String[] temparr = qu.peek().split("\\s+");
			String name = temparr[0];
			int num = Integer.parseInt(temparr[1]);
			if(q>num) {
				timer += num;
				//q= q-num;
				num=0;

			} else if(num>q){
				timer += q;
				num = num - q;
				q=0;

			} else {

				timer += q;
				num=0;
				q=0;

			}

			if(num==0 && qu.size() > 0 && q==0) {
				results[i]=name + " " + timer;
				i++;
				q = quant;
				qu.remove();
			} else
			if(num==0 && qu.size() > 0) {
				results[i]= name + " " + timer;
				i++;
				qu.remove();

			} else
			if(q==0 && qu.size() > 0) {
				q = quant;
				qu.remove();
				qu.add(name + " " + num);
			}
			
		}
		for(int j=0; j<results.length;j++) {
			System.out.println(results[j]);
		}
		
	}
	
}
 import java.util.LinkedList; LinkedList java.util import java.util.Queue; Queue java.util import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {

		Queue<String> qu = new LinkedList<>();
		Scanner scan = new Scanner(System.in);

		int amt = scan.nextInt();
		int quant = scan.nextInt();
		
		for(int i=0; i<amt; i++){
			qu.add(scan.next() + " " + scan.next());
			
		}
		
		int timer = 0;
		int q = quant;
		int i=0;
		String[] results = new String[amt];
		while(qu.size() > 0) {
			String[] temparr = qu.peek().split("\\s+");
			String name = temparr[0];
			int num = Integer.parseInt(temparr[1]);
			if(q>num) {
				timer += num;
				//q= q-num;
				num=0;

			} else if(num>q){
				timer += q;
				num = num - q;
				q=0;

			} else {

				timer += q;
				num=0;
				q=0;

			}

			if(num==0 && qu.size() > 0 && q==0) {
				results[i]=name + " " + timer;
				i++;
				q = quant;
				qu.remove();
			} else
			if(num==0 && qu.size() > 0) {
				results[i]= name + " " + timer;
				i++;
				qu.remove();

			} else
			if(q==0 && qu.size() > 0) {
				q = quant;
				qu.remove();
				qu.add(name + " " + num);
			}
			
		}
		for(int j=0; j<results.length;j++) {
			System.out.println(results[j]);
		}
		
	}
	
} Main public static void main(String[] args) {

		Queue<String> qu = new LinkedList<>();
		Scanner scan = new Scanner(System.in);

		int amt = scan.nextInt();
		int quant = scan.nextInt();
		
		for(int i=0; i<amt; i++){
			qu.add(scan.next() + " " + scan.next());
			
		}
		
		int timer = 0;
		int q = quant;
		int i=0;
		String[] results = new String[amt];
		while(qu.size() > 0) {
			String[] temparr = qu.peek().split("\\s+");
			String name = temparr[0];
			int num = Integer.parseInt(temparr[1]);
			if(q>num) {
				timer += num;
				//q= q-num;
				num=0;

			} else if(num>q){
				timer += q;
				num = num - q;
				q=0;

			} else {

				timer += q;
				num=0;
				q=0;

			}

			if(num==0 && qu.size() > 0 && q==0) {
				results[i]=name + " " + timer;
				i++;
				q = quant;
				qu.remove();
			} else
			if(num==0 && qu.size() > 0) {
				results[i]= name + " " + timer;
				i++;
				qu.remove();

			} else
			if(q==0 && qu.size() > 0) {
				q = quant;
				qu.remove();
				qu.add(name + " " + num);
			}
			
		}
		for(int j=0; j<results.length;j++) {
			System.out.println(results[j]);
		}
		
	} main {

		Queue<String> qu = new LinkedList<>();
		Scanner scan = new Scanner(System.in);

		int amt = scan.nextInt();
		int quant = scan.nextInt();
		
		for(int i=0; i<amt; i++){
			qu.add(scan.next() + " " + scan.next());
			
		}
		
		int timer = 0;
		int q = quant;
		int i=0;
		String[] results = new String[amt];
		while(qu.size() > 0) {
			String[] temparr = qu.peek().split("\\s+");
			String name = temparr[0];
			int num = Integer.parseInt(temparr[1]);
			if(q>num) {
				timer += num;
				//q= q-num;
				num=0;

			} else if(num>q){
				timer += q;
				num = num - q;
				q=0;

			} else {

				timer += q;
				num=0;
				q=0;

			}

			if(num==0 && qu.size() > 0 && q==0) {
				results[i]=name + " " + timer;
				i++;
				q = quant;
				qu.remove();
			} else
			if(num==0 && qu.size() > 0) {
				results[i]= name + " " + timer;
				i++;
				qu.remove();

			} else
			if(q==0 && qu.size() > 0) {
				q = quant;
				qu.remove();
				qu.add(name + " " + num);
			}
			
		}
		for(int j=0; j<results.length;j++) {
			System.out.println(results[j]);
		}
		
	} Queue<String> qu = new LinkedList<>(); qu new LinkedList<>() Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int amt = scan.nextInt(); amt scan.nextInt() scan.nextInt scan int quant = scan.nextInt(); quant scan.nextInt() scan.nextInt scan for(int i=0; i<amt; i++){
			qu.add(scan.next() + " " + scan.next());
			
		} int i=0; int i=0; i 0 i<amt i amt i++ i++ i {
			qu.add(scan.next() + " " + scan.next());
			
		} {
			qu.add(scan.next() + " " + scan.next());
			
		} qu.add(scan.next() + " " + scan.next()) qu.add qu scan.next() + " " + scan.next() scan.next() + " " + scan.next() scan.next() scan.next scan " " scan.next() scan.next scan int timer = 0; timer 0 int q = quant; q quant int i=0; i 0 String[] results = new String[amt]; results new String[amt] amt while(qu.size() > 0) {
			String[] temparr = qu.peek().split("\\s+");
			String name = temparr[0];
			int num = Integer.parseInt(temparr[1]);
			if(q>num) {
				timer += num;
				//q= q-num;
				num=0;

			} else if(num>q){
				timer += q;
				num = num - q;
				q=0;

			} else {

				timer += q;
				num=0;
				q=0;

			}

			if(num==0 && qu.size() > 0 && q==0) {
				results[i]=name + " " + timer;
				i++;
				q = quant;
				qu.remove();
			} else
			if(num==0 && qu.size() > 0) {
				results[i]= name + " " + timer;
				i++;
				qu.remove();

			} else
			if(q==0 && qu.size() > 0) {
				q = quant;
				qu.remove();
				qu.add(name + " " + num);
			}
			
		} qu.size() > 0 qu.size() qu.size qu 0 {
			String[] temparr = qu.peek().split("\\s+");
			String name = temparr[0];
			int num = Integer.parseInt(temparr[1]);
			if(q>num) {
				timer += num;
				//q= q-num;
				num=0;

			} else if(num>q){
				timer += q;
				num = num - q;
				q=0;

			} else {

				timer += q;
				num=0;
				q=0;

			}

			if(num==0 && qu.size() > 0 && q==0) {
				results[i]=name + " " + timer;
				i++;
				q = quant;
				qu.remove();
			} else
			if(num==0 && qu.size() > 0) {
				results[i]= name + " " + timer;
				i++;
				qu.remove();

			} else
			if(q==0 && qu.size() > 0) {
				q = quant;
				qu.remove();
				qu.add(name + " " + num);
			}
			
		} String[] temparr = qu.peek().split("\\s+"); temparr qu.peek().split("\\s+") qu.peek().split qu.peek() qu.peek qu "\\s+" String name = temparr[0]; name temparr[0] temparr 0 int num = Integer.parseInt(temparr[1]); num Integer.parseInt(temparr[1]) Integer.parseInt Integer temparr[1] temparr 1 if(q>num) {
				timer += num;
				//q= q-num;
				num=0;

			} else if(num>q){
				timer += q;
				num = num - q;
				q=0;

			} else {

				timer += q;
				num=0;
				q=0;

			} q>num q num {
				timer += num;
				//q= q-num;
				num=0;

			} timer += num timer num num=0 num 0 if(num>q){
				timer += q;
				num = num - q;
				q=0;

			} else {

				timer += q;
				num=0;
				q=0;

			} num>q num q {
				timer += q;
				num = num - q;
				q=0;

			} timer += q timer q num = num - q num num - q num q q=0 q 0 {

				timer += q;
				num=0;
				q=0;

			} timer += q timer q num=0 num 0 q=0 q 0 if(num==0 && qu.size() > 0 && q==0) {
				results[i]=name + " " + timer;
				i++;
				q = quant;
				qu.remove();
			} else
			if(num==0 && qu.size() > 0) {
				results[i]= name + " " + timer;
				i++;
				qu.remove();

			} else
			if(q==0 && qu.size() > 0) {
				q = quant;
				qu.remove();
				qu.add(name + " " + num);
			} num==0 && qu.size() > 0 && q==0 num==0 && qu.size() > 0 && q==0 num==0 num 0 qu.size() > 0 qu.size() qu.size qu 0 q==0 q 0 {
				results[i]=name + " " + timer;
				i++;
				q = quant;
				qu.remove();
			} results[i]=name + " " + timer results[i] results i name + " " + timer name + " " + timer name " " timer i++ i q = quant q quant qu.remove() qu.remove qu if(num==0 && qu.size() > 0) {
				results[i]= name + " " + timer;
				i++;
				qu.remove();

			} else
			if(q==0 && qu.size() > 0) {
				q = quant;
				qu.remove();
				qu.add(name + " " + num);
			} num==0 && qu.size() > 0 num==0 num 0 qu.size() > 0 qu.size() qu.size qu 0 {
				results[i]= name + " " + timer;
				i++;
				qu.remove();

			} results[i]= name + " " + timer results[i] results i name + " " + timer name + " " + timer name " " timer i++ i qu.remove() qu.remove qu if(q==0 && qu.size() > 0) {
				q = quant;
				qu.remove();
				qu.add(name + " " + num);
			} q==0 && qu.size() > 0 q==0 q 0 qu.size() > 0 qu.size() qu.size qu 0 {
				q = quant;
				qu.remove();
				qu.add(name + " " + num);
			} q = quant q quant qu.remove() qu.remove qu qu.add(name + " " + num) qu.add qu name + " " + num name + " " + num name " " num for(int j=0; j<results.length;j++) {
			System.out.println(results[j]);
		} int j=0; int j=0; j 0 j<results.length j results.length results results.length j++ j++ j {
			System.out.println(results[j]);
		} {
			System.out.println(results[j]);
		} System.out.println(results[j]) System.out.println System.out System System.out results[j] results j String[] args args public class Main {
	public static void main(String[] args) {

		Queue<String> qu = new LinkedList<>();
		Scanner scan = new Scanner(System.in);

		int amt = scan.nextInt();
		int quant = scan.nextInt();
		
		for(int i=0; i<amt; i++){
			qu.add(scan.next() + " " + scan.next());
			
		}
		
		int timer = 0;
		int q = quant;
		int i=0;
		String[] results = new String[amt];
		while(qu.size() > 0) {
			String[] temparr = qu.peek().split("\\s+");
			String name = temparr[0];
			int num = Integer.parseInt(temparr[1]);
			if(q>num) {
				timer += num;
				//q= q-num;
				num=0;

			} else if(num>q){
				timer += q;
				num = num - q;
				q=0;

			} else {

				timer += q;
				num=0;
				q=0;

			}

			if(num==0 && qu.size() > 0 && q==0) {
				results[i]=name + " " + timer;
				i++;
				q = quant;
				qu.remove();
			} else
			if(num==0 && qu.size() > 0) {
				results[i]= name + " " + timer;
				i++;
				qu.remove();

			} else
			if(q==0 && qu.size() > 0) {
				q = quant;
				qu.remove();
				qu.add(name + " " + num);
			}
			
		}
		for(int j=0; j<results.length;j++) {
			System.out.println(results[j]);
		}
		
	}
	
} public class Main {
	public static void main(String[] args) {

		Queue<String> qu = new LinkedList<>();
		Scanner scan = new Scanner(System.in);

		int amt = scan.nextInt();
		int quant = scan.nextInt();
		
		for(int i=0; i<amt; i++){
			qu.add(scan.next() + " " + scan.next());
			
		}
		
		int timer = 0;
		int q = quant;
		int i=0;
		String[] results = new String[amt];
		while(qu.size() > 0) {
			String[] temparr = qu.peek().split("\\s+");
			String name = temparr[0];
			int num = Integer.parseInt(temparr[1]);
			if(q>num) {
				timer += num;
				//q= q-num;
				num=0;

			} else if(num>q){
				timer += q;
				num = num - q;
				q=0;

			} else {

				timer += q;
				num=0;
				q=0;

			}

			if(num==0 && qu.size() > 0 && q==0) {
				results[i]=name + " " + timer;
				i++;
				q = quant;
				qu.remove();
			} else
			if(num==0 && qu.size() > 0) {
				results[i]= name + " " + timer;
				i++;
				qu.remove();

			} else
			if(q==0 && qu.size() > 0) {
				q = quant;
				qu.remove();
				qu.add(name + " " + num);
			}
			
		}
		for(int j=0; j<results.length;j++) {
			System.out.println(results[j]);
		}
		
	}
	
} Main

import java.util.LinkedList; 
import java.util.Queue;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Queue<String> qu = new LinkedList<>();
		Scanner scan = new Scanner(System.in);

		int amt = scan.nextInt();
		int quant = scan.nextInt();
		
		for(int i=0; i<amt; i++){
			qu.add(scan.next() + " " + scan.next());
			
		}
		
		int timer = 0;
		int q = quant;
		int i=0;
		String[] results = new String[amt];
		while(qu.size() > 0) {
			String[] temparr = qu.peek().split("\\s+");
			String name = temparr[0];
			int num = Integer.parseInt(temparr[1]);
			if(q>num) {
				timer += num;
				//q= q-num;
				num=0;

			} else if(num>q){
				timer += q;
				num = num - q;
				q=0;

			} else {

				timer += q;
				num=0;
				q=0;

			}

			if(num==0 && qu.size() > 0 && q==0) {
				results[i]=name + " " + timer;
				i++;
				q = quant;
				qu.remove();
			} else
			if(num==0 && qu.size() > 0) {
				results[i]= name + " " + timer;
				i++;
				qu.remove();

			} else
			if(q==0 && qu.size() > 0) {
				q = quant;
				qu.remove();
				qu.add(name + " " + num);
			}
			
		}
		for(int j=0; j<results.length;j++) {
			System.out.println(results[j]);
		}
		
	}
	
}

