import java.util.Scanner;

public class Main {
    
    static Pair[] queue;
    static int head;
    static int tail;

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        int q = Integer.parseInt(sc.next());
        
        queue = new Pair[100010];
        initialize();
        for(int i = 0; i < n; i++){
            enqueue(new Pair(sc.next(), Integer.parseInt(sc.next())));
        }
        
        int t = 0;
        StringBuilder sb = new StringBuilder();
        while(!isEmpty()){
            Pair x = dequeue();
            if(x.time <= q){
                t += x.time;
                sb.append(x.name).append(" ").append(t).append(System.lineSeparator());
            }else{
                t += q;
                x.time -= q;
                enqueue(x);
            }
        }
        
        System.out.print(sb);
    }
    
    static void initialize(){
        head = tail = 0;
    }
    
    static boolean isEmpty(){
        return head == tail;
    }
    
    static void enqueue(Pair x){
        
        queue[tail] = x;
        if(tail+1 == queue.length){
            tail = 0;
        }else{
            tail++;
        }
    }
    
    static Pair dequeue(){
        
        Pair x = queue[head];
        if(head+1 == queue.length){
            head = 0;
        }else{
            head++;
        }
        return x;
    }
    
    static class Pair{
        String name;
        int time;

        public Pair(String name, int time) {
            this.name = name;
            this.time = time;
        }
    }
} import java.util.Scanner; Scanner java.util public class Main {
    
    static Pair[] queue;
    static int head;
    static int tail;

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        int q = Integer.parseInt(sc.next());
        
        queue = new Pair[100010];
        initialize();
        for(int i = 0; i < n; i++){
            enqueue(new Pair(sc.next(), Integer.parseInt(sc.next())));
        }
        
        int t = 0;
        StringBuilder sb = new StringBuilder();
        while(!isEmpty()){
            Pair x = dequeue();
            if(x.time <= q){
                t += x.time;
                sb.append(x.name).append(" ").append(t).append(System.lineSeparator());
            }else{
                t += q;
                x.time -= q;
                enqueue(x);
            }
        }
        
        System.out.print(sb);
    }
    
    static void initialize(){
        head = tail = 0;
    }
    
    static boolean isEmpty(){
        return head == tail;
    }
    
    static void enqueue(Pair x){
        
        queue[tail] = x;
        if(tail+1 == queue.length){
            tail = 0;
        }else{
            tail++;
        }
    }
    
    static Pair dequeue(){
        
        Pair x = queue[head];
        if(head+1 == queue.length){
            head = 0;
        }else{
            head++;
        }
        return x;
    }
    
    static class Pair{
        String name;
        int time;

        public Pair(String name, int time) {
            this.name = name;
            this.time = time;
        }
    }
} Main static Pair[] queue; queue static int head; head static int tail; tail public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        int q = Integer.parseInt(sc.next());
        
        queue = new Pair[100010];
        initialize();
        for(int i = 0; i < n; i++){
            enqueue(new Pair(sc.next(), Integer.parseInt(sc.next())));
        }
        
        int t = 0;
        StringBuilder sb = new StringBuilder();
        while(!isEmpty()){
            Pair x = dequeue();
            if(x.time <= q){
                t += x.time;
                sb.append(x.name).append(" ").append(t).append(System.lineSeparator());
            }else{
                t += q;
                x.time -= q;
                enqueue(x);
            }
        }
        
        System.out.print(sb);
    } main {
        
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        int q = Integer.parseInt(sc.next());
        
        queue = new Pair[100010];
        initialize();
        for(int i = 0; i < n; i++){
            enqueue(new Pair(sc.next(), Integer.parseInt(sc.next())));
        }
        
        int t = 0;
        StringBuilder sb = new StringBuilder();
        while(!isEmpty()){
            Pair x = dequeue();
            if(x.time <= q){
                t += x.time;
                sb.append(x.name).append(" ").append(t).append(System.lineSeparator());
            }else{
                t += q;
                x.time -= q;
                enqueue(x);
            }
        }
        
        System.out.print(sb);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = Integer.parseInt(sc.next()); n Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int q = Integer.parseInt(sc.next()); q Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc queue = new Pair[100010] queue new Pair[100010] 100010 initialize() initialize for(int i = 0; i < n; i++){
            enqueue(new Pair(sc.next(), Integer.parseInt(sc.next())));
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            enqueue(new Pair(sc.next(), Integer.parseInt(sc.next())));
        } {
            enqueue(new Pair(sc.next(), Integer.parseInt(sc.next())));
        } enqueue(new Pair(sc.next(), Integer.parseInt(sc.next()))) enqueue new Pair(sc.next(), Integer.parseInt(sc.next())) int t = 0; t 0 StringBuilder sb = new StringBuilder(); sb new StringBuilder() while(!isEmpty()){
            Pair x = dequeue();
            if(x.time <= q){
                t += x.time;
                sb.append(x.name).append(" ").append(t).append(System.lineSeparator());
            }else{
                t += q;
                x.time -= q;
                enqueue(x);
            }
        } !isEmpty() isEmpty() isEmpty {
            Pair x = dequeue();
            if(x.time <= q){
                t += x.time;
                sb.append(x.name).append(" ").append(t).append(System.lineSeparator());
            }else{
                t += q;
                x.time -= q;
                enqueue(x);
            }
        } Pair x = dequeue(); x dequeue() dequeue if(x.time <= q){
                t += x.time;
                sb.append(x.name).append(" ").append(t).append(System.lineSeparator());
            }else{
                t += q;
                x.time -= q;
                enqueue(x);
            } x.time <= q x.time x x.time q {
                t += x.time;
                sb.append(x.name).append(" ").append(t).append(System.lineSeparator());
            } t += x.time t x.time x x.time sb.append(x.name).append(" ").append(t).append(System.lineSeparator()) sb.append(x.name).append(" ").append(t).append sb.append(x.name).append(" ").append(t) sb.append(x.name).append(" ").append sb.append(x.name).append(" ") sb.append(x.name).append sb.append(x.name) sb.append sb x.name x x.name " " t System.lineSeparator() System.lineSeparator System {
                t += q;
                x.time -= q;
                enqueue(x);
            } t += q t q x.time -= q x.time x x.time q enqueue(x) enqueue x System.out.print(sb) System.out.print System.out System System.out sb String[] args args static void initialize(){
        head = tail = 0;
    } initialize {
        head = tail = 0;
    } head = tail = 0 head tail = 0 tail 0 static boolean isEmpty(){
        return head == tail;
    } isEmpty {
        return head == tail;
    } return head == tail; head == tail head tail static void enqueue(Pair x){
        
        queue[tail] = x;
        if(tail+1 == queue.length){
            tail = 0;
        }else{
            tail++;
        }
    } enqueue {
        
        queue[tail] = x;
        if(tail+1 == queue.length){
            tail = 0;
        }else{
            tail++;
        }
    } queue[tail] = x queue[tail] queue tail x if(tail+1 == queue.length){
            tail = 0;
        }else{
            tail++;
        } tail+1 == queue.length tail+1 tail 1 queue.length queue queue.length {
            tail = 0;
        } tail = 0 tail 0 {
            tail++;
        } tail++ tail Pair x x static Pair dequeue(){
        
        Pair x = queue[head];
        if(head+1 == queue.length){
            head = 0;
        }else{
            head++;
        }
        return x;
    } dequeue {
        
        Pair x = queue[head];
        if(head+1 == queue.length){
            head = 0;
        }else{
            head++;
        }
        return x;
    } Pair x = queue[head]; x queue[head] queue head if(head+1 == queue.length){
            head = 0;
        }else{
            head++;
        } head+1 == queue.length head+1 head 1 queue.length queue queue.length {
            head = 0;
        } head = 0 head 0 {
            head++;
        } head++ head return x; x static class Pair{
        String name;
        int time;

        public Pair(String name, int time) {
            this.name = name;
            this.time = time;
        }
    } Pair String name; name int time; time public Pair(String name, int time) {
            this.name = name;
            this.time = time;
        } Pair {
            this.name = name;
            this.time = time;
        } this.name = name this.name this this.name name this.time = time this.time this this.time time String name name int time time public class Main {
    
    static Pair[] queue;
    static int head;
    static int tail;

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        int q = Integer.parseInt(sc.next());
        
        queue = new Pair[100010];
        initialize();
        for(int i = 0; i < n; i++){
            enqueue(new Pair(sc.next(), Integer.parseInt(sc.next())));
        }
        
        int t = 0;
        StringBuilder sb = new StringBuilder();
        while(!isEmpty()){
            Pair x = dequeue();
            if(x.time <= q){
                t += x.time;
                sb.append(x.name).append(" ").append(t).append(System.lineSeparator());
            }else{
                t += q;
                x.time -= q;
                enqueue(x);
            }
        }
        
        System.out.print(sb);
    }
    
    static void initialize(){
        head = tail = 0;
    }
    
    static boolean isEmpty(){
        return head == tail;
    }
    
    static void enqueue(Pair x){
        
        queue[tail] = x;
        if(tail+1 == queue.length){
            tail = 0;
        }else{
            tail++;
        }
    }
    
    static Pair dequeue(){
        
        Pair x = queue[head];
        if(head+1 == queue.length){
            head = 0;
        }else{
            head++;
        }
        return x;
    }
    
    static class Pair{
        String name;
        int time;

        public Pair(String name, int time) {
            this.name = name;
            this.time = time;
        }
    }
} public class Main {
    
    static Pair[] queue;
    static int head;
    static int tail;

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        int q = Integer.parseInt(sc.next());
        
        queue = new Pair[100010];
        initialize();
        for(int i = 0; i < n; i++){
            enqueue(new Pair(sc.next(), Integer.parseInt(sc.next())));
        }
        
        int t = 0;
        StringBuilder sb = new StringBuilder();
        while(!isEmpty()){
            Pair x = dequeue();
            if(x.time <= q){
                t += x.time;
                sb.append(x.name).append(" ").append(t).append(System.lineSeparator());
            }else{
                t += q;
                x.time -= q;
                enqueue(x);
            }
        }
        
        System.out.print(sb);
    }
    
    static void initialize(){
        head = tail = 0;
    }
    
    static boolean isEmpty(){
        return head == tail;
    }
    
    static void enqueue(Pair x){
        
        queue[tail] = x;
        if(tail+1 == queue.length){
            tail = 0;
        }else{
            tail++;
        }
    }
    
    static Pair dequeue(){
        
        Pair x = queue[head];
        if(head+1 == queue.length){
            head = 0;
        }else{
            head++;
        }
        return x;
    }
    
    static class Pair{
        String name;
        int time;

        public Pair(String name, int time) {
            this.name = name;
            this.time = time;
        }
    }
} Main
import java.util.Scanner;

