import java.util.*;

public class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int timenow = 0;
        int n = sc.nextInt();
        int q = sc.nextInt();
        String[] names = new String[n];
        int[] times = new int[n];
        LinkedList<Integer> queue = new LinkedList<Integer>();
        for (int i = 0; i < n; i++){
            names[i] = sc.next();
            times[i] = sc.nextInt();
            queue.add(i);
        }
        while (queue.size()!=0){
            int p = queue.poll();
            if (times[p]>q) {
                times[p] -= q;
                queue.add(p);
                timenow += q;
            } else {
                timenow += times[p];
                System.out.println(names[p]+" "+timenow);
            }
        }
    }
} import java.util.*; util.* java public class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int timenow = 0;
        int n = sc.nextInt();
        int q = sc.nextInt();
        String[] names = new String[n];
        int[] times = new int[n];
        LinkedList<Integer> queue = new LinkedList<Integer>();
        for (int i = 0; i < n; i++){
            names[i] = sc.next();
            times[i] = sc.nextInt();
            queue.add(i);
        }
        while (queue.size()!=0){
            int p = queue.poll();
            if (times[p]>q) {
                times[p] -= q;
                queue.add(p);
                timenow += q;
            } else {
                timenow += times[p];
                System.out.println(names[p]+" "+timenow);
            }
        }
    }
} Main public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int timenow = 0;
        int n = sc.nextInt();
        int q = sc.nextInt();
        String[] names = new String[n];
        int[] times = new int[n];
        LinkedList<Integer> queue = new LinkedList<Integer>();
        for (int i = 0; i < n; i++){
            names[i] = sc.next();
            times[i] = sc.nextInt();
            queue.add(i);
        }
        while (queue.size()!=0){
            int p = queue.poll();
            if (times[p]>q) {
                times[p] -= q;
                queue.add(p);
                timenow += q;
            } else {
                timenow += times[p];
                System.out.println(names[p]+" "+timenow);
            }
        }
    } main {
        Scanner sc = new Scanner(System.in);
        int timenow = 0;
        int n = sc.nextInt();
        int q = sc.nextInt();
        String[] names = new String[n];
        int[] times = new int[n];
        LinkedList<Integer> queue = new LinkedList<Integer>();
        for (int i = 0; i < n; i++){
            names[i] = sc.next();
            times[i] = sc.nextInt();
            queue.add(i);
        }
        while (queue.size()!=0){
            int p = queue.poll();
            if (times[p]>q) {
                times[p] -= q;
                queue.add(p);
                timenow += q;
            } else {
                timenow += times[p];
                System.out.println(names[p]+" "+timenow);
            }
        }
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int timenow = 0; timenow 0 int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int q = sc.nextInt(); q sc.nextInt() sc.nextInt sc String[] names = new String[n]; names new String[n] n int[] times = new int[n]; times new int[n] n LinkedList<Integer> queue = new LinkedList<Integer>(); queue new LinkedList<Integer>() for (int i = 0; i < n; i++){
            names[i] = sc.next();
            times[i] = sc.nextInt();
            queue.add(i);
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            names[i] = sc.next();
            times[i] = sc.nextInt();
            queue.add(i);
        } {
            names[i] = sc.next();
            times[i] = sc.nextInt();
            queue.add(i);
        } names[i] = sc.next() names[i] names i sc.next() sc.next sc times[i] = sc.nextInt() times[i] times i sc.nextInt() sc.nextInt sc queue.add(i) queue.add queue i while (queue.size()!=0){
            int p = queue.poll();
            if (times[p]>q) {
                times[p] -= q;
                queue.add(p);
                timenow += q;
            } else {
                timenow += times[p];
                System.out.println(names[p]+" "+timenow);
            }
        } queue.size()!=0 queue.size() queue.size queue 0 {
            int p = queue.poll();
            if (times[p]>q) {
                times[p] -= q;
                queue.add(p);
                timenow += q;
            } else {
                timenow += times[p];
                System.out.println(names[p]+" "+timenow);
            }
        } int p = queue.poll(); p queue.poll() queue.poll queue if (times[p]>q) {
                times[p] -= q;
                queue.add(p);
                timenow += q;
            } else {
                timenow += times[p];
                System.out.println(names[p]+" "+timenow);
            } times[p]>q times[p] times p q {
                times[p] -= q;
                queue.add(p);
                timenow += q;
            } times[p] -= q times[p] times p q queue.add(p) queue.add queue p timenow += q timenow q {
                timenow += times[p];
                System.out.println(names[p]+" "+timenow);
            } timenow += times[p] timenow times[p] times p System.out.println(names[p]+" "+timenow) System.out.println System.out System System.out names[p]+" "+timenow names[p]+" "+timenow names[p] names p " " timenow String args[] args public class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int timenow = 0;
        int n = sc.nextInt();
        int q = sc.nextInt();
        String[] names = new String[n];
        int[] times = new int[n];
        LinkedList<Integer> queue = new LinkedList<Integer>();
        for (int i = 0; i < n; i++){
            names[i] = sc.next();
            times[i] = sc.nextInt();
            queue.add(i);
        }
        while (queue.size()!=0){
            int p = queue.poll();
            if (times[p]>q) {
                times[p] -= q;
                queue.add(p);
                timenow += q;
            } else {
                timenow += times[p];
                System.out.println(names[p]+" "+timenow);
            }
        }
    }
} public class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int timenow = 0;
        int n = sc.nextInt();
        int q = sc.nextInt();
        String[] names = new String[n];
        int[] times = new int[n];
        LinkedList<Integer> queue = new LinkedList<Integer>();
        for (int i = 0; i < n; i++){
            names[i] = sc.next();
            times[i] = sc.nextInt();
            queue.add(i);
        }
        while (queue.size()!=0){
            int p = queue.poll();
            if (times[p]>q) {
                times[p] -= q;
                queue.add(p);
                timenow += q;
            } else {
                timenow += times[p];
                System.out.println(names[p]+" "+timenow);
            }
        }
    }
} Main
import java.util.*;

public class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int timenow = 0;
        int n = sc.nextInt();
        int q = sc.nextInt();
        String[] names = new String[n];
        int[] times = new int[n];
        LinkedList<Integer> queue = new LinkedList<Integer>();
        for (int i = 0; i < n; i++){
            names[i] = sc.next();
            times[i] = sc.nextInt();
            queue.add(i);
        }
        while (queue.size()!=0){
            int p = queue.poll();
            if (times[p]>q) {
                times[p] -= q;
                queue.add(p);
                timenow += q;
            } else {
                timenow += times[p];
                System.out.println(names[p]+" "+timenow);
            }
        }
    }
}