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

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int q = sc.nextInt();
		Orique oq = new Orique();
		for (int i = 0; i < n; i++) {
			oq.inque(sc.next(), sc.nextInt());
		}
		oq.RoundRobinScheduling(q);
	}
}

class Orique {
	private class kakunou {
		String kstr;
		int kint;
		int kprenum;

		void setkakunou(String s, int i, int pre) {
			kstr = s;
			kint = i;
			kprenum = pre;
		}
	}

	private int length = 0;
	ArrayList<String> str = new ArrayList<String>();
	ArrayList<Integer> in = new ArrayList<Integer>();
	kakunou k;
	private ArrayList<Integer> prenumber = new ArrayList<Integer>();

	Orique() {
		k = new kakunou();
	}

	public void inque(String t, int i) {
		str.add(t);
		in.add(i);
		prenumber.add(i);
		length++;
	}

	private void inque(kakunou k) {
		str.add(k.kstr);
		in.add(k.kint);
		prenumber.add(k.kprenum);
		length++;
	}

	private void deque() {
		k.setkakunou(str.get(0), in.get(0), prenumber.get(0));
		str.remove(0);
		in.remove(0);
		prenumber.remove(0);
		length--;

	}
    public void RoundRobinScheduling(int q) {
		
		int total=0;
		deque();
		while(true){
			int t1=k.kint-q;
			if(t1>0){
				total=total+q;
				k.kint=t1;
				inque(k);
				
			}else{
				total=total+k.kint;
				System.out.println(k.kstr+" "+total);
				}
			if(length>0)deque();
			else break;
		}
		}
} import java.util.ArrayList; ArrayList java.util import java.util.Scanner; Scanner java.util class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int q = sc.nextInt();
		Orique oq = new Orique();
		for (int i = 0; i < n; i++) {
			oq.inque(sc.next(), sc.nextInt());
		}
		oq.RoundRobinScheduling(q);
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int q = sc.nextInt();
		Orique oq = new Orique();
		for (int i = 0; i < n; i++) {
			oq.inque(sc.next(), sc.nextInt());
		}
		oq.RoundRobinScheduling(q);
	} main {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int q = sc.nextInt();
		Orique oq = new Orique();
		for (int i = 0; i < n; i++) {
			oq.inque(sc.next(), sc.nextInt());
		}
		oq.RoundRobinScheduling(q);
	} 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 Orique oq = new Orique(); oq new Orique() for (int i = 0; i < n; i++) {
			oq.inque(sc.next(), sc.nextInt());
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			oq.inque(sc.next(), sc.nextInt());
		} {
			oq.inque(sc.next(), sc.nextInt());
		} oq.inque(sc.next(), sc.nextInt()) oq.inque oq sc.next() sc.next sc sc.nextInt() sc.nextInt sc oq.RoundRobinScheduling(q) oq.RoundRobinScheduling oq q String[] args args class Orique {
	private class kakunou {
		String kstr;
		int kint;
		int kprenum;

		void setkakunou(String s, int i, int pre) {
			kstr = s;
			kint = i;
			kprenum = pre;
		}
	}

	private int length = 0;
	ArrayList<String> str = new ArrayList<String>();
	ArrayList<Integer> in = new ArrayList<Integer>();
	kakunou k;
	private ArrayList<Integer> prenumber = new ArrayList<Integer>();

	Orique() {
		k = new kakunou();
	}

	public void inque(String t, int i) {
		str.add(t);
		in.add(i);
		prenumber.add(i);
		length++;
	}

	private void inque(kakunou k) {
		str.add(k.kstr);
		in.add(k.kint);
		prenumber.add(k.kprenum);
		length++;
	}

	private void deque() {
		k.setkakunou(str.get(0), in.get(0), prenumber.get(0));
		str.remove(0);
		in.remove(0);
		prenumber.remove(0);
		length--;

	}
    public void RoundRobinScheduling(int q) {
		
		int total=0;
		deque();
		while(true){
			int t1=k.kint-q;
			if(t1>0){
				total=total+q;
				k.kint=t1;
				inque(k);
				
			}else{
				total=total+k.kint;
				System.out.println(k.kstr+" "+total);
				}
			if(length>0)deque();
			else break;
		}
		}
} Orique private int length = 0; length 0 ArrayList<String> str = new ArrayList<String>(); str new ArrayList<String>() ArrayList<Integer> in = new ArrayList<Integer>(); in new ArrayList<Integer>() kakunou k; k private ArrayList<Integer> prenumber = new ArrayList<Integer>(); prenumber new ArrayList<Integer>() Orique() {
		k = new kakunou();
	} Orique {
		k = new kakunou();
	} k = new kakunou() k new kakunou() public void inque(String t, int i) {
		str.add(t);
		in.add(i);
		prenumber.add(i);
		length++;
	} inque {
		str.add(t);
		in.add(i);
		prenumber.add(i);
		length++;
	} str.add(t) str.add str t in.add(i) in.add in i prenumber.add(i) prenumber.add prenumber i length++ length String t t int i i private void inque(kakunou k) {
		str.add(k.kstr);
		in.add(k.kint);
		prenumber.add(k.kprenum);
		length++;
	} inque {
		str.add(k.kstr);
		in.add(k.kint);
		prenumber.add(k.kprenum);
		length++;
	} str.add(k.kstr) str.add str k.kstr k k.kstr in.add(k.kint) in.add in k.kint k k.kint prenumber.add(k.kprenum) prenumber.add prenumber k.kprenum k k.kprenum length++ length kakunou k k private void deque() {
		k.setkakunou(str.get(0), in.get(0), prenumber.get(0));
		str.remove(0);
		in.remove(0);
		prenumber.remove(0);
		length--;

	} deque {
		k.setkakunou(str.get(0), in.get(0), prenumber.get(0));
		str.remove(0);
		in.remove(0);
		prenumber.remove(0);
		length--;

	} k.setkakunou(str.get(0), in.get(0), prenumber.get(0)) k.setkakunou k str.get(0) str.get str 0 in.get(0) in.get in 0 prenumber.get(0) prenumber.get prenumber 0 str.remove(0) str.remove str 0 in.remove(0) in.remove in 0 prenumber.remove(0) prenumber.remove prenumber 0 length-- length public void RoundRobinScheduling(int q) {
		
		int total=0;
		deque();
		while(true){
			int t1=k.kint-q;
			if(t1>0){
				total=total+q;
				k.kint=t1;
				inque(k);
				
			}else{
				total=total+k.kint;
				System.out.println(k.kstr+" "+total);
				}
			if(length>0)deque();
			else break;
		}
		} RoundRobinScheduling {
		
		int total=0;
		deque();
		while(true){
			int t1=k.kint-q;
			if(t1>0){
				total=total+q;
				k.kint=t1;
				inque(k);
				
			}else{
				total=total+k.kint;
				System.out.println(k.kstr+" "+total);
				}
			if(length>0)deque();
			else break;
		}
		} int total=0; total 0 deque() deque while(true){
			int t1=k.kint-q;
			if(t1>0){
				total=total+q;
				k.kint=t1;
				inque(k);
				
			}else{
				total=total+k.kint;
				System.out.println(k.kstr+" "+total);
				}
			if(length>0)deque();
			else break;
		} true {
			int t1=k.kint-q;
			if(t1>0){
				total=total+q;
				k.kint=t1;
				inque(k);
				
			}else{
				total=total+k.kint;
				System.out.println(k.kstr+" "+total);
				}
			if(length>0)deque();
			else break;
		} int t1=k.kint-q; t1 k.kint-q k.kint k k.kint q if(t1>0){
				total=total+q;
				k.kint=t1;
				inque(k);
				
			}else{
				total=total+k.kint;
				System.out.println(k.kstr+" "+total);
				} t1>0 t1 0 {
				total=total+q;
				k.kint=t1;
				inque(k);
				
			} total=total+q total total+q total q k.kint=t1 k.kint k k.kint t1 inque(k) inque k {
				total=total+k.kint;
				System.out.println(k.kstr+" "+total);
				} total=total+k.kint total total+k.kint total k.kint k k.kint System.out.println(k.kstr+" "+total) System.out.println System.out System System.out k.kstr+" "+total k.kstr+" "+total k.kstr k k.kstr " " total if(length>0)deque();
			else break; length>0 length 0 deque() deque break; int q q private class kakunou {
		String kstr;
		int kint;
		int kprenum;

		void setkakunou(String s, int i, int pre) {
			kstr = s;
			kint = i;
			kprenum = pre;
		}
	} kakunou String kstr; kstr int kint; kint int kprenum; kprenum void setkakunou(String s, int i, int pre) {
			kstr = s;
			kint = i;
			kprenum = pre;
		} setkakunou {
			kstr = s;
			kint = i;
			kprenum = pre;
		} kstr = s kstr s kint = i kint i kprenum = pre kprenum pre String s s int i i int pre pre
