import java.util.*;
import java.io.*;

class Main{
    public static void main(String[] args) throws IOException{
	Scanner sc = new Scanner(System.in);

	int i;
	int n;
	int t;
	int gettime = 0;
	
	Queue<String> p = new LinkedList<String>();
	Queue<Integer> time = new LinkedList<Integer>();
	
	n = sc.nextInt();
	t = sc.nextInt();
	
	for(i=0; i<n; i++){
	    p.add(sc.next());
	    time.add(sc.nextInt());
	}
	
	while(0 < p.size()){
	    if(0 < (time.peek() - t)){
		p.add(p.poll());
		time.add(time.poll() - t);
		gettime = gettime + t;
	    }else{
		gettime = gettime + time.poll();
		System.out.println(p.poll() + " " + gettime);
	    }
	}
    }
}
 import java.util.*; util.* java import java.io.*; io.* java class Main{
    public static void main(String[] args) throws IOException{
	Scanner sc = new Scanner(System.in);

	int i;
	int n;
	int t;
	int gettime = 0;
	
	Queue<String> p = new LinkedList<String>();
	Queue<Integer> time = new LinkedList<Integer>();
	
	n = sc.nextInt();
	t = sc.nextInt();
	
	for(i=0; i<n; i++){
	    p.add(sc.next());
	    time.add(sc.nextInt());
	}
	
	while(0 < p.size()){
	    if(0 < (time.peek() - t)){
		p.add(p.poll());
		time.add(time.poll() - t);
		gettime = gettime + t;
	    }else{
		gettime = gettime + time.poll();
		System.out.println(p.poll() + " " + gettime);
	    }
	}
    }
} Main public static void main(String[] args) throws IOException{
	Scanner sc = new Scanner(System.in);

	int i;
	int n;
	int t;
	int gettime = 0;
	
	Queue<String> p = new LinkedList<String>();
	Queue<Integer> time = new LinkedList<Integer>();
	
	n = sc.nextInt();
	t = sc.nextInt();
	
	for(i=0; i<n; i++){
	    p.add(sc.next());
	    time.add(sc.nextInt());
	}
	
	while(0 < p.size()){
	    if(0 < (time.peek() - t)){
		p.add(p.poll());
		time.add(time.poll() - t);
		gettime = gettime + t;
	    }else{
		gettime = gettime + time.poll();
		System.out.println(p.poll() + " " + gettime);
	    }
	}
    } main {
	Scanner sc = new Scanner(System.in);

	int i;
	int n;
	int t;
	int gettime = 0;
	
	Queue<String> p = new LinkedList<String>();
	Queue<Integer> time = new LinkedList<Integer>();
	
	n = sc.nextInt();
	t = sc.nextInt();
	
	for(i=0; i<n; i++){
	    p.add(sc.next());
	    time.add(sc.nextInt());
	}
	
	while(0 < p.size()){
	    if(0 < (time.peek() - t)){
		p.add(p.poll());
		time.add(time.poll() - t);
		gettime = gettime + t;
	    }else{
		gettime = gettime + time.poll();
		System.out.println(p.poll() + " " + gettime);
	    }
	}
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int i; i int n; n int t; t int gettime = 0; gettime 0 Queue<String> p = new LinkedList<String>(); p new LinkedList<String>() Queue<Integer> time = new LinkedList<Integer>(); time new LinkedList<Integer>() n = sc.nextInt() n sc.nextInt() sc.nextInt sc t = sc.nextInt() t sc.nextInt() sc.nextInt sc for(i=0; i<n; i++){
	    p.add(sc.next());
	    time.add(sc.nextInt());
	} i=0; i=0 i 0 i<n i n i++ i++ i {
	    p.add(sc.next());
	    time.add(sc.nextInt());
	} {
	    p.add(sc.next());
	    time.add(sc.nextInt());
	} p.add(sc.next()) p.add p sc.next() sc.next sc time.add(sc.nextInt()) time.add time sc.nextInt() sc.nextInt sc while(0 < p.size()){
	    if(0 < (time.peek() - t)){
		p.add(p.poll());
		time.add(time.poll() - t);
		gettime = gettime + t;
	    }else{
		gettime = gettime + time.poll();
		System.out.println(p.poll() + " " + gettime);
	    }
	} 0 < p.size() 0 p.size() p.size p {
	    if(0 < (time.peek() - t)){
		p.add(p.poll());
		time.add(time.poll() - t);
		gettime = gettime + t;
	    }else{
		gettime = gettime + time.poll();
		System.out.println(p.poll() + " " + gettime);
	    }
	} if(0 < (time.peek() - t)){
		p.add(p.poll());
		time.add(time.poll() - t);
		gettime = gettime + t;
	    }else{
		gettime = gettime + time.poll();
		System.out.println(p.poll() + " " + gettime);
	    } 0 < (time.peek() - t) 0 (time.peek() - t) time.peek() time.peek time t {
		p.add(p.poll());
		time.add(time.poll() - t);
		gettime = gettime + t;
	    } p.add(p.poll()) p.add p p.poll() p.poll p time.add(time.poll() - t) time.add time time.poll() - t time.poll() time.poll time t gettime = gettime + t gettime gettime + t gettime t {
		gettime = gettime + time.poll();
		System.out.println(p.poll() + " " + gettime);
	    } gettime = gettime + time.poll() gettime gettime + time.poll() gettime time.poll() time.poll time System.out.println(p.poll() + " " + gettime) System.out.println System.out System System.out p.poll() + " " + gettime p.poll() + " " + gettime p.poll() p.poll p " " gettime String[] args args
import java.util.*;
import java.io.*;

class Main{
    public static void main(String[] args) throws IOException{
	Scanner sc = new Scanner(System.in);

	int i;
	int n;
	int t;
	int gettime = 0;
	
	Queue<String> p = new LinkedList<String>();
	Queue<Integer> time = new LinkedList<Integer>();
	
	n = sc.nextInt();
	t = sc.nextInt();
	
	for(i=0; i<n; i++){
	    p.add(sc.next());
	    time.add(sc.nextInt());
	}
	
	while(0 < p.size()){
	    if(0 < (time.peek() - t)){
		p.add(p.poll());
		time.add(time.poll() - t);
		gettime = gettime + t;
	    }else{
		gettime = gettime + time.poll();
		System.out.println(p.poll() + " " + gettime);
	    }
	}
    }
}

