import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static int quantum;
    public static int currentTime = 0;
    public Main() {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int quantum = scan.nextInt();

        Queue queue = new Queue(100000 + n);
        this.quantum = quantum;

        while(scan.hasNext()){
            String pName = scan.next();
            int time = scan.nextInt();
            queue.enqueue(new Data(pName, time));
        }
        while(!queue.isEmpty()){
            Data data = queue.dequeue();
            if(data.time == 0){
                System.out.println(data.pName + " " + currentTime);
            }
        }
    }

    public static void main(String[] args) {
        new Main();
    }

    private class Queue{
        private int head = 0;
        private int tail = 0;
        private Data queue[];

        public Queue(int size){
            queue = new Data[size*2];
        }

        public void enqueue(Data data){
            queue[tail++] = data;
        }

        public Data dequeue(){
            Data data = queue[head++];
            int time = expendedTime(data);
            if(data.time != 0){
                enqueue(data);
            }
            currentTime += time;
            return data;
        }

        public int expendedTime(Data data){
            int time;
            if(data.time > quantum){
                time = quantum;
                data.time -= quantum;
            }else{
                time = data.time;
                data.time = 0;
            }
            return time;
        }

        public boolean isEmpty(){
            return head == tail;
        }

    }

    private class Data{
        public String pName;
        public int time;

        public Data(String pName, int time){
            this.pName = pName;
            this.time = time;
        }
    }
} import java.util.Arrays; Arrays java.util import java.util.Scanner; Scanner java.util public class Main {
    public static int quantum;
    public static int currentTime = 0;
    public Main() {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int quantum = scan.nextInt();

        Queue queue = new Queue(100000 + n);
        this.quantum = quantum;

        while(scan.hasNext()){
            String pName = scan.next();
            int time = scan.nextInt();
            queue.enqueue(new Data(pName, time));
        }
        while(!queue.isEmpty()){
            Data data = queue.dequeue();
            if(data.time == 0){
                System.out.println(data.pName + " " + currentTime);
            }
        }
    }

    public static void main(String[] args) {
        new Main();
    }

    private class Queue{
        private int head = 0;
        private int tail = 0;
        private Data queue[];

        public Queue(int size){
            queue = new Data[size*2];
        }

        public void enqueue(Data data){
            queue[tail++] = data;
        }

        public Data dequeue(){
            Data data = queue[head++];
            int time = expendedTime(data);
            if(data.time != 0){
                enqueue(data);
            }
            currentTime += time;
            return data;
        }

        public int expendedTime(Data data){
            int time;
            if(data.time > quantum){
                time = quantum;
                data.time -= quantum;
            }else{
                time = data.time;
                data.time = 0;
            }
            return time;
        }

        public boolean isEmpty(){
            return head == tail;
        }

    }

    private class Data{
        public String pName;
        public int time;

        public Data(String pName, int time){
            this.pName = pName;
            this.time = time;
        }
    }
} Main public static int quantum; quantum public static int currentTime = 0; currentTime 0 public Main() {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int quantum = scan.nextInt();

        Queue queue = new Queue(100000 + n);
        this.quantum = quantum;

        while(scan.hasNext()){
            String pName = scan.next();
            int time = scan.nextInt();
            queue.enqueue(new Data(pName, time));
        }
        while(!queue.isEmpty()){
            Data data = queue.dequeue();
            if(data.time == 0){
                System.out.println(data.pName + " " + currentTime);
            }
        }
    } Main {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int quantum = scan.nextInt();

        Queue queue = new Queue(100000 + n);
        this.quantum = quantum;

        while(scan.hasNext()){
            String pName = scan.next();
            int time = scan.nextInt();
            queue.enqueue(new Data(pName, time));
        }
        while(!queue.isEmpty()){
            Data data = queue.dequeue();
            if(data.time == 0){
                System.out.println(data.pName + " " + currentTime);
            }
        }
    } Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int n = scan.nextInt(); n scan.nextInt() scan.nextInt scan int quantum = scan.nextInt(); quantum scan.nextInt() scan.nextInt scan Queue queue = new Queue(100000 + n); queue new Queue(100000 + n) this.quantum = quantum this.quantum this this.quantum quantum while(scan.hasNext()){
            String pName = scan.next();
            int time = scan.nextInt();
            queue.enqueue(new Data(pName, time));
        } scan.hasNext() scan.hasNext scan {
            String pName = scan.next();
            int time = scan.nextInt();
            queue.enqueue(new Data(pName, time));
        } String pName = scan.next(); pName scan.next() scan.next scan int time = scan.nextInt(); time scan.nextInt() scan.nextInt scan queue.enqueue(new Data(pName, time)) queue.enqueue queue new Data(pName, time) while(!queue.isEmpty()){
            Data data = queue.dequeue();
            if(data.time == 0){
                System.out.println(data.pName + " " + currentTime);
            }
        } !queue.isEmpty() queue.isEmpty() queue.isEmpty queue {
            Data data = queue.dequeue();
            if(data.time == 0){
                System.out.println(data.pName + " " + currentTime);
            }
        } Data data = queue.dequeue(); data queue.dequeue() queue.dequeue queue if(data.time == 0){
                System.out.println(data.pName + " " + currentTime);
            } data.time == 0 data.time data data.time 0 {
                System.out.println(data.pName + " " + currentTime);
            } System.out.println(data.pName + " " + currentTime) System.out.println System.out System System.out data.pName + " " + currentTime data.pName + " " + currentTime data.pName data data.pName " " currentTime public static void main(String[] args) {
        new Main();
    } main {
        new Main();
    } new Main() String[] args args private class Queue{
        private int head = 0;
        private int tail = 0;
        private Data queue[];

        public Queue(int size){
            queue = new Data[size*2];
        }

        public void enqueue(Data data){
            queue[tail++] = data;
        }

        public Data dequeue(){
            Data data = queue[head++];
            int time = expendedTime(data);
            if(data.time != 0){
                enqueue(data);
            }
            currentTime += time;
            return data;
        }

        public int expendedTime(Data data){
            int time;
            if(data.time > quantum){
                time = quantum;
                data.time -= quantum;
            }else{
                time = data.time;
                data.time = 0;
            }
            return time;
        }

        public boolean isEmpty(){
            return head == tail;
        }

    } Queue private int head = 0; head 0 private int tail = 0; tail 0 private Data queue[]; queue public Queue(int size){
            queue = new Data[size*2];
        } Queue {
            queue = new Data[size*2];
        } queue = new Data[size*2] queue new Data[size*2] size*2 size 2 int size size public void enqueue(Data data){
            queue[tail++] = data;
        } enqueue {
            queue[tail++] = data;
        } queue[tail++] = data queue[tail++] queue tail++ tail data Data data data public Data dequeue(){
            Data data = queue[head++];
            int time = expendedTime(data);
            if(data.time != 0){
                enqueue(data);
            }
            currentTime += time;
            return data;
        } dequeue {
            Data data = queue[head++];
            int time = expendedTime(data);
            if(data.time != 0){
                enqueue(data);
            }
            currentTime += time;
            return data;
        } Data data = queue[head++]; data queue[head++] queue head++ head int time = expendedTime(data); time expendedTime(data) expendedTime data if(data.time != 0){
                enqueue(data);
            } data.time != 0 data.time data data.time 0 {
                enqueue(data);
            } enqueue(data) enqueue data currentTime += time currentTime time return data; data public int expendedTime(Data data){
            int time;
            if(data.time > quantum){
                time = quantum;
                data.time -= quantum;
            }else{
                time = data.time;
                data.time = 0;
            }
            return time;
        } expendedTime {
            int time;
            if(data.time > quantum){
                time = quantum;
                data.time -= quantum;
            }else{
                time = data.time;
                data.time = 0;
            }
            return time;
        } int time; time if(data.time > quantum){
                time = quantum;
                data.time -= quantum;
            }else{
                time = data.time;
                data.time = 0;
            } data.time > quantum data.time data data.time quantum {
                time = quantum;
                data.time -= quantum;
            } time = quantum time quantum data.time -= quantum data.time data data.time quantum {
                time = data.time;
                data.time = 0;
            } time = data.time time data.time data data.time data.time = 0 data.time data data.time 0 return time; time Data data data public boolean isEmpty(){
            return head == tail;
        } isEmpty {
            return head == tail;
        } return head == tail; head == tail head tail private class Data{
        public String pName;
        public int time;

        public Data(String pName, int time){
            this.pName = pName;
            this.time = time;
        }
    } Data public String pName; pName public int time; time public Data(String pName, int time){
            this.pName = pName;
            this.time = time;
        } Data {
            this.pName = pName;
            this.time = time;
        } this.pName = pName this.pName this this.pName pName this.time = time this.time this this.time time String pName pName int time time public class Main {
    public static int quantum;
    public static int currentTime = 0;
    public Main() {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int quantum = scan.nextInt();

        Queue queue = new Queue(100000 + n);
        this.quantum = quantum;

        while(scan.hasNext()){
            String pName = scan.next();
            int time = scan.nextInt();
            queue.enqueue(new Data(pName, time));
        }
        while(!queue.isEmpty()){
            Data data = queue.dequeue();
            if(data.time == 0){
                System.out.println(data.pName + " " + currentTime);
            }
        }
    }

    public static void main(String[] args) {
        new Main();
    }

    private class Queue{
        private int head = 0;
        private int tail = 0;
        private Data queue[];

        public Queue(int size){
            queue = new Data[size*2];
        }

        public void enqueue(Data data){
            queue[tail++] = data;
        }

        public Data dequeue(){
            Data data = queue[head++];
            int time = expendedTime(data);
            if(data.time != 0){
                enqueue(data);
            }
            currentTime += time;
            return data;
        }

        public int expendedTime(Data data){
            int time;
            if(data.time > quantum){
                time = quantum;
                data.time -= quantum;
            }else{
                time = data.time;
                data.time = 0;
            }
            return time;
        }

        public boolean isEmpty(){
            return head == tail;
        }

    }

    private class Data{
        public String pName;
        public int time;

        public Data(String pName, int time){
            this.pName = pName;
            this.time = time;
        }
    }
} public class Main {
    public static int quantum;
    public static int currentTime = 0;
    public Main() {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int quantum = scan.nextInt();

        Queue queue = new Queue(100000 + n);
        this.quantum = quantum;

        while(scan.hasNext()){
            String pName = scan.next();
            int time = scan.nextInt();
            queue.enqueue(new Data(pName, time));
        }
        while(!queue.isEmpty()){
            Data data = queue.dequeue();
            if(data.time == 0){
                System.out.println(data.pName + " " + currentTime);
            }
        }
    }

    public static void main(String[] args) {
        new Main();
    }

    private class Queue{
        private int head = 0;
        private int tail = 0;
        private Data queue[];

        public Queue(int size){
            queue = new Data[size*2];
        }

        public void enqueue(Data data){
            queue[tail++] = data;
        }

        public Data dequeue(){
            Data data = queue[head++];
            int time = expendedTime(data);
            if(data.time != 0){
                enqueue(data);
            }
            currentTime += time;
            return data;
        }

        public int expendedTime(Data data){
            int time;
            if(data.time > quantum){
                time = quantum;
                data.time -= quantum;
            }else{
                time = data.time;
                data.time = 0;
            }
            return time;
        }

        public boolean isEmpty(){
            return head == tail;
        }

    }

    private class Data{
        public String pName;
        public int time;

        public Data(String pName, int time){
            this.pName = pName;
            this.time = time;
        }
    }
} Main
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static int quantum;
    public static int currentTime = 0;
    public Main() {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int quantum = scan.nextInt();

        Queue queue = new Queue(100000 + n);
        this.quantum = quantum;

        while(scan.hasNext()){
            String pName = scan.next();
            int time = scan.nextInt();
            queue.enqueue(new Data(pName, time));
        }
        while(!queue.isEmpty()){
            Data data = queue.dequeue();
            if(data.time == 0){
                System.out.println(data.pName + " " + currentTime);
            }
        }
    }

    public static void main(String[] args) {
        new Main();
    }

    private class Queue{
        private int head = 0;
        private int tail = 0;
        private Data queue[];

        public Queue(int size){
            queue = new Data[size*2];
        }

        public void enqueue(Data data){
            queue[tail++] = data;
        }

        public Data dequeue(){
            Data data = queue[head++];
            int time = expendedTime(data);
            if(data.time != 0){
                enqueue(data);
            }
            currentTime += time;
            return data;
        }

        public int expendedTime(Data data){
            int time;
            if(data.time > quantum){
                time = quantum;
                data.time -= quantum;
            }else{
                time = data.time;
                data.time = 0;
            }
            return time;
        }

        public boolean isEmpty(){
            return head == tail;
        }

    }

    private class Data{
        public String pName;
        public int time;

        public Data(String pName, int time){
            this.pName = pName;
            this.time = time;
        }
    }
}