
import java.util.*;



/*
 * Aizuuuuuuu
 * 
 */
public class Main {
	public static void print(ArrayList<String> list) {
		for (String i :list) {
			System.out.println(i);
		}
	}
	public static void main(String[] args) {
		int globalTime = 0;
		
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int q = sc.nextInt();
		ArrayList<String> results = new ArrayList<String>();
		LinkedList<String> ns = new LinkedList<String>();
		LinkedList<Integer> qs = new LinkedList<Integer>();
		
		while (ns.size() < n) {
			ns.addLast(sc.next());
			qs.addLast(sc.nextInt());
		}
		
		String tempS = "";
		int tempI = 0;
		
		while (ns.size() > 0) {
			if (qs.peek() - q <= 0) {
				results.add(ns.poll() + " " + (qs.peek()+globalTime));
				globalTime += qs.poll();
			}
			else {
				tempI = qs.poll();
				tempI -= q;
				qs.addLast(tempI);
				ns.addLast(ns.poll());
				globalTime += q;
			}
		}
		print(results);
		
	}
}
 import java.util.*; util.* java public class Main {
	public static void print(ArrayList<String> list) {
		for (String i :list) {
			System.out.println(i);
		}
	}
	public static void main(String[] args) {
		int globalTime = 0;
		
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int q = sc.nextInt();
		ArrayList<String> results = new ArrayList<String>();
		LinkedList<String> ns = new LinkedList<String>();
		LinkedList<Integer> qs = new LinkedList<Integer>();
		
		while (ns.size() < n) {
			ns.addLast(sc.next());
			qs.addLast(sc.nextInt());
		}
		
		String tempS = "";
		int tempI = 0;
		
		while (ns.size() > 0) {
			if (qs.peek() - q <= 0) {
				results.add(ns.poll() + " " + (qs.peek()+globalTime));
				globalTime += qs.poll();
			}
			else {
				tempI = qs.poll();
				tempI -= q;
				qs.addLast(tempI);
				ns.addLast(ns.poll());
				globalTime += q;
			}
		}
		print(results);
		
	}
} Main public static void print(ArrayList<String> list) {
		for (String i :list) {
			System.out.println(i);
		}
	} print {
		for (String i :list) {
			System.out.println(i);
		}
	} for (String i :list) {
			System.out.println(i);
		} String i list {
			System.out.println(i);
		} {
			System.out.println(i);
		} System.out.println(i) System.out.println System.out System System.out i ArrayList<String> list list public static void main(String[] args) {
		int globalTime = 0;
		
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int q = sc.nextInt();
		ArrayList<String> results = new ArrayList<String>();
		LinkedList<String> ns = new LinkedList<String>();
		LinkedList<Integer> qs = new LinkedList<Integer>();
		
		while (ns.size() < n) {
			ns.addLast(sc.next());
			qs.addLast(sc.nextInt());
		}
		
		String tempS = "";
		int tempI = 0;
		
		while (ns.size() > 0) {
			if (qs.peek() - q <= 0) {
				results.add(ns.poll() + " " + (qs.peek()+globalTime));
				globalTime += qs.poll();
			}
			else {
				tempI = qs.poll();
				tempI -= q;
				qs.addLast(tempI);
				ns.addLast(ns.poll());
				globalTime += q;
			}
		}
		print(results);
		
	} main {
		int globalTime = 0;
		
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int q = sc.nextInt();
		ArrayList<String> results = new ArrayList<String>();
		LinkedList<String> ns = new LinkedList<String>();
		LinkedList<Integer> qs = new LinkedList<Integer>();
		
		while (ns.size() < n) {
			ns.addLast(sc.next());
			qs.addLast(sc.nextInt());
		}
		
		String tempS = "";
		int tempI = 0;
		
		while (ns.size() > 0) {
			if (qs.peek() - q <= 0) {
				results.add(ns.poll() + " " + (qs.peek()+globalTime));
				globalTime += qs.poll();
			}
			else {
				tempI = qs.poll();
				tempI -= q;
				qs.addLast(tempI);
				ns.addLast(ns.poll());
				globalTime += q;
			}
		}
		print(results);
		
	} int globalTime = 0; globalTime 0 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 ArrayList<String> results = new ArrayList<String>(); results new ArrayList<String>() LinkedList<String> ns = new LinkedList<String>(); ns new LinkedList<String>() LinkedList<Integer> qs = new LinkedList<Integer>(); qs new LinkedList<Integer>() while (ns.size() < n) {
			ns.addLast(sc.next());
			qs.addLast(sc.nextInt());
		} ns.size() < n ns.size() ns.size ns n {
			ns.addLast(sc.next());
			qs.addLast(sc.nextInt());
		} ns.addLast(sc.next()) ns.addLast ns sc.next() sc.next sc qs.addLast(sc.nextInt()) qs.addLast qs sc.nextInt() sc.nextInt sc String tempS = ""; tempS "" int tempI = 0; tempI 0 while (ns.size() > 0) {
			if (qs.peek() - q <= 0) {
				results.add(ns.poll() + " " + (qs.peek()+globalTime));
				globalTime += qs.poll();
			}
			else {
				tempI = qs.poll();
				tempI -= q;
				qs.addLast(tempI);
				ns.addLast(ns.poll());
				globalTime += q;
			}
		} ns.size() > 0 ns.size() ns.size ns 0 {
			if (qs.peek() - q <= 0) {
				results.add(ns.poll() + " " + (qs.peek()+globalTime));
				globalTime += qs.poll();
			}
			else {
				tempI = qs.poll();
				tempI -= q;
				qs.addLast(tempI);
				ns.addLast(ns.poll());
				globalTime += q;
			}
		} if (qs.peek() - q <= 0) {
				results.add(ns.poll() + " " + (qs.peek()+globalTime));
				globalTime += qs.poll();
			}
			else {
				tempI = qs.poll();
				tempI -= q;
				qs.addLast(tempI);
				ns.addLast(ns.poll());
				globalTime += q;
			} qs.peek() - q <= 0 qs.peek() - q qs.peek() qs.peek qs q 0 {
				results.add(ns.poll() + " " + (qs.peek()+globalTime));
				globalTime += qs.poll();
			} results.add(ns.poll() + " " + (qs.peek()+globalTime)) results.add results ns.poll() + " " + (qs.peek()+globalTime) ns.poll() + " " + (qs.peek()+globalTime) ns.poll() ns.poll ns " " (qs.peek()+globalTime) qs.peek() qs.peek qs globalTime globalTime += qs.poll() globalTime qs.poll() qs.poll qs {
				tempI = qs.poll();
				tempI -= q;
				qs.addLast(tempI);
				ns.addLast(ns.poll());
				globalTime += q;
			} tempI = qs.poll() tempI qs.poll() qs.poll qs tempI -= q tempI q qs.addLast(tempI) qs.addLast qs tempI ns.addLast(ns.poll()) ns.addLast ns ns.poll() ns.poll ns globalTime += q globalTime q print(results) print results String[] args args public class Main {
	public static void print(ArrayList<String> list) {
		for (String i :list) {
			System.out.println(i);
		}
	}
	public static void main(String[] args) {
		int globalTime = 0;
		
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int q = sc.nextInt();
		ArrayList<String> results = new ArrayList<String>();
		LinkedList<String> ns = new LinkedList<String>();
		LinkedList<Integer> qs = new LinkedList<Integer>();
		
		while (ns.size() < n) {
			ns.addLast(sc.next());
			qs.addLast(sc.nextInt());
		}
		
		String tempS = "";
		int tempI = 0;
		
		while (ns.size() > 0) {
			if (qs.peek() - q <= 0) {
				results.add(ns.poll() + " " + (qs.peek()+globalTime));
				globalTime += qs.poll();
			}
			else {
				tempI = qs.poll();
				tempI -= q;
				qs.addLast(tempI);
				ns.addLast(ns.poll());
				globalTime += q;
			}
		}
		print(results);
		
	}
} public class Main {
	public static void print(ArrayList<String> list) {
		for (String i :list) {
			System.out.println(i);
		}
	}
	public static void main(String[] args) {
		int globalTime = 0;
		
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int q = sc.nextInt();
		ArrayList<String> results = new ArrayList<String>();
		LinkedList<String> ns = new LinkedList<String>();
		LinkedList<Integer> qs = new LinkedList<Integer>();
		
		while (ns.size() < n) {
			ns.addLast(sc.next());
			qs.addLast(sc.nextInt());
		}
		
		String tempS = "";
		int tempI = 0;
		
		while (ns.size() > 0) {
			if (qs.peek() - q <= 0) {
				results.add(ns.poll() + " " + (qs.peek()+globalTime));
				globalTime += qs.poll();
			}
			else {
				tempI = qs.poll();
				tempI -= q;
				qs.addLast(tempI);
				ns.addLast(ns.poll());
				globalTime += q;
			}
		}
		print(results);
		
	}
} Main

import java.util.*;



/*
 * Aizuuuuuuu
 * 
 */
public class Main {
	public static void print(ArrayList<String> list) {
		for (String i :list) {
			System.out.println(i);
		}
	}
	public static void main(String[] args) {
		int globalTime = 0;
		
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int q = sc.nextInt();
		ArrayList<String> results = new ArrayList<String>();
		LinkedList<String> ns = new LinkedList<String>();
		LinkedList<Integer> qs = new LinkedList<Integer>();
		
		while (ns.size() < n) {
			ns.addLast(sc.next());
			qs.addLast(sc.nextInt());
		}
		
		String tempS = "";
		int tempI = 0;
		
		while (ns.size() > 0) {
			if (qs.peek() - q <= 0) {
				results.add(ns.poll() + " " + (qs.peek()+globalTime));
				globalTime += qs.poll();
			}
			else {
				tempI = qs.poll();
				tempI -= q;
				qs.addLast(tempI);
				ns.addLast(ns.poll());
				globalTime += q;
			}
		}
		print(results);
		
	}
}

