import java.util.Scanner;

class Main {

    static Scanner scan;
    static P[] p;
    static int head;
    static int tail;

    public static void main(String[] args) {
	int elaps = 0;
	
	// get from std in: n, q
	scan = new Scanner(System.in);
	final int n = scan.nextInt();
	final int q = scan.nextInt();

	// create a queue
	p = new P[100000];
	head = 0;
	tail = n;

	for (int i = 0; i < n; i++) {
	    String name = scan.next();
	    int t = scan.nextInt();
	    p[i] = new P(name, t);
	}

	while(head != tail) {
	    P u = dequeue();
	    int c = min(q, u.t);
	    u.t -= c;
	    elaps += c;
	    if(u.t > 0) enqueue(u);
	    else {
		System.out.printf("%s %d\n", u.name, elaps);
	    }
	}
    }

    static void enqueue(P x) {
	p[tail] = x;
	tail = (tail + 1) % p.length;
    }
    
    static P dequeue() {
	P x = p[head];
	head = (head + 1) % p.length;
	return x;
    }

    static int min(int a, int b) {
	if(a < b) {
	    return a;
	} else {
	    return b;
	}
    }
}

class P {
    public String name;
    public int t;

    public P(String name, int t) {
	this.name = name;
	this.t = t;
    }
}
 import java.util.Scanner; Scanner java.util class Main {

    static Scanner scan;
    static P[] p;
    static int head;
    static int tail;

    public static void main(String[] args) {
	int elaps = 0;
	
	// get from std in: n, q
	scan = new Scanner(System.in);
	final int n = scan.nextInt();
	final int q = scan.nextInt();

	// create a queue
	p = new P[100000];
	head = 0;
	tail = n;

	for (int i = 0; i < n; i++) {
	    String name = scan.next();
	    int t = scan.nextInt();
	    p[i] = new P(name, t);
	}

	while(head != tail) {
	    P u = dequeue();
	    int c = min(q, u.t);
	    u.t -= c;
	    elaps += c;
	    if(u.t > 0) enqueue(u);
	    else {
		System.out.printf("%s %d\n", u.name, elaps);
	    }
	}
    }

    static void enqueue(P x) {
	p[tail] = x;
	tail = (tail + 1) % p.length;
    }
    
    static P dequeue() {
	P x = p[head];
	head = (head + 1) % p.length;
	return x;
    }

    static int min(int a, int b) {
	if(a < b) {
	    return a;
	} else {
	    return b;
	}
    }
} Main static Scanner scan; scan static P[] p; p static int head; head static int tail; tail public static void main(String[] args) {
	int elaps = 0;
	
	// get from std in: n, q
	scan = new Scanner(System.in);
	final int n = scan.nextInt();
	final int q = scan.nextInt();

	// create a queue
	p = new P[100000];
	head = 0;
	tail = n;

	for (int i = 0; i < n; i++) {
	    String name = scan.next();
	    int t = scan.nextInt();
	    p[i] = new P(name, t);
	}

	while(head != tail) {
	    P u = dequeue();
	    int c = min(q, u.t);
	    u.t -= c;
	    elaps += c;
	    if(u.t > 0) enqueue(u);
	    else {
		System.out.printf("%s %d\n", u.name, elaps);
	    }
	}
    } main {
	int elaps = 0;
	
	// get from std in: n, q
	scan = new Scanner(System.in);
	final int n = scan.nextInt();
	final int q = scan.nextInt();

	// create a queue
	p = new P[100000];
	head = 0;
	tail = n;

	for (int i = 0; i < n; i++) {
	    String name = scan.next();
	    int t = scan.nextInt();
	    p[i] = new P(name, t);
	}

	while(head != tail) {
	    P u = dequeue();
	    int c = min(q, u.t);
	    u.t -= c;
	    elaps += c;
	    if(u.t > 0) enqueue(u);
	    else {
		System.out.printf("%s %d\n", u.name, elaps);
	    }
	}
    } int elaps = 0; elaps 0 scan = new Scanner(System.in) scan new Scanner(System.in) final int n = scan.nextInt(); n scan.nextInt() scan.nextInt scan final int q = scan.nextInt(); q scan.nextInt() scan.nextInt scan p = new P[100000] p new P[100000] 100000 head = 0 head 0 tail = n tail n for (int i = 0; i < n; i++) {
	    String name = scan.next();
	    int t = scan.nextInt();
	    p[i] = new P(name, t);
	} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
	    String name = scan.next();
	    int t = scan.nextInt();
	    p[i] = new P(name, t);
	} {
	    String name = scan.next();
	    int t = scan.nextInt();
	    p[i] = new P(name, t);
	} String name = scan.next(); name scan.next() scan.next scan int t = scan.nextInt(); t scan.nextInt() scan.nextInt scan p[i] = new P(name, t) p[i] p i new P(name, t) while(head != tail) {
	    P u = dequeue();
	    int c = min(q, u.t);
	    u.t -= c;
	    elaps += c;
	    if(u.t > 0) enqueue(u);
	    else {
		System.out.printf("%s %d\n", u.name, elaps);
	    }
	} head != tail head tail {
	    P u = dequeue();
	    int c = min(q, u.t);
	    u.t -= c;
	    elaps += c;
	    if(u.t > 0) enqueue(u);
	    else {
		System.out.printf("%s %d\n", u.name, elaps);
	    }
	} P u = dequeue(); u dequeue() dequeue int c = min(q, u.t); c min(q, u.t) min q u.t u u.t u.t -= c u.t u u.t c elaps += c elaps c if(u.t > 0) enqueue(u);
	    else {
		System.out.printf("%s %d\n", u.name, elaps);
	    } u.t > 0 u.t u u.t 0 enqueue(u) enqueue u {
		System.out.printf("%s %d\n", u.name, elaps);
	    } System.out.printf("%s %d\n", u.name, elaps) System.out.printf System.out System System.out "%s %d\n" u.name u u.name elaps String[] args args static void enqueue(P x) {
	p[tail] = x;
	tail = (tail + 1) % p.length;
    } enqueue {
	p[tail] = x;
	tail = (tail + 1) % p.length;
    } p[tail] = x p[tail] p tail x tail = (tail + 1) % p.length tail (tail + 1) % p.length (tail + 1) tail 1 p.length p p.length P x x static P dequeue() {
	P x = p[head];
	head = (head + 1) % p.length;
	return x;
    } dequeue {
	P x = p[head];
	head = (head + 1) % p.length;
	return x;
    } P x = p[head]; x p[head] p head head = (head + 1) % p.length head (head + 1) % p.length (head + 1) head 1 p.length p p.length return x; x static int min(int a, int b) {
	if(a < b) {
	    return a;
	} else {
	    return b;
	}
    } min {
	if(a < b) {
	    return a;
	} else {
	    return b;
	}
    } if(a < b) {
	    return a;
	} else {
	    return b;
	} a < b a b {
	    return a;
	} return a; a {
	    return b;
	} return b; b int a a int b b class P {
    public String name;
    public int t;

    public P(String name, int t) {
	this.name = name;
	this.t = t;
    }
} P public String name; name public int t; t public P(String name, int t) {
	this.name = name;
	this.t = t;
    } P {
	this.name = name;
	this.t = t;
    } this.name = name this.name this this.name name this.t = t this.t this this.t t String name name int t t
