import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.ArrayDeque;

public class Main{

    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] t = br.readLine().split(" ");
        int n = Integer.parseInt(t[0]);
        int q = Integer.parseInt(t[1]);
        ArrayDeque<P> Q = new ArrayDeque<P>();
        for(int i = 0; i < n; i++){
            t = br.readLine().split(" ");
            P p = new P();
            p.name = t[0];
            p.time = Integer.parseInt(t[1]);
            Q.addLast(p);
        }
        int sumTime = 0;
        StringBuilder sb = new StringBuilder();
        while(!Q.isEmpty()){
            P p = new P();
            p = Q.pollFirst();
            //p.time = p.time - q;                                                   
            if(p.time - q <= 0){
                sumTime += p.time;
                sb.append(p.name).append(" ").append(sumTime).append("\n");
            }else if(p.time - q > 0){
                p.time = p.time - q;
                Q.addLast(p);
                sumTime = sumTime + q;
            }
        }
        System.out.print(sb);
    }

}

class P{
    String name;
    int time;
} import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io import java.io.IOException; IOException java.io import java.util.ArrayDeque; ArrayDeque java.util public class Main{

    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] t = br.readLine().split(" ");
        int n = Integer.parseInt(t[0]);
        int q = Integer.parseInt(t[1]);
        ArrayDeque<P> Q = new ArrayDeque<P>();
        for(int i = 0; i < n; i++){
            t = br.readLine().split(" ");
            P p = new P();
            p.name = t[0];
            p.time = Integer.parseInt(t[1]);
            Q.addLast(p);
        }
        int sumTime = 0;
        StringBuilder sb = new StringBuilder();
        while(!Q.isEmpty()){
            P p = new P();
            p = Q.pollFirst();
            //p.time = p.time - q;                                                   
            if(p.time - q <= 0){
                sumTime += p.time;
                sb.append(p.name).append(" ").append(sumTime).append("\n");
            }else if(p.time - q > 0){
                p.time = p.time - q;
                Q.addLast(p);
                sumTime = sumTime + q;
            }
        }
        System.out.print(sb);
    }

} Main public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] t = br.readLine().split(" ");
        int n = Integer.parseInt(t[0]);
        int q = Integer.parseInt(t[1]);
        ArrayDeque<P> Q = new ArrayDeque<P>();
        for(int i = 0; i < n; i++){
            t = br.readLine().split(" ");
            P p = new P();
            p.name = t[0];
            p.time = Integer.parseInt(t[1]);
            Q.addLast(p);
        }
        int sumTime = 0;
        StringBuilder sb = new StringBuilder();
        while(!Q.isEmpty()){
            P p = new P();
            p = Q.pollFirst();
            //p.time = p.time - q;                                                   
            if(p.time - q <= 0){
                sumTime += p.time;
                sb.append(p.name).append(" ").append(sumTime).append("\n");
            }else if(p.time - q > 0){
                p.time = p.time - q;
                Q.addLast(p);
                sumTime = sumTime + q;
            }
        }
        System.out.print(sb);
    } main {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] t = br.readLine().split(" ");
        int n = Integer.parseInt(t[0]);
        int q = Integer.parseInt(t[1]);
        ArrayDeque<P> Q = new ArrayDeque<P>();
        for(int i = 0; i < n; i++){
            t = br.readLine().split(" ");
            P p = new P();
            p.name = t[0];
            p.time = Integer.parseInt(t[1]);
            Q.addLast(p);
        }
        int sumTime = 0;
        StringBuilder sb = new StringBuilder();
        while(!Q.isEmpty()){
            P p = new P();
            p = Q.pollFirst();
            //p.time = p.time - q;                                                   
            if(p.time - q <= 0){
                sumTime += p.time;
                sb.append(p.name).append(" ").append(sumTime).append("\n");
            }else if(p.time - q > 0){
                p.time = p.time - q;
                Q.addLast(p);
                sumTime = sumTime + q;
            }
        }
        System.out.print(sb);
    } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) String[] t = br.readLine().split(" "); t br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " int n = Integer.parseInt(t[0]); n Integer.parseInt(t[0]) Integer.parseInt Integer t[0] t 0 int q = Integer.parseInt(t[1]); q Integer.parseInt(t[1]) Integer.parseInt Integer t[1] t 1 ArrayDeque<P> Q = new ArrayDeque<P>(); Q new ArrayDeque<P>() for(int i = 0; i < n; i++){
            t = br.readLine().split(" ");
            P p = new P();
            p.name = t[0];
            p.time = Integer.parseInt(t[1]);
            Q.addLast(p);
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            t = br.readLine().split(" ");
            P p = new P();
            p.name = t[0];
            p.time = Integer.parseInt(t[1]);
            Q.addLast(p);
        } {
            t = br.readLine().split(" ");
            P p = new P();
            p.name = t[0];
            p.time = Integer.parseInt(t[1]);
            Q.addLast(p);
        } t = br.readLine().split(" ") t br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " P p = new P(); p new P() p.name = t[0] p.name p p.name t[0] t 0 p.time = Integer.parseInt(t[1]) p.time p p.time Integer.parseInt(t[1]) Integer.parseInt Integer t[1] t 1 Q.addLast(p) Q.addLast Q p int sumTime = 0; sumTime 0 StringBuilder sb = new StringBuilder(); sb new StringBuilder() while(!Q.isEmpty()){
            P p = new P();
            p = Q.pollFirst();
            //p.time = p.time - q;                                                   
            if(p.time - q <= 0){
                sumTime += p.time;
                sb.append(p.name).append(" ").append(sumTime).append("\n");
            }else if(p.time - q > 0){
                p.time = p.time - q;
                Q.addLast(p);
                sumTime = sumTime + q;
            }
        } !Q.isEmpty() Q.isEmpty() Q.isEmpty Q {
            P p = new P();
            p = Q.pollFirst();
            //p.time = p.time - q;                                                   
            if(p.time - q <= 0){
                sumTime += p.time;
                sb.append(p.name).append(" ").append(sumTime).append("\n");
            }else if(p.time - q > 0){
                p.time = p.time - q;
                Q.addLast(p);
                sumTime = sumTime + q;
            }
        } P p = new P(); p new P() p = Q.pollFirst() p Q.pollFirst() Q.pollFirst Q if(p.time - q <= 0){
                sumTime += p.time;
                sb.append(p.name).append(" ").append(sumTime).append("\n");
            }else if(p.time - q > 0){
                p.time = p.time - q;
                Q.addLast(p);
                sumTime = sumTime + q;
            } p.time - q <= 0 p.time - q p.time p p.time q 0 {
                sumTime += p.time;
                sb.append(p.name).append(" ").append(sumTime).append("\n");
            } sumTime += p.time sumTime p.time p p.time sb.append(p.name).append(" ").append(sumTime).append("\n") sb.append(p.name).append(" ").append(sumTime).append sb.append(p.name).append(" ").append(sumTime) sb.append(p.name).append(" ").append sb.append(p.name).append(" ") sb.append(p.name).append sb.append(p.name) sb.append sb p.name p p.name " " sumTime "\n" if(p.time - q > 0){
                p.time = p.time - q;
                Q.addLast(p);
                sumTime = sumTime + q;
            } p.time - q > 0 p.time - q p.time p p.time q 0 {
                p.time = p.time - q;
                Q.addLast(p);
                sumTime = sumTime + q;
            } p.time = p.time - q p.time p p.time p.time - q p.time p p.time q Q.addLast(p) Q.addLast Q p sumTime = sumTime + q sumTime sumTime + q sumTime q System.out.print(sb) System.out.print System.out System System.out sb String[] args args class P{
    String name;
    int time;
} P String name; name int time; time public class Main{

    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] t = br.readLine().split(" ");
        int n = Integer.parseInt(t[0]);
        int q = Integer.parseInt(t[1]);
        ArrayDeque<P> Q = new ArrayDeque<P>();
        for(int i = 0; i < n; i++){
            t = br.readLine().split(" ");
            P p = new P();
            p.name = t[0];
            p.time = Integer.parseInt(t[1]);
            Q.addLast(p);
        }
        int sumTime = 0;
        StringBuilder sb = new StringBuilder();
        while(!Q.isEmpty()){
            P p = new P();
            p = Q.pollFirst();
            //p.time = p.time - q;                                                   
            if(p.time - q <= 0){
                sumTime += p.time;
                sb.append(p.name).append(" ").append(sumTime).append("\n");
            }else if(p.time - q > 0){
                p.time = p.time - q;
                Q.addLast(p);
                sumTime = sumTime + q;
            }
        }
        System.out.print(sb);
    }

} public class Main{

    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] t = br.readLine().split(" ");
        int n = Integer.parseInt(t[0]);
        int q = Integer.parseInt(t[1]);
        ArrayDeque<P> Q = new ArrayDeque<P>();
        for(int i = 0; i < n; i++){
            t = br.readLine().split(" ");
            P p = new P();
            p.name = t[0];
            p.time = Integer.parseInt(t[1]);
            Q.addLast(p);
        }
        int sumTime = 0;
        StringBuilder sb = new StringBuilder();
        while(!Q.isEmpty()){
            P p = new P();
            p = Q.pollFirst();
            //p.time = p.time - q;                                                   
            if(p.time - q <= 0){
                sumTime += p.time;
                sb.append(p.name).append(" ").append(sumTime).append("\n");
            }else if(p.time - q > 0){
                p.time = p.time - q;
                Q.addLast(p);
                sumTime = sumTime + q;
            }
        }
        System.out.print(sb);
    }

} Main
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.ArrayDeque;

public class Main{

    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] t = br.readLine().split(" ");
        int n = Integer.parseInt(t[0]);
        int q = Integer.parseInt(t[1]);
        ArrayDeque<P> Q = new ArrayDeque<P>();
        for(int i = 0; i < n; i++){
            t = br.readLine().split(" ");
            P p = new P();
            p.name = t[0];
            p.time = Integer.parseInt(t[1]);
            Q.addLast(p);
        }
        int sumTime = 0;
        StringBuilder sb = new StringBuilder();
        while(!Q.isEmpty()){
            P p = new P();
            p = Q.pollFirst();
            //p.time = p.time - q;                                                   
            if(p.time - q <= 0){
                sumTime += p.time;
                sb.append(p.name).append(" ").append(sumTime).append("\n");
            }else if(p.time - q > 0){
                p.time = p.time - q;
                Q.addLast(p);
                sumTime = sumTime + q;
            }
        }
        System.out.print(sb);
    }

}

class P{
    String name;
    int time;
}