
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
	// write your code here
        Scanner scanner=new Scanner(System.in);
        Deque<Task> deque=new ArrayDeque<>();
        long time=0;
        int n=scanner.nextInt();
        final int limit=scanner.nextInt();
        for(int i=0;i<n;i++){
            deque.addLast(new Task(scanner.next(),scanner.nextInt()));
        }
        while(deque.size()>0){
            Task currentTask=deque.removeFirst();
            if(currentTask.time<=limit){
                time+=currentTask.time;
                System.out.println(String.format("%s %d",currentTask.name,time));
            }else{
                currentTask.time=currentTask.time-limit;
                deque.addLast(currentTask);
                time+=limit;
            }
        }
    }
    public static class Task{
        public String name;
        public int time;
        public Task(String name,int time){
            this.name=name;
            this.time=time;
        }
    }
}
 import java.util.ArrayDeque; ArrayDeque java.util import java.util.Deque; Deque java.util import java.util.Scanner; Scanner java.util public class Main {

    public static void main(String[] args) {
	// write your code here
        Scanner scanner=new Scanner(System.in);
        Deque<Task> deque=new ArrayDeque<>();
        long time=0;
        int n=scanner.nextInt();
        final int limit=scanner.nextInt();
        for(int i=0;i<n;i++){
            deque.addLast(new Task(scanner.next(),scanner.nextInt()));
        }
        while(deque.size()>0){
            Task currentTask=deque.removeFirst();
            if(currentTask.time<=limit){
                time+=currentTask.time;
                System.out.println(String.format("%s %d",currentTask.name,time));
            }else{
                currentTask.time=currentTask.time-limit;
                deque.addLast(currentTask);
                time+=limit;
            }
        }
    }
    public static class Task{
        public String name;
        public int time;
        public Task(String name,int time){
            this.name=name;
            this.time=time;
        }
    }
} Main public static void main(String[] args) {
	// write your code here
        Scanner scanner=new Scanner(System.in);
        Deque<Task> deque=new ArrayDeque<>();
        long time=0;
        int n=scanner.nextInt();
        final int limit=scanner.nextInt();
        for(int i=0;i<n;i++){
            deque.addLast(new Task(scanner.next(),scanner.nextInt()));
        }
        while(deque.size()>0){
            Task currentTask=deque.removeFirst();
            if(currentTask.time<=limit){
                time+=currentTask.time;
                System.out.println(String.format("%s %d",currentTask.name,time));
            }else{
                currentTask.time=currentTask.time-limit;
                deque.addLast(currentTask);
                time+=limit;
            }
        }
    } main {
	// write your code here
        Scanner scanner=new Scanner(System.in);
        Deque<Task> deque=new ArrayDeque<>();
        long time=0;
        int n=scanner.nextInt();
        final int limit=scanner.nextInt();
        for(int i=0;i<n;i++){
            deque.addLast(new Task(scanner.next(),scanner.nextInt()));
        }
        while(deque.size()>0){
            Task currentTask=deque.removeFirst();
            if(currentTask.time<=limit){
                time+=currentTask.time;
                System.out.println(String.format("%s %d",currentTask.name,time));
            }else{
                currentTask.time=currentTask.time-limit;
                deque.addLast(currentTask);
                time+=limit;
            }
        }
    } Scanner scanner=new Scanner(System.in); scanner new Scanner(System.in) Deque<Task> deque=new ArrayDeque<>(); deque new ArrayDeque<>() long time=0; time 0 int n=scanner.nextInt(); n scanner.nextInt() scanner.nextInt scanner final int limit=scanner.nextInt(); limit scanner.nextInt() scanner.nextInt scanner for(int i=0;i<n;i++){
            deque.addLast(new Task(scanner.next(),scanner.nextInt()));
        } int i=0; int i=0; i 0 i<n i n i++ i++ i {
            deque.addLast(new Task(scanner.next(),scanner.nextInt()));
        } {
            deque.addLast(new Task(scanner.next(),scanner.nextInt()));
        } deque.addLast(new Task(scanner.next(),scanner.nextInt())) deque.addLast deque new Task(scanner.next(),scanner.nextInt()) while(deque.size()>0){
            Task currentTask=deque.removeFirst();
            if(currentTask.time<=limit){
                time+=currentTask.time;
                System.out.println(String.format("%s %d",currentTask.name,time));
            }else{
                currentTask.time=currentTask.time-limit;
                deque.addLast(currentTask);
                time+=limit;
            }
        } deque.size()>0 deque.size() deque.size deque 0 {
            Task currentTask=deque.removeFirst();
            if(currentTask.time<=limit){
                time+=currentTask.time;
                System.out.println(String.format("%s %d",currentTask.name,time));
            }else{
                currentTask.time=currentTask.time-limit;
                deque.addLast(currentTask);
                time+=limit;
            }
        } Task currentTask=deque.removeFirst(); currentTask deque.removeFirst() deque.removeFirst deque if(currentTask.time<=limit){
                time+=currentTask.time;
                System.out.println(String.format("%s %d",currentTask.name,time));
            }else{
                currentTask.time=currentTask.time-limit;
                deque.addLast(currentTask);
                time+=limit;
            } currentTask.time<=limit currentTask.time currentTask currentTask.time limit {
                time+=currentTask.time;
                System.out.println(String.format("%s %d",currentTask.name,time));
            } time+=currentTask.time time currentTask.time currentTask currentTask.time System.out.println(String.format("%s %d",currentTask.name,time)) System.out.println System.out System System.out String.format("%s %d",currentTask.name,time) String.format String "%s %d" currentTask.name currentTask currentTask.name time {
                currentTask.time=currentTask.time-limit;
                deque.addLast(currentTask);
                time+=limit;
            } currentTask.time=currentTask.time-limit currentTask.time currentTask currentTask.time currentTask.time-limit currentTask.time currentTask currentTask.time limit deque.addLast(currentTask) deque.addLast deque currentTask time+=limit time limit String[] args args public static class Task{
        public String name;
        public int time;
        public Task(String name,int time){
            this.name=name;
            this.time=time;
        }
    } Task public String name; name public int time; time public Task(String name,int time){
            this.name=name;
            this.time=time;
        } Task {
            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 class Main {

    public static void main(String[] args) {
	// write your code here
        Scanner scanner=new Scanner(System.in);
        Deque<Task> deque=new ArrayDeque<>();
        long time=0;
        int n=scanner.nextInt();
        final int limit=scanner.nextInt();
        for(int i=0;i<n;i++){
            deque.addLast(new Task(scanner.next(),scanner.nextInt()));
        }
        while(deque.size()>0){
            Task currentTask=deque.removeFirst();
            if(currentTask.time<=limit){
                time+=currentTask.time;
                System.out.println(String.format("%s %d",currentTask.name,time));
            }else{
                currentTask.time=currentTask.time-limit;
                deque.addLast(currentTask);
                time+=limit;
            }
        }
    }
    public static class Task{
        public String name;
        public int time;
        public Task(String name,int time){
            this.name=name;
            this.time=time;
        }
    }
} public class Main {

    public static void main(String[] args) {
	// write your code here
        Scanner scanner=new Scanner(System.in);
        Deque<Task> deque=new ArrayDeque<>();
        long time=0;
        int n=scanner.nextInt();
        final int limit=scanner.nextInt();
        for(int i=0;i<n;i++){
            deque.addLast(new Task(scanner.next(),scanner.nextInt()));
        }
        while(deque.size()>0){
            Task currentTask=deque.removeFirst();
            if(currentTask.time<=limit){
                time+=currentTask.time;
                System.out.println(String.format("%s %d",currentTask.name,time));
            }else{
                currentTask.time=currentTask.time-limit;
                deque.addLast(currentTask);
                time+=limit;
            }
        }
    }
    public static class Task{
        public String name;
        public int time;
        public Task(String name,int time){
            this.name=name;
            this.time=time;
        }
    }
} Main

import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
	// write your code here
        Scanner scanner=new Scanner(System.in);
        Deque<Task> deque=new ArrayDeque<>();
        long time=0;
        int n=scanner.nextInt();
        final int limit=scanner.nextInt();
        for(int i=0;i<n;i++){
            deque.addLast(new Task(scanner.next(),scanner.nextInt()));
        }
        while(deque.size()>0){
            Task currentTask=deque.removeFirst();
            if(currentTask.time<=limit){
                time+=currentTask.time;
                System.out.println(String.format("%s %d",currentTask.name,time));
            }else{
                currentTask.time=currentTask.time-limit;
                deque.addLast(currentTask);
                time+=limit;
            }
        }
    }
    public static class Task{
        public String name;
        public int time;
        public Task(String name,int time){
            this.name=name;
            this.time=time;
        }
    }
}

