import java.util.Scanner;

class Process{
	int time;
	String name;
	public Process(String name,int time){
		this.time = time;
		this.name = name;
	}
}

class Queue{
	private Process[] queArray;
	private int front;
	private int rear;
	private int maxSize;
	private int nItems;
	
	public Queue(int size){
		maxSize = size;
		queArray = new Process[maxSize];
		front = 0;
		rear = -1;
		nItems = 0;
	}
	public void insert(Process p){
		if(rear == maxSize -1) rear = -1;
		queArray[++rear] = p;
		nItems++;
	}
	public Process remove(){
		Process temp = queArray[front++];
		if(front == maxSize) front = 0;
		nItems--;
			return temp;
	}
	public boolean isEmpty(){
		//return (rear+1==front || (front+maxSize-1==rear));
		return (nItems == 0);
	}
}

 class Main{
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int q = in.nextInt();
		Queue que = new Queue(n);
		int finTime = 0;
		for(int i = 0;i<n;i++){
			que.insert(new Process(in.next(),in.nextInt()) );
		}
		
		while(!que.isEmpty()){
			Process remove = que.remove();
			int c = Math.min(q, remove.time);
			remove.time -= c;
			finTime += c;
			if(remove.time>0){
				que.insert(remove);
			}else{
				System.out.println(remove.name+ " " +finTime);
			}
	}

	}
} import java.util.Scanner; Scanner java.util class Process{
	int time;
	String name;
	public Process(String name,int time){
		this.time = time;
		this.name = name;
	}
} Process int time; time String name; name public Process(String name,int time){
		this.time = time;
		this.name = name;
	} Process {
		this.time = time;
		this.name = name;
	} this.time = time this.time this this.time time this.name = name this.name this this.name name String name name int time time class Queue{
	private Process[] queArray;
	private int front;
	private int rear;
	private int maxSize;
	private int nItems;
	
	public Queue(int size){
		maxSize = size;
		queArray = new Process[maxSize];
		front = 0;
		rear = -1;
		nItems = 0;
	}
	public void insert(Process p){
		if(rear == maxSize -1) rear = -1;
		queArray[++rear] = p;
		nItems++;
	}
	public Process remove(){
		Process temp = queArray[front++];
		if(front == maxSize) front = 0;
		nItems--;
			return temp;
	}
	public boolean isEmpty(){
		//return (rear+1==front || (front+maxSize-1==rear));
		return (nItems == 0);
	}
} Queue private Process[] queArray; queArray private int front; front private int rear; rear private int maxSize; maxSize private int nItems; nItems public Queue(int size){
		maxSize = size;
		queArray = new Process[maxSize];
		front = 0;
		rear = -1;
		nItems = 0;
	} Queue {
		maxSize = size;
		queArray = new Process[maxSize];
		front = 0;
		rear = -1;
		nItems = 0;
	} maxSize = size maxSize size queArray = new Process[maxSize] queArray new Process[maxSize] maxSize front = 0 front 0 rear = -1 rear -1 1 nItems = 0 nItems 0 int size size public void insert(Process p){
		if(rear == maxSize -1) rear = -1;
		queArray[++rear] = p;
		nItems++;
	} insert {
		if(rear == maxSize -1) rear = -1;
		queArray[++rear] = p;
		nItems++;
	} if(rear == maxSize -1) rear = -1; rear == maxSize -1 rear maxSize -1 maxSize 1 rear = -1 rear -1 1 queArray[++rear] = p queArray[++rear] queArray ++rear rear p nItems++ nItems Process p p public Process remove(){
		Process temp = queArray[front++];
		if(front == maxSize) front = 0;
		nItems--;
			return temp;
	} remove {
		Process temp = queArray[front++];
		if(front == maxSize) front = 0;
		nItems--;
			return temp;
	} Process temp = queArray[front++]; temp queArray[front++] queArray front++ front if(front == maxSize) front = 0; front == maxSize front maxSize front = 0 front 0 nItems-- nItems return temp; temp public boolean isEmpty(){
		//return (rear+1==front || (front+maxSize-1==rear));
		return (nItems == 0);
	} isEmpty {
		//return (rear+1==front || (front+maxSize-1==rear));
		return (nItems == 0);
	} return (nItems == 0); (nItems == 0) nItems 0 class Main{
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int q = in.nextInt();
		Queue que = new Queue(n);
		int finTime = 0;
		for(int i = 0;i<n;i++){
			que.insert(new Process(in.next(),in.nextInt()) );
		}
		
		while(!que.isEmpty()){
			Process remove = que.remove();
			int c = Math.min(q, remove.time);
			remove.time -= c;
			finTime += c;
			if(remove.time>0){
				que.insert(remove);
			}else{
				System.out.println(remove.name+ " " +finTime);
			}
	}

	}
} Main public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int q = in.nextInt();
		Queue que = new Queue(n);
		int finTime = 0;
		for(int i = 0;i<n;i++){
			que.insert(new Process(in.next(),in.nextInt()) );
		}
		
		while(!que.isEmpty()){
			Process remove = que.remove();
			int c = Math.min(q, remove.time);
			remove.time -= c;
			finTime += c;
			if(remove.time>0){
				que.insert(remove);
			}else{
				System.out.println(remove.name+ " " +finTime);
			}
	}

	} main {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int q = in.nextInt();
		Queue que = new Queue(n);
		int finTime = 0;
		for(int i = 0;i<n;i++){
			que.insert(new Process(in.next(),in.nextInt()) );
		}
		
		while(!que.isEmpty()){
			Process remove = que.remove();
			int c = Math.min(q, remove.time);
			remove.time -= c;
			finTime += c;
			if(remove.time>0){
				que.insert(remove);
			}else{
				System.out.println(remove.name+ " " +finTime);
			}
	}

	} Scanner in = new Scanner(System.in); in new Scanner(System.in) int n = in.nextInt(); n in.nextInt() in.nextInt in int q = in.nextInt(); q in.nextInt() in.nextInt in Queue que = new Queue(n); que new Queue(n) int finTime = 0; finTime 0 for(int i = 0;i<n;i++){
			que.insert(new Process(in.next(),in.nextInt()) );
		} int i = 0; int i = 0; i 0 i<n i n i++ i++ i {
			que.insert(new Process(in.next(),in.nextInt()) );
		} {
			que.insert(new Process(in.next(),in.nextInt()) );
		} que.insert(new Process(in.next(),in.nextInt()) ) que.insert que new Process(in.next(),in.nextInt()) while(!que.isEmpty()){
			Process remove = que.remove();
			int c = Math.min(q, remove.time);
			remove.time -= c;
			finTime += c;
			if(remove.time>0){
				que.insert(remove);
			}else{
				System.out.println(remove.name+ " " +finTime);
			}
	} !que.isEmpty() que.isEmpty() que.isEmpty que {
			Process remove = que.remove();
			int c = Math.min(q, remove.time);
			remove.time -= c;
			finTime += c;
			if(remove.time>0){
				que.insert(remove);
			}else{
				System.out.println(remove.name+ " " +finTime);
			}
	} Process remove = que.remove(); remove que.remove() que.remove que int c = Math.min(q, remove.time); c Math.min(q, remove.time) Math.min Math q remove.time remove remove.time remove.time -= c remove.time remove remove.time c finTime += c finTime c if(remove.time>0){
				que.insert(remove);
			}else{
				System.out.println(remove.name+ " " +finTime);
			} remove.time>0 remove.time remove remove.time 0 {
				que.insert(remove);
			} que.insert(remove) que.insert que remove {
				System.out.println(remove.name+ " " +finTime);
			} System.out.println(remove.name+ " " +finTime) System.out.println System.out System System.out remove.name+ " " +finTime remove.name+ " " +finTime remove.name remove remove.name " " finTime String[] args args
