import java.util.*;

public class Main {
    static int head = 0;
    static int tail = 0;
    static final int MAX = 100000;
    static int[] Q = new int[MAX];
    static int NOW = 0;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        LinkedList<String> name = new LinkedList<>();
        for (int i = 0; i < n; i++) {
            name.offer(sc.next());
            enqueue(sc.nextInt());
        }

        ArrayList<String> ansName = new ArrayList<>();
        ArrayList<Integer> ansTime = new ArrayList<>();
        String tmpName;
        int tmpTime;

        while(!isEmpty()){
            tmpName = name.poll();
            tmpTime = dequeue();
            if(tmpTime <= q){
                NOW += tmpTime;
                ansName.add(tmpName);
                ansTime.add(NOW);
            }else{
                NOW += q;
                name.offer(tmpName);
                tmpTime -= q;
                enqueue(tmpTime);
            }
        }

        for (int i = 0; i < n; i++) {
            System.out.println(ansName.get(i) + " " + ansTime.get(i));
        }
    }

    static Boolean isEmpty(){
        return head == tail;
    }

    static void enqueue(int x){
        Q[tail] = x;
        if(tail + 1 == MAX){
            tail = 0;
        }else{
            tail ++;
        }
    }

    static int dequeue(){
        int x = Q[head];
        if(head + 1 == MAX){
            head = 0;
        }else {
            head++;
        }
        return x;
    }
}
 import java.util.*; util.* java public class Main {
    static int head = 0;
    static int tail = 0;
    static final int MAX = 100000;
    static int[] Q = new int[MAX];
    static int NOW = 0;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        LinkedList<String> name = new LinkedList<>();
        for (int i = 0; i < n; i++) {
            name.offer(sc.next());
            enqueue(sc.nextInt());
        }

        ArrayList<String> ansName = new ArrayList<>();
        ArrayList<Integer> ansTime = new ArrayList<>();
        String tmpName;
        int tmpTime;

        while(!isEmpty()){
            tmpName = name.poll();
            tmpTime = dequeue();
            if(tmpTime <= q){
                NOW += tmpTime;
                ansName.add(tmpName);
                ansTime.add(NOW);
            }else{
                NOW += q;
                name.offer(tmpName);
                tmpTime -= q;
                enqueue(tmpTime);
            }
        }

        for (int i = 0; i < n; i++) {
            System.out.println(ansName.get(i) + " " + ansTime.get(i));
        }
    }

    static Boolean isEmpty(){
        return head == tail;
    }

    static void enqueue(int x){
        Q[tail] = x;
        if(tail + 1 == MAX){
            tail = 0;
        }else{
            tail ++;
        }
    }

    static int dequeue(){
        int x = Q[head];
        if(head + 1 == MAX){
            head = 0;
        }else {
            head++;
        }
        return x;
    }
} Main static int head = 0; head 0 static int tail = 0; tail 0 static final int MAX = 100000; MAX 100000 static int[] Q = new int[MAX]; Q new int[MAX] MAX static int NOW = 0; NOW 0 public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        LinkedList<String> name = new LinkedList<>();
        for (int i = 0; i < n; i++) {
            name.offer(sc.next());
            enqueue(sc.nextInt());
        }

        ArrayList<String> ansName = new ArrayList<>();
        ArrayList<Integer> ansTime = new ArrayList<>();
        String tmpName;
        int tmpTime;

        while(!isEmpty()){
            tmpName = name.poll();
            tmpTime = dequeue();
            if(tmpTime <= q){
                NOW += tmpTime;
                ansName.add(tmpName);
                ansTime.add(NOW);
            }else{
                NOW += q;
                name.offer(tmpName);
                tmpTime -= q;
                enqueue(tmpTime);
            }
        }

        for (int i = 0; i < n; i++) {
            System.out.println(ansName.get(i) + " " + ansTime.get(i));
        }
    } main {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        LinkedList<String> name = new LinkedList<>();
        for (int i = 0; i < n; i++) {
            name.offer(sc.next());
            enqueue(sc.nextInt());
        }

        ArrayList<String> ansName = new ArrayList<>();
        ArrayList<Integer> ansTime = new ArrayList<>();
        String tmpName;
        int tmpTime;

        while(!isEmpty()){
            tmpName = name.poll();
            tmpTime = dequeue();
            if(tmpTime <= q){
                NOW += tmpTime;
                ansName.add(tmpName);
                ansTime.add(NOW);
            }else{
                NOW += q;
                name.offer(tmpName);
                tmpTime -= q;
                enqueue(tmpTime);
            }
        }

        for (int i = 0; i < n; i++) {
            System.out.println(ansName.get(i) + " " + ansTime.get(i));
        }
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int q = sc.nextInt(); q sc.nextInt() sc.nextInt sc LinkedList<String> name = new LinkedList<>(); name new LinkedList<>() for (int i = 0; i < n; i++) {
            name.offer(sc.next());
            enqueue(sc.nextInt());
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            name.offer(sc.next());
            enqueue(sc.nextInt());
        } {
            name.offer(sc.next());
            enqueue(sc.nextInt());
        } name.offer(sc.next()) name.offer name sc.next() sc.next sc enqueue(sc.nextInt()) enqueue sc.nextInt() sc.nextInt sc ArrayList<String> ansName = new ArrayList<>(); ansName new ArrayList<>() ArrayList<Integer> ansTime = new ArrayList<>(); ansTime new ArrayList<>() String tmpName; tmpName int tmpTime; tmpTime while(!isEmpty()){
            tmpName = name.poll();
            tmpTime = dequeue();
            if(tmpTime <= q){
                NOW += tmpTime;
                ansName.add(tmpName);
                ansTime.add(NOW);
            }else{
                NOW += q;
                name.offer(tmpName);
                tmpTime -= q;
                enqueue(tmpTime);
            }
        } !isEmpty() isEmpty() isEmpty {
            tmpName = name.poll();
            tmpTime = dequeue();
            if(tmpTime <= q){
                NOW += tmpTime;
                ansName.add(tmpName);
                ansTime.add(NOW);
            }else{
                NOW += q;
                name.offer(tmpName);
                tmpTime -= q;
                enqueue(tmpTime);
            }
        } tmpName = name.poll() tmpName name.poll() name.poll name tmpTime = dequeue() tmpTime dequeue() dequeue if(tmpTime <= q){
                NOW += tmpTime;
                ansName.add(tmpName);
                ansTime.add(NOW);
            }else{
                NOW += q;
                name.offer(tmpName);
                tmpTime -= q;
                enqueue(tmpTime);
            } tmpTime <= q tmpTime q {
                NOW += tmpTime;
                ansName.add(tmpName);
                ansTime.add(NOW);
            } NOW += tmpTime NOW tmpTime ansName.add(tmpName) ansName.add ansName tmpName ansTime.add(NOW) ansTime.add ansTime NOW {
                NOW += q;
                name.offer(tmpName);
                tmpTime -= q;
                enqueue(tmpTime);
            } NOW += q NOW q name.offer(tmpName) name.offer name tmpName tmpTime -= q tmpTime q enqueue(tmpTime) enqueue tmpTime for (int i = 0; i < n; i++) {
            System.out.println(ansName.get(i) + " " + ansTime.get(i));
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            System.out.println(ansName.get(i) + " " + ansTime.get(i));
        } {
            System.out.println(ansName.get(i) + " " + ansTime.get(i));
        } System.out.println(ansName.get(i) + " " + ansTime.get(i)) System.out.println System.out System System.out ansName.get(i) + " " + ansTime.get(i) ansName.get(i) + " " + ansTime.get(i) ansName.get(i) ansName.get ansName i " " ansTime.get(i) ansTime.get ansTime i String[] args args static Boolean isEmpty(){
        return head == tail;
    } isEmpty {
        return head == tail;
    } return head == tail; head == tail head tail static void enqueue(int x){
        Q[tail] = x;
        if(tail + 1 == MAX){
            tail = 0;
        }else{
            tail ++;
        }
    } enqueue {
        Q[tail] = x;
        if(tail + 1 == MAX){
            tail = 0;
        }else{
            tail ++;
        }
    } Q[tail] = x Q[tail] Q tail x if(tail + 1 == MAX){
            tail = 0;
        }else{
            tail ++;
        } tail + 1 == MAX tail + 1 tail 1 MAX {
            tail = 0;
        } tail = 0 tail 0 {
            tail ++;
        } tail ++ tail int x x static int dequeue(){
        int x = Q[head];
        if(head + 1 == MAX){
            head = 0;
        }else {
            head++;
        }
        return x;
    } dequeue {
        int x = Q[head];
        if(head + 1 == MAX){
            head = 0;
        }else {
            head++;
        }
        return x;
    } int x = Q[head]; x Q[head] Q head if(head + 1 == MAX){
            head = 0;
        }else {
            head++;
        } head + 1 == MAX head + 1 head 1 MAX {
            head = 0;
        } head = 0 head 0 {
            head++;
        } head++ head return x; x public class Main {
    static int head = 0;
    static int tail = 0;
    static final int MAX = 100000;
    static int[] Q = new int[MAX];
    static int NOW = 0;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        LinkedList<String> name = new LinkedList<>();
        for (int i = 0; i < n; i++) {
            name.offer(sc.next());
            enqueue(sc.nextInt());
        }

        ArrayList<String> ansName = new ArrayList<>();
        ArrayList<Integer> ansTime = new ArrayList<>();
        String tmpName;
        int tmpTime;

        while(!isEmpty()){
            tmpName = name.poll();
            tmpTime = dequeue();
            if(tmpTime <= q){
                NOW += tmpTime;
                ansName.add(tmpName);
                ansTime.add(NOW);
            }else{
                NOW += q;
                name.offer(tmpName);
                tmpTime -= q;
                enqueue(tmpTime);
            }
        }

        for (int i = 0; i < n; i++) {
            System.out.println(ansName.get(i) + " " + ansTime.get(i));
        }
    }

    static Boolean isEmpty(){
        return head == tail;
    }

    static void enqueue(int x){
        Q[tail] = x;
        if(tail + 1 == MAX){
            tail = 0;
        }else{
            tail ++;
        }
    }

    static int dequeue(){
        int x = Q[head];
        if(head + 1 == MAX){
            head = 0;
        }else {
            head++;
        }
        return x;
    }
} public class Main {
    static int head = 0;
    static int tail = 0;
    static final int MAX = 100000;
    static int[] Q = new int[MAX];
    static int NOW = 0;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        LinkedList<String> name = new LinkedList<>();
        for (int i = 0; i < n; i++) {
            name.offer(sc.next());
            enqueue(sc.nextInt());
        }

        ArrayList<String> ansName = new ArrayList<>();
        ArrayList<Integer> ansTime = new ArrayList<>();
        String tmpName;
        int tmpTime;

        while(!isEmpty()){
            tmpName = name.poll();
            tmpTime = dequeue();
            if(tmpTime <= q){
                NOW += tmpTime;
                ansName.add(tmpName);
                ansTime.add(NOW);
            }else{
                NOW += q;
                name.offer(tmpName);
                tmpTime -= q;
                enqueue(tmpTime);
            }
        }

        for (int i = 0; i < n; i++) {
            System.out.println(ansName.get(i) + " " + ansTime.get(i));
        }
    }

    static Boolean isEmpty(){
        return head == tail;
    }

    static void enqueue(int x){
        Q[tail] = x;
        if(tail + 1 == MAX){
            tail = 0;
        }else{
            tail ++;
        }
    }

    static int dequeue(){
        int x = Q[head];
        if(head + 1 == MAX){
            head = 0;
        }else {
            head++;
        }
        return x;
    }
} Main
import java.util.*;