public class Main {
    
    static Pair[] queue;
    static int head;
    static int tail;

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        int q = Integer.parseInt(sc.next());
        
        queue = new Pair[100010];
        initialize();
        for(int i = 0; i < n; i++){
            enqueue(new Pair(sc.next(), Integer.parseInt(sc.next())));
        }
        
        int t = 0;
        StringBuilder sb = new StringBuilder();
        while(!isEmpty()){
            Pair x = dequeue();
            if(x.time <= q){
                t += x.time;
                sb.append(x.name).append(" ").append(t).append(System.lineSeparator());
            }else{
                t += q;
                x.time -= q;
                enqueue(x);
            }
        }
        
        System.out.print(sb);
    }
    
    static void initialize(){
        head = tail = 0;
    }
    
    static boolean isEmpty(){
        return head == tail;
    }
    
    static void enqueue(Pair x){
        
        queue[tail] = x;
        if(tail+1 == queue.length){
            tail = 0;
        }else{
            tail++;
        }
    }
    
    static Pair dequeue(){
        
        Pair x = queue[head];
        if(head+1 == queue.length){
            head = 0;
        }else{
            head++;
        }
        return x;
    }
    
    static class Pair{
        String name;
        int time;

        public Pair(String name, int time) {
            this.name = name;
            this.time = time;
        }
    }
}
