import java.io.File;
import java.io.FileNotFoundException;
import java.lang.management.ManagementFactory;
import java.lang.management.ThreadMXBean;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws FileNotFoundException {

		Scanner scan = new Scanner(System.in);
		// Scanner scan = new Scanner(new
		// File("D:\\UserArea\\J0124567\\Downloads\\2010-input.txt"));

		while (scan.hasNext()) {
			int n = scan.nextInt();
			int q = scan.nextInt();

			Qu qu = new Qu(n);
			for (int i = 0; i < n; i++) {
				qu.add(scan.next(), scan.nextInt());
			}
			while (qu.process(q))
				;
		}

		scan.close();
		System.exit(0);
	}
}

class Qu {
	class Proc {
		public Proc(String _name, int _time) {
			name = new String(_name);
			time = _time;
		}

		String name;
		int time;
	}

	List<Proc> proc = new ArrayList<Proc>();
	int pt = 0;
	int total = 0;

	public Qu(int n) {
	}

	public boolean process(int q) {
		if (proc.get(pt).time <= q) {
			total += proc.get(pt).time;
			System.out.println(proc.get(pt).name + " " + total);
			proc.remove(pt);
			if (proc.size() == 0)
				return false;
		} else {
			total += q;
			proc.get(pt).time -= q;
			pt++;
		}
		if (pt == proc.size())
			pt = 0;
		return true;
	}

