import java.util.Scanner;
import java.util.ArrayDeque;
import java.util.Queue;

class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        Queue<Integer> queue = new ArrayDeque<>();
        
        int n = sc.nextInt();
        int q = sc.nextInt();
        String name[] = new String[n];
        int time[] = new int[n];
        for(int i = 0; i < n; i++){
            name[i] = sc.next();
            time[i] = sc.nextInt();
            queue.add(i);
        }
        
        int x = 0;
        while(!queue.isEmpty()){
            int y = queue.poll();
            if(time[y] <= q){
                x += time[y];
                System.out.println(name[y]+" "+x);
            }else{
                x += q;
                time[y] -= q;
                queue.add(y);
            }
        }
    }
} import java.util.Scanner; Scanner java.util import java.util.ArrayDeque; ArrayDeque java.util import java.util.Queue; Queue java.util class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        Queue<Integer> queue = new ArrayDeque<>();
        
        int n = sc.nextInt();
        int q = sc.nextInt();
        String name[] = new String[n];
        int time[] = new int[n];
        for(int i = 0; i < n; i++){
            name[i] = sc.next();
            time[i] = sc.nextInt();
            queue.add(i);
        }
        
        int x = 0;
        while(!queue.isEmpty()){
            int y = queue.poll();
            if(time[y] <= q){
                x += time[y];
                System.out.println(name[y]+" "+x);
            }else{
                x += q;
                time[y] -= q;
                queue.add(y);
            }
        }
    }
} Main public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        Queue<Integer> queue = new ArrayDeque<>();
        
        int n = sc.nextInt();
        int q = sc.nextInt();
        String name[] = new String[n];
        int time[] = new int[n];
        for(int i = 0; i < n; i++){
            name[i] = sc.next();
            time[i] = sc.nextInt();
            queue.add(i);
        }
        
        int x = 0;
        while(!queue.isEmpty()){
            int y = queue.poll();
            if(time[y] <= q){
                x += time[y];
                System.out.println(name[y]+" "+x);
            }else{
                x += q;
                time[y] -= q;
                queue.add(y);
            }
        }
    } main {
        Scanner sc = new Scanner(System.in);
        Queue<Integer> queue = new ArrayDeque<>();
        
        int n = sc.nextInt();
        int q = sc.nextInt();
        String name[] = new String[n];
        int time[] = new int[n];
        for(int i = 0; i < n; i++){
            name[i] = sc.next();
            time[i] = sc.nextInt();
            queue.add(i);
        }
        
        int x = 0;
        while(!queue.isEmpty()){
            int y = queue.poll();
            if(time[y] <= q){
                x += time[y];
                System.out.println(name[y]+" "+x);
            }else{
                x += q;
                time[y] -= q;
                queue.add(y);
            }
        }
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) Queue<Integer> queue = new ArrayDeque<>(); queue new ArrayDeque<>() int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int q = sc.nextInt(); q sc.nextInt() sc.nextInt sc String name[] = new String[n]; name new String[n] n int time[] = new int[n]; time new int[n] n for(int i = 0; i < n; i++){
            name[i] = sc.next();
            time[i] = sc.nextInt();
            queue.add(i);
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            name[i] = sc.next();
            time[i] = sc.nextInt();
            queue.add(i);
        } {
            name[i] = sc.next();
            time[i] = sc.nextInt();
            queue.add(i);
        } name[i] = sc.next() name[i] name i sc.next() sc.next sc time[i] = sc.nextInt() time[i] time i sc.nextInt() sc.nextInt sc queue.add(i) queue.add queue i int x = 0; x 0 while(!queue.isEmpty()){
            int y = queue.poll();
            if(time[y] <= q){
                x += time[y];
                System.out.println(name[y]+" "+x);
            }else{
                x += q;
                time[y] -= q;
                queue.add(y);
            }
        } !queue.isEmpty() queue.isEmpty() queue.isEmpty queue {
            int y = queue.poll();
            if(time[y] <= q){
                x += time[y];
                System.out.println(name[y]+" "+x);
            }else{
                x += q;
                time[y] -= q;
                queue.add(y);
            }
        } int y = queue.poll(); y queue.poll() queue.poll queue if(time[y] <= q){
                x += time[y];
                System.out.println(name[y]+" "+x);
            }else{
                x += q;
                time[y] -= q;
                queue.add(y);
            } time[y] <= q time[y] time y q {
                x += time[y];
                System.out.println(name[y]+" "+x);
            } x += time[y] x time[y] time y System.out.println(name[y]+" "+x) System.out.println System.out System System.out name[y]+" "+x name[y]+" "+x name[y] name y " " x {
                x += q;
                time[y] -= q;
                queue.add(y);
            } x += q x q time[y] -= q time[y] time y q queue.add(y) queue.add queue y String args[] args
import java.util.Scanner;
import java.util.ArrayDeque;
import java.util.Queue;

class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        Queue<Integer> queue = new ArrayDeque<>();
        
        int n = sc.nextInt();
        int q = sc.nextInt();
        String name[] = new String[n];
        int time[] = new int[n];
        for(int i = 0; i < n; i++){
            name[i] = sc.next();
            time[i] = sc.nextInt();
            queue.add(i);
        }
        
        int x = 0;
        while(!queue.isEmpty()){
            int y = queue.poll();
            if(time[y] <= q){
                x += time[y];
                System.out.println(name[y]+" "+x);
            }else{
                x += q;
                time[y] -= q;
                queue.add(y);
            }
        }
    }
}