public class Main {
    static int head = 0;
    static int tail = 0;
    static final int MAX = 100000;
    static int[] Q = new int[MAX];
    static int NOW = 0;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        LinkedList<String> name = new LinkedList<>();
        for (int i = 0; i < n; i++) {
            name.offer(sc.next());
            enqueue(sc.nextInt());
        }

        ArrayList<String> ansName = new ArrayList<>();
        ArrayList<Integer> ansTime = new ArrayList<>();
        String tmpName;
        int tmpTime;

        while(!isEmpty()){
            tmpName = name.poll();
            tmpTime = dequeue();
            if(tmpTime <= q){
                NOW += tmpTime;
                ansName.add(tmpName);
                ansTime.add(NOW);
            }else{
                NOW += q;
                name.offer(tmpName);
                tmpTime -= q;
                enqueue(tmpTime);
            }
        }

        for (int i = 0; i < n; i++) {
            System.out.println(ansName.get(i) + " " + ansTime.get(i));
        }
    }

    static Boolean isEmpty(){
        return head == tail;
    }

    static void enqueue(int x){
        Q[tail] = x;
        if(tail + 1 == MAX){
            tail = 0;
        }else{
            tail ++;
        }
    }

    static int dequeue(){
        int x = Q[head];
        if(head + 1 == MAX){
            head = 0;
        }else {
            head++;
        }
        return x;
    }
}