import java.util.Scanner;

class Process{
	int time;
	String name;
	public Process(String name,int time){
		this.time = time;
		this.name = name;
	}
}

class Queue{
	private Process[] queArray;
	private int front;
	private int rear;
	private int maxSize;
	private int nItems;
	
	public Queue(int size){
		maxSize = size;
		queArray = new Process[maxSize];
		front = 0;
		rear = -1;
		nItems = 0;
	}
	public void insert(Process p){
		if(rear == maxSize -1) rear = -1;
		queArray[++rear] = p;
		nItems++;
	}
	public Process remove(){
		Process temp = queArray[front++];
		if(front == maxSize) front = 0;
		nItems--;
			return temp;
	}
	public boolean isEmpty(){
		//return (rear+1==front || (front+maxSize-1==rear));
		return (nItems == 0);
	}
}

 class Main{
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int q = in.nextInt();
		Queue que = new Queue(n);
		int finTime = 0;
		for(int i = 0;i<n;i++){
			que.insert(new Process(in.next(),in.nextInt()) );
		}
		
		while(!que.isEmpty()){
			Process remove = que.remove();
			int c = Math.min(q, remove.time);
			remove.time -= c;
			finTime += c;
			if(remove.time>0){
				que.insert(remove);
			}else{
				System.out.println(remove.name+ " " +finTime);
			}
	}

	}
}