import java.util.ArrayList;
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int q = sc.nextInt();
		Orique oq = new Orique();
		for (int i = 0; i < n; i++) {
			oq.inque(sc.next(), sc.nextInt());
		}
		oq.RoundRobinScheduling(q);
	}
}

class Orique {
	private class kakunou {
		String kstr;
		int kint;
		int kprenum;

		void setkakunou(String s, int i, int pre) {
			kstr = s;
			kint = i;
			kprenum = pre;
		}
	}

	private int length = 0;
	ArrayList<String> str = new ArrayList<String>();
	ArrayList<Integer> in = new ArrayList<Integer>();
	kakunou k;
	private ArrayList<Integer> prenumber = new ArrayList<Integer>();

	Orique() {
		k = new kakunou();
	}

	public void inque(String t, int i) {
		str.add(t);
		in.add(i);
		prenumber.add(i);
		length++;
	}

	private void inque(kakunou k) {
		str.add(k.kstr);
		in.add(k.kint);
		prenumber.add(k.kprenum);
		length++;
	}

	private void deque() {
		k.setkakunou(str.get(0), in.get(0), prenumber.get(0));
		str.remove(0);
		in.remove(0);
		prenumber.remove(0);
		length--;

	}
    public void RoundRobinScheduling(int q) {
		
		int total=0;
		deque();
		while(true){
			int t1=k.kint-q;
			if(t1>0){
				total=total+q;
				k.kint=t1;
				inque(k);
				
			}else{
				total=total+k.kint;
				System.out.println(k.kstr+" "+total);
				}
			if(length>0)deque();
			else break;
		}
		}
}