import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;
class Main {
	public static void main(String[] args){
		try(Scanner sc = new Scanner(System.in)){
			Deque<Process> process=new ArrayDeque<>();
			int n=Integer.parseInt(sc.next());
			int q=Integer.parseInt(sc.next());
			for(int i=0;i<n;i++){
				String name=sc.next();
				int time=Integer.parseInt(sc.next());
				process.addLast(new Process(name,time));
			}
			int totalTime=0;
			while(process.size()!=0){
				Process p = process.pollFirst().clone();
				if(p.isEnds(q)){
					totalTime+=p.time;
					System.out.println(p.name+" "+totalTime);
				}else{
					totalTime+=q;
					p.work(q);
					process.addLast(p);
				}
			}
		}
	}
}

class Process implements Cloneable{
	String name;
	int time;
	Process(String name, int time){
		this.name=name;
		this.time=time;
	}
	public Process clone(){
		Process p = new Process(this.name,this.time);
		return p;
	}
	public boolean isEnds(int q){
		return (this.time<=q);
	}
	public void work(int q){
		this.time-=q;
	}
} import java.util.ArrayDeque; ArrayDeque java.util import java.util.Deque; Deque java.util import java.util.Scanner; Scanner java.util class Main {
	public static void main(String[] args){
		try(Scanner sc = new Scanner(System.in)){
			Deque<Process> process=new ArrayDeque<>();
			int n=Integer.parseInt(sc.next());
			int q=Integer.parseInt(sc.next());
			for(int i=0;i<n;i++){
				String name=sc.next();
				int time=Integer.parseInt(sc.next());
				process.addLast(new Process(name,time));
			}
			int totalTime=0;
			while(process.size()!=0){
				Process p = process.pollFirst().clone();
				if(p.isEnds(q)){
					totalTime+=p.time;
					System.out.println(p.name+" "+totalTime);
				}else{
					totalTime+=q;
					p.work(q);
					process.addLast(p);
				}
			}
		}
	}
} Main public static void main(String[] args){
		try(Scanner sc = new Scanner(System.in)){
			Deque<Process> process=new ArrayDeque<>();
			int n=Integer.parseInt(sc.next());
			int q=Integer.parseInt(sc.next());
			for(int i=0;i<n;i++){
				String name=sc.next();
				int time=Integer.parseInt(sc.next());
				process.addLast(new Process(name,time));
			}
			int totalTime=0;
			while(process.size()!=0){
				Process p = process.pollFirst().clone();
				if(p.isEnds(q)){
					totalTime+=p.time;
					System.out.println(p.name+" "+totalTime);
				}else{
					totalTime+=q;
					p.work(q);
					process.addLast(p);
				}
			}
		}
	} main {
		try(Scanner sc = new Scanner(System.in)){
			Deque<Process> process=new ArrayDeque<>();
			int n=Integer.parseInt(sc.next());
			int q=Integer.parseInt(sc.next());
			for(int i=0;i<n;i++){
				String name=sc.next();
				int time=Integer.parseInt(sc.next());
				process.addLast(new Process(name,time));
			}
			int totalTime=0;
			while(process.size()!=0){
				Process p = process.pollFirst().clone();
				if(p.isEnds(q)){
					totalTime+=p.time;
					System.out.println(p.name+" "+totalTime);
				}else{
					totalTime+=q;
					p.work(q);
					process.addLast(p);
				}
			}
		}
	} try(Scanner sc = new Scanner(System.in)){
			Deque<Process> process=new ArrayDeque<>();
			int n=Integer.parseInt(sc.next());
			int q=Integer.parseInt(sc.next());
			for(int i=0;i<n;i++){
				String name=sc.next();
				int time=Integer.parseInt(sc.next());
				process.addLast(new Process(name,time));
			}
			int totalTime=0;
			while(process.size()!=0){
				Process p = process.pollFirst().clone();
				if(p.isEnds(q)){
					totalTime+=p.time;
					System.out.println(p.name+" "+totalTime);
				}else{
					totalTime+=q;
					p.work(q);
					process.addLast(p);
				}
			}
		} {
			Deque<Process> process=new ArrayDeque<>();
			int n=Integer.parseInt(sc.next());
			int q=Integer.parseInt(sc.next());
			for(int i=0;i<n;i++){
				String name=sc.next();
				int time=Integer.parseInt(sc.next());
				process.addLast(new Process(name,time));
			}
			int totalTime=0;
			while(process.size()!=0){
				Process p = process.pollFirst().clone();
				if(p.isEnds(q)){
					totalTime+=p.time;
					System.out.println(p.name+" "+totalTime);
				}else{
					totalTime+=q;
					p.work(q);
					process.addLast(p);
				}
			}
		} Scanner sc = new Scanner(System.in) Scanner sc = new Scanner(System.in) new Scanner(System.in) Deque<Process> process=new ArrayDeque<>(); process new ArrayDeque<>() int n=Integer.parseInt(sc.next()); n Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int q=Integer.parseInt(sc.next()); q Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc for(int i=0;i<n;i++){
				String name=sc.next();
				int time=Integer.parseInt(sc.next());
				process.addLast(new Process(name,time));
			} int i=0; int i=0; i 0 i<n i n i++ i++ i {
				String name=sc.next();
				int time=Integer.parseInt(sc.next());
				process.addLast(new Process(name,time));
			} {
				String name=sc.next();
				int time=Integer.parseInt(sc.next());
				process.addLast(new Process(name,time));
			} String name=sc.next(); name sc.next() sc.next sc int time=Integer.parseInt(sc.next()); time Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc process.addLast(new Process(name,time)) process.addLast process new Process(name,time) int totalTime=0; totalTime 0 while(process.size()!=0){
				Process p = process.pollFirst().clone();
				if(p.isEnds(q)){
					totalTime+=p.time;
					System.out.println(p.name+" "+totalTime);
				}else{
					totalTime+=q;
					p.work(q);
					process.addLast(p);
				}
			} process.size()!=0 process.size() process.size process 0 {
				Process p = process.pollFirst().clone();
				if(p.isEnds(q)){
					totalTime+=p.time;
					System.out.println(p.name+" "+totalTime);
				}else{
					totalTime+=q;
					p.work(q);
					process.addLast(p);
				}
			} Process p = process.pollFirst().clone(); p process.pollFirst().clone() process.pollFirst().clone process.pollFirst() process.pollFirst process if(p.isEnds(q)){
					totalTime+=p.time;
					System.out.println(p.name+" "+totalTime);
				}else{
					totalTime+=q;
					p.work(q);
					process.addLast(p);
				} p.isEnds(q) p.isEnds p q {
					totalTime+=p.time;
					System.out.println(p.name+" "+totalTime);
				} totalTime+=p.time totalTime p.time p p.time System.out.println(p.name+" "+totalTime) System.out.println System.out System System.out p.name+" "+totalTime p.name+" "+totalTime p.name p p.name " " totalTime {
					totalTime+=q;
					p.work(q);
					process.addLast(p);
				} totalTime+=q totalTime q p.work(q) p.work p q process.addLast(p) process.addLast process p String[] args args class Process implements Cloneable{
	String name;
	int time;
	Process(String name, int time){
		this.name=name;
		this.time=time;
	}
	public Process clone(){
		Process p = new Process(this.name,this.time);
		return p;
	}
	public boolean isEnds(int q){
		return (this.time<=q);
	}
	public void work(int q){
		this.time-=q;
	}
} Process String name; name int time; time Process(String name, int time){
		this.name=name;
		this.time=time;
	} Process {
		this.name=name;
		this.time=time;
	} this.name=name this.name this this.name name this.time=time this.time this this.time time String name name int time time public Process clone(){
		Process p = new Process(this.name,this.time);
		return p;
	} clone {
		Process p = new Process(this.name,this.time);
		return p;
	} Process p = new Process(this.name,this.time); p new Process(this.name,this.time) return p; p public boolean isEnds(int q){
		return (this.time<=q);
	} isEnds {
		return (this.time<=q);
	} return (this.time<=q); (this.time<=q) this.time this this.time q int q q public void work(int q){
		this.time-=q;
	} work {
		this.time-=q;
	} this.time-=q this.time this this.time q int q q Cloneable
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;
class Main {
	public static void main(String[] args){
		try(Scanner sc = new Scanner(System.in)){
			Deque<Process> process=new ArrayDeque<>();
			int n=Integer.parseInt(sc.next());
			int q=Integer.parseInt(sc.next());
			for(int i=0;i<n;i++){
				String name=sc.next();
				int time=Integer.parseInt(sc.next());
				process.addLast(new Process(name,time));
			}
			int totalTime=0;
			while(process.size()!=0){
				Process p = process.pollFirst().clone();
				if(p.isEnds(q)){
					totalTime+=p.time;
					System.out.println(p.name+" "+totalTime);
				}else{
					totalTime+=q;
					p.work(q);
					process.addLast(p);
				}
			}
		}
	}
}

class Process implements Cloneable{
	String name;
	int time;
	Process(String name, int time){
		this.name=name;
		this.time=time;
	}
	public Process clone(){
		Process p = new Process(this.name,this.time);
		return p;
	}
	public boolean isEnds(int q){
		return (this.time<=q);
	}
	public void work(int q){
		this.time-=q;
	}
}