
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;



public class Main {

	public static void main(String[] args) {
		Scanner sc  = new Scanner(System.in);
		int n = sc.nextInt();
		int q = sc.nextInt();
		List<List<String>> list = new ArrayList <>();
		for(int i = 0; i < n; i++) {
			list.add(new ArrayList<>());
			list.get(i).add(sc.next());
			list.get(i).add(sc.next());
		}
		int sum = 0;
		while(list.size() > 0) {
			int time = Integer.parseInt(list.get(0).get(1));
			if(time <= q) {
				sum += time;
				System.out.println(list.get(0).get(0) + " " + sum);
				list.remove(0);
			} else {
				sum += q;
				list.add(list.get(0));
				list.get(list.size() - 1).set(1, Integer.toString(time - q));
				list.remove(0);
			}
		}
		sc.close();
	}

}
 import java.util.ArrayList; ArrayList java.util import java.util.List; List java.util import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		Scanner sc  = new Scanner(System.in);
		int n = sc.nextInt();
		int q = sc.nextInt();
		List<List<String>> list = new ArrayList <>();
		for(int i = 0; i < n; i++) {
			list.add(new ArrayList<>());
			list.get(i).add(sc.next());
			list.get(i).add(sc.next());
		}
		int sum = 0;
		while(list.size() > 0) {
			int time = Integer.parseInt(list.get(0).get(1));
			if(time <= q) {
				sum += time;
				System.out.println(list.get(0).get(0) + " " + sum);
				list.remove(0);
			} else {
				sum += q;
				list.add(list.get(0));
				list.get(list.size() - 1).set(1, Integer.toString(time - q));
				list.remove(0);
			}
		}
		sc.close();
	}

} Main public static void main(String[] args) {
		Scanner sc  = new Scanner(System.in);
		int n = sc.nextInt();
		int q = sc.nextInt();
		List<List<String>> list = new ArrayList <>();
		for(int i = 0; i < n; i++) {
			list.add(new ArrayList<>());
			list.get(i).add(sc.next());
			list.get(i).add(sc.next());
		}
		int sum = 0;
		while(list.size() > 0) {
			int time = Integer.parseInt(list.get(0).get(1));
			if(time <= q) {
				sum += time;
				System.out.println(list.get(0).get(0) + " " + sum);
				list.remove(0);
			} else {
				sum += q;
				list.add(list.get(0));
				list.get(list.size() - 1).set(1, Integer.toString(time - q));
				list.remove(0);
			}
		}
		sc.close();
	} main {
		Scanner sc  = new Scanner(System.in);
		int n = sc.nextInt();
		int q = sc.nextInt();
		List<List<String>> list = new ArrayList <>();
		for(int i = 0; i < n; i++) {
			list.add(new ArrayList<>());
			list.get(i).add(sc.next());
			list.get(i).add(sc.next());
		}
		int sum = 0;
		while(list.size() > 0) {
			int time = Integer.parseInt(list.get(0).get(1));
			if(time <= q) {
				sum += time;
				System.out.println(list.get(0).get(0) + " " + sum);
				list.remove(0);
			} else {
				sum += q;
				list.add(list.get(0));
				list.get(list.size() - 1).set(1, Integer.toString(time - q));
				list.remove(0);
			}
		}
		sc.close();
	} Scanner sc  = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int q = sc.nextInt(); q sc.nextInt() sc.nextInt sc List<List<String>> list = new ArrayList <>(); list new ArrayList <>() for(int i = 0; i < n; i++) {
			list.add(new ArrayList<>());
			list.get(i).add(sc.next());
			list.get(i).add(sc.next());
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			list.add(new ArrayList<>());
			list.get(i).add(sc.next());
			list.get(i).add(sc.next());
		} {
			list.add(new ArrayList<>());
			list.get(i).add(sc.next());
			list.get(i).add(sc.next());
		} list.add(new ArrayList<>()) list.add list new ArrayList<>() list.get(i).add(sc.next()) list.get(i).add list.get(i) list.get list i sc.next() sc.next sc list.get(i).add(sc.next()) list.get(i).add list.get(i) list.get list i sc.next() sc.next sc int sum = 0; sum 0 while(list.size() > 0) {
			int time = Integer.parseInt(list.get(0).get(1));
			if(time <= q) {
				sum += time;
				System.out.println(list.get(0).get(0) + " " + sum);
				list.remove(0);
			} else {
				sum += q;
				list.add(list.get(0));
				list.get(list.size() - 1).set(1, Integer.toString(time - q));
				list.remove(0);
			}
		} list.size() > 0 list.size() list.size list 0 {
			int time = Integer.parseInt(list.get(0).get(1));
			if(time <= q) {
				sum += time;
				System.out.println(list.get(0).get(0) + " " + sum);
				list.remove(0);
			} else {
				sum += q;
				list.add(list.get(0));
				list.get(list.size() - 1).set(1, Integer.toString(time - q));
				list.remove(0);
			}
		} int time = Integer.parseInt(list.get(0).get(1)); time Integer.parseInt(list.get(0).get(1)) Integer.parseInt Integer list.get(0).get(1) list.get(0).get list.get(0) list.get list 0 1 if(time <= q) {
				sum += time;
				System.out.println(list.get(0).get(0) + " " + sum);
				list.remove(0);
			} else {
				sum += q;
				list.add(list.get(0));
				list.get(list.size() - 1).set(1, Integer.toString(time - q));
				list.remove(0);
			} time <= q time q {
				sum += time;
				System.out.println(list.get(0).get(0) + " " + sum);
				list.remove(0);
			} sum += time sum time System.out.println(list.get(0).get(0) + " " + sum) System.out.println System.out System System.out list.get(0).get(0) + " " + sum list.get(0).get(0) + " " + sum list.get(0).get(0) list.get(0).get list.get(0) list.get list 0 0 " " sum list.remove(0) list.remove list 0 {
				sum += q;
				list.add(list.get(0));
				list.get(list.size() - 1).set(1, Integer.toString(time - q));
				list.remove(0);
			} sum += q sum q list.add(list.get(0)) list.add list list.get(0) list.get list 0 list.get(list.size() - 1).set(1, Integer.toString(time - q)) list.get(list.size() - 1).set list.get(list.size() - 1) list.get list list.size() - 1 list.size() list.size list 1 1 Integer.toString(time - q) Integer.toString Integer time - q time q list.remove(0) list.remove list 0 sc.close() sc.close sc String[] args args public class Main {

	public static void main(String[] args) {
		Scanner sc  = new Scanner(System.in);
		int n = sc.nextInt();
		int q = sc.nextInt();
		List<List<String>> list = new ArrayList <>();
		for(int i = 0; i < n; i++) {
			list.add(new ArrayList<>());
			list.get(i).add(sc.next());
			list.get(i).add(sc.next());
		}
		int sum = 0;
		while(list.size() > 0) {
			int time = Integer.parseInt(list.get(0).get(1));
			if(time <= q) {
				sum += time;
				System.out.println(list.get(0).get(0) + " " + sum);
				list.remove(0);
			} else {
				sum += q;
				list.add(list.get(0));
				list.get(list.size() - 1).set(1, Integer.toString(time - q));
				list.remove(0);
			}
		}
		sc.close();
	}

} public class Main {

	public static void main(String[] args) {
		Scanner sc  = new Scanner(System.in);
		int n = sc.nextInt();
		int q = sc.nextInt();
		List<List<String>> list = new ArrayList <>();
		for(int i = 0; i < n; i++) {
			list.add(new ArrayList<>());
			list.get(i).add(sc.next());
			list.get(i).add(sc.next());
		}
		int sum = 0;
		while(list.size() > 0) {
			int time = Integer.parseInt(list.get(0).get(1));
			if(time <= q) {
				sum += time;
				System.out.println(list.get(0).get(0) + " " + sum);
				list.remove(0);
			} else {
				sum += q;
				list.add(list.get(0));
				list.get(list.size() - 1).set(1, Integer.toString(time - q));
				list.remove(0);
			}
		}
		sc.close();
	}

} Main

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;



public class Main {

	public static void main(String[] args) {
		Scanner sc  = new Scanner(System.in);
		int n = sc.nextInt();
		int q = sc.nextInt();
		List<List<String>> list = new ArrayList <>();
		for(int i = 0; i < n; i++) {
			list.add(new ArrayList<>());
			list.get(i).add(sc.next());
			list.get(i).add(sc.next());
		}
		int sum = 0;
		while(list.size() > 0) {
			int time = Integer.parseInt(list.get(0).get(1));
			if(time <= q) {
				sum += time;
				System.out.println(list.get(0).get(0) + " " + sum);
				list.remove(0);
			} else {
				sum += q;
				list.add(list.get(0));
				list.get(list.size() - 1).set(1, Integer.toString(time - q));
				list.remove(0);
			}
		}
		sc.close();
	}

}

