import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main {
    public static void solve(){
        Scanner scan = new Scanner(System.in);
        int n, q, i, t;
        String[] names = new String[100001];
        int[] times = new int[100001];
        Queue<Integer> processList = new LinkedList<>();
        n = scan.nextInt();
        q = scan.nextInt();
        
        for(i=0;i<n;i++){
            names[i] = scan.next();
            times[i] = scan.nextInt();
            processList.add(i);
        }
        t = 0;
        while(!processList.isEmpty()){
            int x = processList.remove();
            if(times[x]> q){
                times[x] -= q;
                t+=q;
                processList.add(x);
            }else if(times[x] == q){
                t+=q;
                System.out.println(names[x] + " " + t);
            }else{
                t += times[x];
                System.out.println(names[x] + " " + t);
            }
        }
    }
    
    public static void main(String[] args) {
        solve();
    }
}
 import java.util.LinkedList; LinkedList java.util import java.util.Queue; Queue java.util import java.util.Scanner; Scanner java.util public class Main {
    public static void solve(){
        Scanner scan = new Scanner(System.in);
        int n, q, i, t;
        String[] names = new String[100001];
        int[] times = new int[100001];
        Queue<Integer> processList = new LinkedList<>();
        n = scan.nextInt();
        q = scan.nextInt();
        
        for(i=0;i<n;i++){
            names[i] = scan.next();
            times[i] = scan.nextInt();
            processList.add(i);
        }
        t = 0;
        while(!processList.isEmpty()){
            int x = processList.remove();
            if(times[x]> q){
                times[x] -= q;
                t+=q;
                processList.add(x);
            }else if(times[x] == q){
                t+=q;
                System.out.println(names[x] + " " + t);
            }else{
                t += times[x];
                System.out.println(names[x] + " " + t);
            }
        }
    }
    
    public static void main(String[] args) {
        solve();
    }
} Main public static void solve(){
        Scanner scan = new Scanner(System.in);
        int n, q, i, t;
        String[] names = new String[100001];
        int[] times = new int[100001];
        Queue<Integer> processList = new LinkedList<>();
        n = scan.nextInt();
        q = scan.nextInt();
        
        for(i=0;i<n;i++){
            names[i] = scan.next();
            times[i] = scan.nextInt();
            processList.add(i);
        }
        t = 0;
        while(!processList.isEmpty()){
            int x = processList.remove();
            if(times[x]> q){
                times[x] -= q;
                t+=q;
                processList.add(x);
            }else if(times[x] == q){
                t+=q;
                System.out.println(names[x] + " " + t);
            }else{
                t += times[x];
                System.out.println(names[x] + " " + t);
            }
        }
    } solve {
        Scanner scan = new Scanner(System.in);
        int n, q, i, t;
        String[] names = new String[100001];
        int[] times = new int[100001];
        Queue<Integer> processList = new LinkedList<>();
        n = scan.nextInt();
        q = scan.nextInt();
        
        for(i=0;i<n;i++){
            names[i] = scan.next();
            times[i] = scan.nextInt();
            processList.add(i);
        }
        t = 0;
        while(!processList.isEmpty()){
            int x = processList.remove();
            if(times[x]> q){
                times[x] -= q;
                t+=q;
                processList.add(x);
            }else if(times[x] == q){
                t+=q;
                System.out.println(names[x] + " " + t);
            }else{
                t += times[x];
                System.out.println(names[x] + " " + t);
            }
        }
    } Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int n n q q i i t; t String[] names = new String[100001]; names new String[100001] 100001 int[] times = new int[100001]; times new int[100001] 100001 Queue<Integer> processList = new LinkedList<>(); processList new LinkedList<>() n = scan.nextInt() n scan.nextInt() scan.nextInt scan q = scan.nextInt() q scan.nextInt() scan.nextInt scan for(i=0;i<n;i++){
            names[i] = scan.next();
            times[i] = scan.nextInt();
            processList.add(i);
        } i=0; i=0 i 0 i<n i n i++ i++ i {
            names[i] = scan.next();
            times[i] = scan.nextInt();
            processList.add(i);
        } {
            names[i] = scan.next();
            times[i] = scan.nextInt();
            processList.add(i);
        } names[i] = scan.next() names[i] names i scan.next() scan.next scan times[i] = scan.nextInt() times[i] times i scan.nextInt() scan.nextInt scan processList.add(i) processList.add processList i t = 0 t 0 while(!processList.isEmpty()){
            int x = processList.remove();
            if(times[x]> q){
                times[x] -= q;
                t+=q;
                processList.add(x);
            }else if(times[x] == q){
                t+=q;
                System.out.println(names[x] + " " + t);
            }else{
                t += times[x];
                System.out.println(names[x] + " " + t);
            }
        } !processList.isEmpty() processList.isEmpty() processList.isEmpty processList {
            int x = processList.remove();
            if(times[x]> q){
                times[x] -= q;
                t+=q;
                processList.add(x);
            }else if(times[x] == q){
                t+=q;
                System.out.println(names[x] + " " + t);
            }else{
                t += times[x];
                System.out.println(names[x] + " " + t);
            }
        } int x = processList.remove(); x processList.remove() processList.remove processList if(times[x]> q){
                times[x] -= q;
                t+=q;
                processList.add(x);
            }else if(times[x] == q){
                t+=q;
                System.out.println(names[x] + " " + t);
            }else{
                t += times[x];
                System.out.println(names[x] + " " + t);
            } times[x]> q times[x] times x q {
                times[x] -= q;
                t+=q;
                processList.add(x);
            } times[x] -= q times[x] times x q t+=q t q processList.add(x) processList.add processList x if(times[x] == q){
                t+=q;
                System.out.println(names[x] + " " + t);
            }else{
                t += times[x];
                System.out.println(names[x] + " " + t);
            } times[x] == q times[x] times x q {
                t+=q;
                System.out.println(names[x] + " " + t);
            } t+=q t q System.out.println(names[x] + " " + t) System.out.println System.out System System.out names[x] + " " + t names[x] + " " + t names[x] names x " " t {
                t += times[x];
                System.out.println(names[x] + " " + t);
            } t += times[x] t times[x] times x System.out.println(names[x] + " " + t) System.out.println System.out System System.out names[x] + " " + t names[x] + " " + t names[x] names x " " t public static void main(String[] args) {
        solve();
    } main {
        solve();
    } solve() solve String[] args args public class Main {
    public static void solve(){
        Scanner scan = new Scanner(System.in);
        int n, q, i, t;
        String[] names = new String[100001];
        int[] times = new int[100001];
        Queue<Integer> processList = new LinkedList<>();
        n = scan.nextInt();
        q = scan.nextInt();
        
        for(i=0;i<n;i++){
            names[i] = scan.next();
            times[i] = scan.nextInt();
            processList.add(i);
        }
        t = 0;
        while(!processList.isEmpty()){
            int x = processList.remove();
            if(times[x]> q){
                times[x] -= q;
                t+=q;
                processList.add(x);
            }else if(times[x] == q){
                t+=q;
                System.out.println(names[x] + " " + t);
            }else{
                t += times[x];
                System.out.println(names[x] + " " + t);
            }
        }
    }
    
    public static void main(String[] args) {
        solve();
    }
} public class Main {
    public static void solve(){
        Scanner scan = new Scanner(System.in);
        int n, q, i, t;
        String[] names = new String[100001];
        int[] times = new int[100001];
        Queue<Integer> processList = new LinkedList<>();
        n = scan.nextInt();
        q = scan.nextInt();
        
        for(i=0;i<n;i++){
            names[i] = scan.next();
            times[i] = scan.nextInt();
            processList.add(i);
        }
        t = 0;
        while(!processList.isEmpty()){
            int x = processList.remove();
            if(times[x]> q){
                times[x] -= q;
                t+=q;
                processList.add(x);
            }else if(times[x] == q){
                t+=q;
                System.out.println(names[x] + " " + t);
            }else{
                t += times[x];
                System.out.println(names[x] + " " + t);
            }
        }
    }
    
    public static void main(String[] args) {
        solve();
    }
} Main
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main {
    public static void solve(){
        Scanner scan = new Scanner(System.in);
        int n, q, i, t;
        String[] names = new String[100001];
        int[] times = new int[100001];
        Queue<Integer> processList = new LinkedList<>();
        n = scan.nextInt();
        q = scan.nextInt();
        
        for(i=0;i<n;i++){
            names[i] = scan.next();
            times[i] = scan.nextInt();
            processList.add(i);
        }
        t = 0;
        while(!processList.isEmpty()){
            int x = processList.remove();
            if(times[x]> q){
                times[x] -= q;
                t+=q;
                processList.add(x);
            }else if(times[x] == q){
                t+=q;
                System.out.println(names[x] + " " + t);
            }else{
                t += times[x];
                System.out.println(names[x] + " " + t);
            }
        }
    }
    
    public static void main(String[] args) {
        solve();
    }
}