	public void add(String _name, int _time) {
		proc.add(new Proc(_name, _time));
	}

} import java.io.File; File java.io import java.io.FileNotFoundException; FileNotFoundException java.io import java.lang.management.ManagementFactory; ManagementFactory java.lang.management import java.lang.management.ThreadMXBean; ThreadMXBean java.lang.management import java.util.ArrayList; ArrayList java.util import java.util.Collections; Collections java.util import java.util.Comparator; Comparator java.util import java.util.List; List java.util import java.util.PriorityQueue; PriorityQueue java.util import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) throws FileNotFoundException {

		Scanner scan = new Scanner(System.in);
		// Scanner scan = new Scanner(new
		// File("D:\\UserArea\\J0124567\\Downloads\\2010-input.txt"));

		while (scan.hasNext()) {
			int n = scan.nextInt();
			int q = scan.nextInt();

			Qu qu = new Qu(n);
			for (int i = 0; i < n; i++) {
				qu.add(scan.next(), scan.nextInt());
			}
			while (qu.process(q))
				;
		}

		scan.close();
		System.exit(0);
	}
} Main public static void main(String[] args) throws FileNotFoundException {

		Scanner scan = new Scanner(System.in);
		// Scanner scan = new Scanner(new
		// File("D:\\UserArea\\J0124567\\Downloads\\2010-input.txt"));

		while (scan.hasNext()) {
			int n = scan.nextInt();
			int q = scan.nextInt();

			Qu qu = new Qu(n);
			for (int i = 0; i < n; i++) {
				qu.add(scan.next(), scan.nextInt());
			}
			while (qu.process(q))
				;
		}

		scan.close();
		System.exit(0);
	} main {

		Scanner scan = new Scanner(System.in);
		// Scanner scan = new Scanner(new
		// File("D:\\UserArea\\J0124567\\Downloads\\2010-input.txt"));

		while (scan.hasNext()) {
			int n = scan.nextInt();
			int q = scan.nextInt();

			Qu qu = new Qu(n);
			for (int i = 0; i < n; i++) {
				qu.add(scan.next(), scan.nextInt());
			}
			while (qu.process(q))
				;
		}

		scan.close();
		System.exit(0);
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) while (scan.hasNext()) {
			int n = scan.nextInt();
			int q = scan.nextInt();

			Qu qu = new Qu(n);
			for (int i = 0; i < n; i++) {
				qu.add(scan.next(), scan.nextInt());
			}
			while (qu.process(q))
				;
		} scan.hasNext() scan.hasNext scan {
			int n = scan.nextInt();
			int q = scan.nextInt();

			Qu qu = new Qu(n);
			for (int i = 0; i < n; i++) {
				qu.add(scan.next(), scan.nextInt());
			}
			while (qu.process(q))
				;
		} int n = scan.nextInt(); n scan.nextInt() scan.nextInt scan int q = scan.nextInt(); q scan.nextInt() scan.nextInt scan Qu qu = new Qu(n); qu new Qu(n) for (int i = 0; i < n; i++) {
				qu.add(scan.next(), scan.nextInt());
			} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
				qu.add(scan.next(), scan.nextInt());
			} {
				qu.add(scan.next(), scan.nextInt());
			} qu.add(scan.next(), scan.nextInt()) qu.add qu scan.next() scan.next scan scan.nextInt() scan.nextInt scan while (qu.process(q))
				; qu.process(q) qu.process qu q scan.close() scan.close scan System.exit(0) System.exit System 0 String[] args args class Qu {
	class Proc {
		public Proc(String _name, int _time) {
			name = new String(_name);
			time = _time;
		}

		String name;
		int time;
	}

	List<Proc> proc = new ArrayList<Proc>();
	int pt = 0;
	int total = 0;

	public Qu(int n) {
	}

	public boolean process(int q) {
		if (proc.get(pt).time <= q) {
			total += proc.get(pt).time;
			System.out.println(proc.get(pt).name + " " + total);
			proc.remove(pt);
			if (proc.size() == 0)
				return false;
		} else {
			total += q;
			proc.get(pt).time -= q;
			pt++;
		}
		if (pt == proc.size())
			pt = 0;
		return true;
	}

	public void add(String _name, int _time) {
		proc.add(new Proc(_name, _time));
	}

} Qu List<Proc> proc = new ArrayList<Proc>(); proc new ArrayList<Proc>() int pt = 0; pt 0 int total = 0; total 0 public Qu(int n) {
	} Qu {
	} int n n public boolean process(int q) {
		if (proc.get(pt).time <= q) {
			total += proc.get(pt).time;
			System.out.println(proc.get(pt).name + " " + total);
			proc.remove(pt);
			if (proc.size() == 0)
				return false;
		} else {
			total += q;
			proc.get(pt).time -= q;
			pt++;
		}
		if (pt == proc.size())
			pt = 0;
		return true;
	} process {
		if (proc.get(pt).time <= q) {
			total += proc.get(pt).time;
			System.out.println(proc.get(pt).name + " " + total);
			proc.remove(pt);
			if (proc.size() == 0)
				return false;
		} else {
			total += q;
			proc.get(pt).time -= q;
			pt++;
		}
		if (pt == proc.size())
			pt = 0;
		return true;
	} if (proc.get(pt).time <= q) {
			total += proc.get(pt).time;
			System.out.println(proc.get(pt).name + " " + total);
			proc.remove(pt);
			if (proc.size() == 0)
				return false;
		} else {
			total += q;
			proc.get(pt).time -= q;
			pt++;
		} proc.get(pt).time <= q proc.get(pt).time proc.get(pt) proc.get proc pt proc.get(pt).time q {
			total += proc.get(pt).time;
			System.out.println(proc.get(pt).name + " " + total);
			proc.remove(pt);
			if (proc.size() == 0)
				return false;
		} total += proc.get(pt).time total proc.get(pt).time proc.get(pt) proc.get proc pt proc.get(pt).time System.out.println(proc.get(pt).name + " " + total) System.out.println System.out System System.out proc.get(pt).name + " " + total proc.get(pt).name + " " + total proc.get(pt).name proc.get(pt) proc.get proc pt proc.get(pt).name " " total proc.remove(pt) proc.remove proc pt if (proc.size() == 0)
				return false; proc.size() == 0 proc.size() proc.size proc 0 return false; false {
			total += q;
			proc.get(pt).time -= q;
			pt++;
		} total += q total q proc.get(pt).time -= q proc.get(pt).time proc.get(pt) proc.get proc pt proc.get(pt).time q pt++ pt if (pt == proc.size())
			pt = 0; pt == proc.size() pt proc.size() proc.size proc pt = 0 pt 0 return true; true int q q public void add(String _name, int _time) {
		proc.add(new Proc(_name, _time));
	} add {
		proc.add(new Proc(_name, _time));
	} proc.add(new Proc(_name, _time)) proc.add proc new Proc(_name, _time) String _name _name int _time _time class Proc {
		public Proc(String _name, int _time) {
			name = new String(_name);
			time = _time;
		}

		String name;
		int time;
	} Proc String name; name int time; time public Proc(String _name, int _time) {
			name = new String(_name);
			time = _time;
		} Proc {
			name = new String(_name);
			time = _time;
		} name = new String(_name) name new String(_name) time = _time time _time String _name _name int _time _time public class Main {

	public static void main(String[] args) throws FileNotFoundException {

		Scanner scan = new Scanner(System.in);
		// Scanner scan = new Scanner(new
		// File("D:\\UserArea\\J0124567\\Downloads\\2010-input.txt"));

		while (scan.hasNext()) {
			int n = scan.nextInt();
			int q = scan.nextInt();

			Qu qu = new Qu(n);
			for (int i = 0; i < n; i++) {
				qu.add(scan.next(), scan.nextInt());
			}
			while (qu.process(q))
				;
		}

		scan.close();
		System.exit(0);
	}
} public class Main {

	public static void main(String[] args) throws FileNotFoundException {

		Scanner scan = new Scanner(System.in);
		// Scanner scan = new Scanner(new
		// File("D:\\UserArea\\J0124567\\Downloads\\2010-input.txt"));

		while (scan.hasNext()) {
			int n = scan.nextInt();
			int q = scan.nextInt();

			Qu qu = new Qu(n);
			for (int i = 0; i < n; i++) {
				qu.add(scan.next(), scan.nextInt());
			}
			while (qu.process(q))
				;
		}

		scan.close();
		System.exit(0);
	}
} Main
import java.io.File;
import java.io.FileNotFoundException;
import java.lang.management.ManagementFactory;
import java.lang.management.ThreadMXBean;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws FileNotFoundException {

		Scanner scan = new Scanner(System.in);
		// Scanner scan = new Scanner(new
		// File("D:\\UserArea\\J0124567\\Downloads\\2010-input.txt"));

		while (scan.hasNext()) {
			int n = scan.nextInt();
			int q = scan.nextInt();

			Qu qu = new Qu(n);
			for (int i = 0; i < n; i++) {
				qu.add(scan.next(), scan.nextInt());
			}
			while (qu.process(q))
				;
		}

		scan.close();
		System.exit(0);
	}
}

class Qu {
	class Proc {
		public Proc(String _name, int _time) {
			name = new String(_name);
			time = _time;
		}

		String name;
		int time;
	}

	List<Proc> proc = new ArrayList<Proc>();
	int pt = 0;
	int total = 0;

	public Qu(int n) {
	}

	public boolean process(int q) {
		if (proc.get(pt).time <= q) {
			total += proc.get(pt).time;
			System.out.println(proc.get(pt).name + " " + total);
			proc.remove(pt);
			if (proc.size() == 0)
				return false;
		} else {
			total += q;
			proc.get(pt).time -= q;
			pt++;
		}
		if (pt == proc.size())
			pt = 0;
		return true;
	}

	public void add(String _name, int _time) {
		proc.add(new Proc(_name, _time));
	}

}