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

public class Main {
    public static void main(String[] args) {
        Scanner sca = new Scanner(System.in);
        int n = sca.nextInt();
        Deque<Integer> quu = new LinkedList<>();
        Deque<String> name = new LinkedList<>();
        int hour = 0;
        
        int qa = sca.nextInt();
        int K = 0;
        while (K < n) {
            name.add(sca.next());
            quu.add(sca.nextInt());
             ++K;
        }
        while (quu.size() > 0) {
            
            quu.addLast(quu.poll() - qa);
            name.addLast(name.poll());
            hour += qa;
            
            if (quu.peekLast() <= 0) {
                hour += quu.pollLast();;
                System.out.println(name.pollLast() + " " + hour);
            }
        }
    }
} import java.util.Deque; Deque java.util import java.util.LinkedList; LinkedList java.util import java.util.Scanner; Scanner java.util import java.util.ArrayDeque; ArrayDeque java.util import java.util.*; util.* java public class Main {
    public static void main(String[] args) {
        Scanner sca = new Scanner(System.in);
        int n = sca.nextInt();
        Deque<Integer> quu = new LinkedList<>();
        Deque<String> name = new LinkedList<>();
        int hour = 0;
        
        int qa = sca.nextInt();
        int K = 0;
        while (K < n) {
            name.add(sca.next());
            quu.add(sca.nextInt());
             ++K;
        }
        while (quu.size() > 0) {
            
            quu.addLast(quu.poll() - qa);
            name.addLast(name.poll());
            hour += qa;
            
            if (quu.peekLast() <= 0) {
                hour += quu.pollLast();;
                System.out.println(name.pollLast() + " " + hour);
            }
        }
    }
} Main public static void main(String[] args) {
        Scanner sca = new Scanner(System.in);
        int n = sca.nextInt();
        Deque<Integer> quu = new LinkedList<>();
        Deque<String> name = new LinkedList<>();
        int hour = 0;
        
        int qa = sca.nextInt();
        int K = 0;
        while (K < n) {
            name.add(sca.next());
            quu.add(sca.nextInt());
             ++K;
        }
        while (quu.size() > 0) {
            
            quu.addLast(quu.poll() - qa);
            name.addLast(name.poll());
            hour += qa;
            
            if (quu.peekLast() <= 0) {
                hour += quu.pollLast();;
                System.out.println(name.pollLast() + " " + hour);
            }
        }
    } main {
        Scanner sca = new Scanner(System.in);
        int n = sca.nextInt();
        Deque<Integer> quu = new LinkedList<>();
        Deque<String> name = new LinkedList<>();
        int hour = 0;
        
        int qa = sca.nextInt();
        int K = 0;
        while (K < n) {
            name.add(sca.next());
            quu.add(sca.nextInt());
             ++K;
        }
        while (quu.size() > 0) {
            
            quu.addLast(quu.poll() - qa);
            name.addLast(name.poll());
            hour += qa;
            
            if (quu.peekLast() <= 0) {
                hour += quu.pollLast();;
                System.out.println(name.pollLast() + " " + hour);
            }
        }
    } Scanner sca = new Scanner(System.in); sca new Scanner(System.in) int n = sca.nextInt(); n sca.nextInt() sca.nextInt sca Deque<Integer> quu = new LinkedList<>(); quu new LinkedList<>() Deque<String> name = new LinkedList<>(); name new LinkedList<>() int hour = 0; hour 0 int qa = sca.nextInt(); qa sca.nextInt() sca.nextInt sca int K = 0; K 0 while (K < n) {
            name.add(sca.next());
            quu.add(sca.nextInt());
             ++K;
        } K < n K n {
            name.add(sca.next());
            quu.add(sca.nextInt());
             ++K;
        } name.add(sca.next()) name.add name sca.next() sca.next sca quu.add(sca.nextInt()) quu.add quu sca.nextInt() sca.nextInt sca ++K K while (quu.size() > 0) {
            
            quu.addLast(quu.poll() - qa);
            name.addLast(name.poll());
            hour += qa;
            
            if (quu.peekLast() <= 0) {
                hour += quu.pollLast();;
                System.out.println(name.pollLast() + " " + hour);
            }
        } quu.size() > 0 quu.size() quu.size quu 0 {
            
            quu.addLast(quu.poll() - qa);
            name.addLast(name.poll());
            hour += qa;
            
            if (quu.peekLast() <= 0) {
                hour += quu.pollLast();;
                System.out.println(name.pollLast() + " " + hour);
            }
        } quu.addLast(quu.poll() - qa) quu.addLast quu quu.poll() - qa quu.poll() quu.poll quu qa name.addLast(name.poll()) name.addLast name name.poll() name.poll name hour += qa hour qa if (quu.peekLast() <= 0) {
                hour += quu.pollLast();;
                System.out.println(name.pollLast() + " " + hour);
            } quu.peekLast() <= 0 quu.peekLast() quu.peekLast quu 0 {
                hour += quu.pollLast();;
                System.out.println(name.pollLast() + " " + hour);
            } hour += quu.pollLast() hour quu.pollLast() quu.pollLast quu System.out.println(name.pollLast() + " " + hour) System.out.println System.out System System.out name.pollLast() + " " + hour name.pollLast() + " " + hour name.pollLast() name.pollLast name " " hour String[] args args public class Main {
    public static void main(String[] args) {
        Scanner sca = new Scanner(System.in);
        int n = sca.nextInt();
        Deque<Integer> quu = new LinkedList<>();
        Deque<String> name = new LinkedList<>();
        int hour = 0;
        
        int qa = sca.nextInt();
        int K = 0;
        while (K < n) {
            name.add(sca.next());
            quu.add(sca.nextInt());
             ++K;
        }
        while (quu.size() > 0) {
            
            quu.addLast(quu.poll() - qa);
            name.addLast(name.poll());
            hour += qa;
            
            if (quu.peekLast() <= 0) {
                hour += quu.pollLast();;
                System.out.println(name.pollLast() + " " + hour);
            }
        }
    }
} public class Main {
    public static void main(String[] args) {
        Scanner sca = new Scanner(System.in);
        int n = sca.nextInt();
        Deque<Integer> quu = new LinkedList<>();
        Deque<String> name = new LinkedList<>();
        int hour = 0;
        
        int qa = sca.nextInt();
        int K = 0;
        while (K < n) {
            name.add(sca.next());
            quu.add(sca.nextInt());
             ++K;
        }
        while (quu.size() > 0) {
            
            quu.addLast(quu.poll() - qa);
            name.addLast(name.poll());
            hour += qa;
            
            if (quu.peekLast() <= 0) {
                hour += quu.pollLast();;
                System.out.println(name.pollLast() + " " + hour);
            }
        }
    }
} Main
import java.util.Deque;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.ArrayDeque;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sca = new Scanner(System.in);
        int n = sca.nextInt();
        Deque<Integer> quu = new LinkedList<>();
        Deque<String> name = new LinkedList<>();
        int hour = 0;
        
        int qa = sca.nextInt();
        int K = 0;
        while (K < n) {
            name.add(sca.next());
            quu.add(sca.nextInt());
             ++K;
        }
        while (quu.size() > 0) {
            
            quu.addLast(quu.poll() - qa);
            name.addLast(name.poll());
            hour += qa;
            
            if (quu.peekLast() <= 0) {
                hour += quu.pollLast();;
                System.out.println(name.pollLast() + " " + hour);
            }
        }
    }
}
