import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        Queue<String> name_queue = new ArrayDeque<>();
        Queue<Integer> queue = new ArrayDeque<>();
        int n = sc.nextInt();
        int q = sc.nextInt();
        for(int i = 0 ; i < n ; i++){
            name_queue.add(sc.next());
            queue.add(sc.nextInt());
        }
        int count_time = 0;
        while(true){
            String name = name_queue.poll();
            if(queue.peek() == null)
                break;
            int num = queue.poll();
            if(num <= q){
                count_time += num;
                System.out.println(name + " " + count_time);
            }
            else{
                count_time += q;
                num -= q;
                queue.add(num);
                name_queue.add(name);
            }
        }
    }
} import java.util.*; util.* java public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        Queue<String> name_queue = new ArrayDeque<>();
        Queue<Integer> queue = new ArrayDeque<>();
        int n = sc.nextInt();
        int q = sc.nextInt();
        for(int i = 0 ; i < n ; i++){
            name_queue.add(sc.next());
            queue.add(sc.nextInt());
        }
        int count_time = 0;
        while(true){
            String name = name_queue.poll();
            if(queue.peek() == null)
                break;
            int num = queue.poll();
            if(num <= q){
                count_time += num;
                System.out.println(name + " " + count_time);
            }
            else{
                count_time += q;
                num -= q;
                queue.add(num);
                name_queue.add(name);
            }
        }
    }
} Main public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        Queue<String> name_queue = new ArrayDeque<>();
        Queue<Integer> queue = new ArrayDeque<>();
        int n = sc.nextInt();
        int q = sc.nextInt();
        for(int i = 0 ; i < n ; i++){
            name_queue.add(sc.next());
            queue.add(sc.nextInt());
        }
        int count_time = 0;
        while(true){
            String name = name_queue.poll();
            if(queue.peek() == null)
                break;
            int num = queue.poll();
            if(num <= q){
                count_time += num;
                System.out.println(name + " " + count_time);
            }
            else{
                count_time += q;
                num -= q;
                queue.add(num);
                name_queue.add(name);
            }
        }
    } main {
        Scanner sc = new Scanner(System.in);
        Queue<String> name_queue = new ArrayDeque<>();
        Queue<Integer> queue = new ArrayDeque<>();
        int n = sc.nextInt();
        int q = sc.nextInt();
        for(int i = 0 ; i < n ; i++){
            name_queue.add(sc.next());
            queue.add(sc.nextInt());
        }
        int count_time = 0;
        while(true){
            String name = name_queue.poll();
            if(queue.peek() == null)
                break;
            int num = queue.poll();
            if(num <= q){
                count_time += num;
                System.out.println(name + " " + count_time);
            }
            else{
                count_time += q;
                num -= q;
                queue.add(num);
                name_queue.add(name);
            }
        }
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) Queue<String> name_queue = new ArrayDeque<>(); name_queue new ArrayDeque<>() 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 for(int i = 0 ; i < n ; i++){
            name_queue.add(sc.next());
            queue.add(sc.nextInt());
        } int i = 0 ; int i = 0 ; i 0 i < n i n i++ i++ i {
            name_queue.add(sc.next());
            queue.add(sc.nextInt());
        } {
            name_queue.add(sc.next());
            queue.add(sc.nextInt());
        } name_queue.add(sc.next()) name_queue.add name_queue sc.next() sc.next sc queue.add(sc.nextInt()) queue.add queue sc.nextInt() sc.nextInt sc int count_time = 0; count_time 0 while(true){
            String name = name_queue.poll();
            if(queue.peek() == null)
                break;
            int num = queue.poll();
            if(num <= q){
                count_time += num;
                System.out.println(name + " " + count_time);
            }
            else{
                count_time += q;
                num -= q;
                queue.add(num);
                name_queue.add(name);
            }
        } true {
            String name = name_queue.poll();
            if(queue.peek() == null)
                break;
            int num = queue.poll();
            if(num <= q){
                count_time += num;
                System.out.println(name + " " + count_time);
            }
            else{
                count_time += q;
                num -= q;
                queue.add(num);
                name_queue.add(name);
            }
        } String name = name_queue.poll(); name name_queue.poll() name_queue.poll name_queue if(queue.peek() == null)
                break; queue.peek() == null queue.peek() queue.peek queue null break; int num = queue.poll(); num queue.poll() queue.poll queue if(num <= q){
                count_time += num;
                System.out.println(name + " " + count_time);
            }
            else{
                count_time += q;
                num -= q;
                queue.add(num);
                name_queue.add(name);
            } num <= q num q {
                count_time += num;
                System.out.println(name + " " + count_time);
            } count_time += num count_time num System.out.println(name + " " + count_time) System.out.println System.out System System.out name + " " + count_time name + " " + count_time name " " count_time {
                count_time += q;
                num -= q;
                queue.add(num);
                name_queue.add(name);
            } count_time += q count_time q num -= q num q queue.add(num) queue.add queue num name_queue.add(name) name_queue.add name_queue name String[] args args public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        Queue<String> name_queue = new ArrayDeque<>();
        Queue<Integer> queue = new ArrayDeque<>();
        int n = sc.nextInt();
        int q = sc.nextInt();
        for(int i = 0 ; i < n ; i++){
            name_queue.add(sc.next());
            queue.add(sc.nextInt());
        }
        int count_time = 0;
        while(true){
            String name = name_queue.poll();
            if(queue.peek() == null)
                break;
            int num = queue.poll();
            if(num <= q){
                count_time += num;
                System.out.println(name + " " + count_time);
            }
            else{
                count_time += q;
                num -= q;
                queue.add(num);
                name_queue.add(name);
            }
        }
    }
} public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        Queue<String> name_queue = new ArrayDeque<>();
        Queue<Integer> queue = new ArrayDeque<>();
        int n = sc.nextInt();
        int q = sc.nextInt();
        for(int i = 0 ; i < n ; i++){
            name_queue.add(sc.next());
            queue.add(sc.nextInt());
        }
        int count_time = 0;
        while(true){
            String name = name_queue.poll();
            if(queue.peek() == null)
                break;
            int num = queue.poll();
            if(num <= q){
                count_time += num;
                System.out.println(name + " " + count_time);
            }
            else{
                count_time += q;
                num -= q;
                queue.add(num);
                name_queue.add(name);
            }
        }
    }
} Main
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        Queue<String> name_queue = new ArrayDeque<>();
        Queue<Integer> queue = new ArrayDeque<>();
        int n = sc.nextInt();
        int q = sc.nextInt();
        for(int i = 0 ; i < n ; i++){
            name_queue.add(sc.next());
            queue.add(sc.nextInt());
        }
        int count_time = 0;
        while(true){
            String name = name_queue.poll();
            if(queue.peek() == null)
                break;
            int num = queue.poll();
            if(num <= q){
                count_time += num;
                System.out.println(name + " " + count_time);
            }
            else{
                count_time += q;
                num -= q;
                queue.add(num);
                name_queue.add(name);
            }
        }
    }
}