import java.util.Scanner;

class Main {

    static Scanner scan;
    static P[] p;
    static int head;
    static int tail;

    public static void main(String[] args) {
	int elaps = 0;
	
	// get from std in: n, q
	scan = new Scanner(System.in);
	final int n = scan.nextInt();
	final int q = scan.nextInt();

	// create a queue
	p = new P[100000];
	head = 0;
	tail = n;

	for (int i = 0; i < n; i++) {
	    String name = scan.next();
	    int t = scan.nextInt();
	    p[i] = new P(name, t);
	}

	while(head != tail) {
	    P u = dequeue();
	    int c = min(q, u.t);
	    u.t -= c;
	    elaps += c;
	    if(u.t > 0) enqueue(u);
	    else {
		System.out.printf("%s %d\n", u.name, elaps);
	    }
	}
    }

    static void enqueue(P x) {
	p[tail] = x;
	tail = (tail + 1) % p.length;
    }
    
    static P dequeue() {
	P x = p[head];
	head = (head + 1) % p.length;
	return x;
    }

    static int min(int a, int b) {
	if(a < b) {
	    return a;
	} else {
	    return b;
	}
    }
}

class P {
    public String name;
    public int t;

    public P(String name, int t) {
	this.name = name;
	this.t = t;
    }
}

