import java.util.*;

public class Main{
	private static final Scanner scan = new Scanner(System.in);
	private static final int MAX = 100_001;
	private static String[] P = new String[MAX];
	private static int[] Q = new int[MAX];
	private static int head, tail;
	private static int headQ, tailQ;

	public static void main(String[] args){

		initialize();
		initializeQ();
		int n = scan.nextInt();
		int q = scan.nextInt();
		String[] p = new String[n];
		for(int i = 0; i < n; i++){
			String s = scan.next();
			int m = scan.nextInt();
			enqueue(s);
			enqueueQ(m);
		}
		int total = 0;
		for(;;){
			String s = dequeue();
			int m = dequeueQ();
			if(m >q){
				total += q;
				m = m - q;
				enqueue(s);
				enqueueQ(m);
			}else{
				total += m;
				System.out.printf("%s ", s);
				System.out.printf("%d\n", total);
				if(isEmpty() && isEmptyQ())
					break;
			}
		}
	}

	private static void initializeQ(){
		headQ = tailQ = 0;
	}
	private static boolean isEmptyQ(){
		return headQ == tailQ;
	}
	private static boolean isFullQ(){
		return headQ == (tailQ + 1) % MAX;
	}
	public static void enqueueQ(int y){
		if(isFullQ())
			System.out.printf("%s\n", "???????????????????????§???");
		Q[tailQ] = y;
		if(tailQ + 1 == MAX)
			tailQ = 0;
		else
			tailQ++;
	}
	public static int dequeueQ(){
		if(isEmptyQ())
			System.out.printf("%s\n", "??¢????????????????????§???");
		int y = Q[headQ];
		if(headQ + 1 == MAX)
			headQ = 0;
		else
			headQ++;
		return y;
	}

	private static void initialize(){
		head = tail = 0;
	}
	private static boolean isEmpty(){
		return head == tail;
	}
	private static boolean isFull(){
		return head == (tail + 1) % MAX;
	}
	public static void enqueue(String x){
		if(isFull())
			System.out.printf("%s\n", "???????????????????????§???");
		P[tail] = x;
		if(tail + 1 == MAX)
			tail = 0;
		else
			tail++;
	}
	public static String dequeue(){
		if(isEmpty())
			System.out.printf("%s\n", "??¢????????????????????§???");
		String x = P[head];
		if(head + 1 == MAX)
			head = 0;
		else
			head++;
		return x;
	}
} import java.util.*; util.* java public class Main{
	private static final Scanner scan = new Scanner(System.in);
	private static final int MAX = 100_001;
	private static String[] P = new String[MAX];
	private static int[] Q = new int[MAX];
	private static int head, tail;
	private static int headQ, tailQ;

	public static void main(String[] args){

		initialize();
		initializeQ();
		int n = scan.nextInt();
		int q = scan.nextInt();
		String[] p = new String[n];
		for(int i = 0; i < n; i++){
			String s = scan.next();
			int m = scan.nextInt();
			enqueue(s);
			enqueueQ(m);
		}
		int total = 0;
		for(;;){
			String s = dequeue();
			int m = dequeueQ();
			if(m >q){
				total += q;
				m = m - q;
				enqueue(s);
				enqueueQ(m);
			}else{
				total += m;
				System.out.printf("%s ", s);
				System.out.printf("%d\n", total);
				if(isEmpty() && isEmptyQ())
					break;
			}
		}
	}

	private static void initializeQ(){
		headQ = tailQ = 0;
	}
	private static boolean isEmptyQ(){
		return headQ == tailQ;
	}
	private static boolean isFullQ(){
		return headQ == (tailQ + 1) % MAX;
	}
	public static void enqueueQ(int y){
		if(isFullQ())
			System.out.printf("%s\n", "???????????????????????§???");
		Q[tailQ] = y;
		if(tailQ + 1 == MAX)
			tailQ = 0;
		else
			tailQ++;
	}
	public static int dequeueQ(){
		if(isEmptyQ())
			System.out.printf("%s\n", "??¢????????????????????§???");
		int y = Q[headQ];
		if(headQ + 1 == MAX)
			headQ = 0;
		else
			headQ++;
		return y;
	}

	private static void initialize(){
		head = tail = 0;
	}
	private static boolean isEmpty(){
		return head == tail;
	}
	private static boolean isFull(){
		return head == (tail + 1) % MAX;
	}
	public static void enqueue(String x){
		if(isFull())
			System.out.printf("%s\n", "???????????????????????§???");
		P[tail] = x;
		if(tail + 1 == MAX)
			tail = 0;
		else
			tail++;
	}
	public static String dequeue(){
		if(isEmpty())
			System.out.printf("%s\n", "??¢????????????????????§???");
		String x = P[head];
		if(head + 1 == MAX)
			head = 0;
		else
			head++;
		return x;
	}
} Main private static final Scanner scan = new Scanner(System.in); scan new Scanner(System.in) private static final int MAX = 100_001; MAX 100_001 private static String[] P = new String[MAX]; P new String[MAX] MAX private static int[] Q = new int[MAX]; Q new int[MAX] MAX private static int head head tail; tail private static int headQ headQ tailQ; tailQ public static void main(String[] args){

		initialize();
		initializeQ();
		int n = scan.nextInt();
		int q = scan.nextInt();
		String[] p = new String[n];
		for(int i = 0; i < n; i++){
			String s = scan.next();
			int m = scan.nextInt();
			enqueue(s);
			enqueueQ(m);
		}
		int total = 0;
		for(;;){
			String s = dequeue();
			int m = dequeueQ();
			if(m >q){
				total += q;
				m = m - q;
				enqueue(s);
				enqueueQ(m);
			}else{
				total += m;
				System.out.printf("%s ", s);
				System.out.printf("%d\n", total);
				if(isEmpty() && isEmptyQ())
					break;
			}
		}
	} main {

		initialize();
		initializeQ();
		int n = scan.nextInt();
		int q = scan.nextInt();
		String[] p = new String[n];
		for(int i = 0; i < n; i++){
			String s = scan.next();
			int m = scan.nextInt();
			enqueue(s);
			enqueueQ(m);
		}
		int total = 0;
		for(;;){
			String s = dequeue();
			int m = dequeueQ();
			if(m >q){
				total += q;
				m = m - q;
				enqueue(s);
				enqueueQ(m);
			}else{
				total += m;
				System.out.printf("%s ", s);
				System.out.printf("%d\n", total);
				if(isEmpty() && isEmptyQ())
					break;
			}
		}
	} initialize() initialize initializeQ() initializeQ int n = scan.nextInt(); n scan.nextInt() scan.nextInt scan int q = scan.nextInt(); q scan.nextInt() scan.nextInt scan String[] p = new String[n]; p new String[n] n for(int i = 0; i < n; i++){
			String s = scan.next();
			int m = scan.nextInt();
			enqueue(s);
			enqueueQ(m);
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			String s = scan.next();
			int m = scan.nextInt();
			enqueue(s);
			enqueueQ(m);
		} {
			String s = scan.next();
			int m = scan.nextInt();
			enqueue(s);
			enqueueQ(m);
		} String s = scan.next(); s scan.next() scan.next scan int m = scan.nextInt(); m scan.nextInt() scan.nextInt scan enqueue(s) enqueue s enqueueQ(m) enqueueQ m int total = 0; total 0 for(;;){
			String s = dequeue();
			int m = dequeueQ();
			if(m >q){
				total += q;
				m = m - q;
				enqueue(s);
				enqueueQ(m);
			}else{
				total += m;
				System.out.printf("%s ", s);
				System.out.printf("%d\n", total);
				if(isEmpty() && isEmptyQ())
					break;
			}
		} ; {
			String s = dequeue();
			int m = dequeueQ();
			if(m >q){
				total += q;
				m = m - q;
				enqueue(s);
				enqueueQ(m);
			}else{
				total += m;
				System.out.printf("%s ", s);
				System.out.printf("%d\n", total);
				if(isEmpty() && isEmptyQ())
					break;
			}
		} {
			String s = dequeue();
			int m = dequeueQ();
			if(m >q){
				total += q;
				m = m - q;
				enqueue(s);
				enqueueQ(m);
			}else{
				total += m;
				System.out.printf("%s ", s);
				System.out.printf("%d\n", total);
				if(isEmpty() && isEmptyQ())
					break;
			}
		} String s = dequeue(); s dequeue() dequeue int m = dequeueQ(); m dequeueQ() dequeueQ if(m >q){
				total += q;
				m = m - q;
				enqueue(s);
				enqueueQ(m);
			}else{
				total += m;
				System.out.printf("%s ", s);
				System.out.printf("%d\n", total);
				if(isEmpty() && isEmptyQ())
					break;
			} m >q m q {
				total += q;
				m = m - q;
				enqueue(s);
				enqueueQ(m);
			} total += q total q m = m - q m m - q m q enqueue(s) enqueue s enqueueQ(m) enqueueQ m {
				total += m;
				System.out.printf("%s ", s);
				System.out.printf("%d\n", total);
				if(isEmpty() && isEmptyQ())
					break;
			} total += m total m System.out.printf("%s ", s) System.out.printf System.out System System.out "%s " s System.out.printf("%d\n", total) System.out.printf System.out System System.out "%d\n" total if(isEmpty() && isEmptyQ())
					break; isEmpty() && isEmptyQ() isEmpty() isEmpty isEmptyQ() isEmptyQ break; String[] args args private static void initializeQ(){
		headQ = tailQ = 0;
	} initializeQ {
		headQ = tailQ = 0;
	} headQ = tailQ = 0 headQ tailQ = 0 tailQ 0 private static boolean isEmptyQ(){
		return headQ == tailQ;
	} isEmptyQ {
		return headQ == tailQ;
	} return headQ == tailQ; headQ == tailQ headQ tailQ private static boolean isFullQ(){
		return headQ == (tailQ + 1) % MAX;
	} isFullQ {
		return headQ == (tailQ + 1) % MAX;
	} return headQ == (tailQ + 1) % MAX; headQ == (tailQ + 1) % MAX headQ (tailQ + 1) % MAX (tailQ + 1) tailQ 1 MAX public static void enqueueQ(int y){
		if(isFullQ())
			System.out.printf("%s\n", "???????????????????????§???");
		Q[tailQ] = y;
		if(tailQ + 1 == MAX)
			tailQ = 0;
		else
			tailQ++;
	} enqueueQ {
		if(isFullQ())
			System.out.printf("%s\n", "???????????????????????§???");
		Q[tailQ] = y;
		if(tailQ + 1 == MAX)
			tailQ = 0;
		else
			tailQ++;
	} if(isFullQ())
			System.out.printf("%s\n", "???????????????????????§???"); isFullQ() isFullQ System.out.printf("%s\n", "???????????????????????§???") System.out.printf System.out System System.out "%s\n" "???????????????????????§???" Q[tailQ] = y Q[tailQ] Q tailQ y if(tailQ + 1 == MAX)
			tailQ = 0;
		else
			tailQ++; tailQ + 1 == MAX tailQ + 1 tailQ 1 MAX tailQ = 0 tailQ 0 tailQ++ tailQ int y y public static int dequeueQ(){
		if(isEmptyQ())
			System.out.printf("%s\n", "??¢????????????????????§???");
		int y = Q[headQ];
		if(headQ + 1 == MAX)
			headQ = 0;
		else
			headQ++;
		return y;
	} dequeueQ {
		if(isEmptyQ())
			System.out.printf("%s\n", "??¢????????????????????§???");
		int y = Q[headQ];
		if(headQ + 1 == MAX)
			headQ = 0;
		else
			headQ++;
		return y;
	} if(isEmptyQ())
			System.out.printf("%s\n", "??¢????????????????????§???"); isEmptyQ() isEmptyQ System.out.printf("%s\n", "??¢????????????????????§???") System.out.printf System.out System System.out "%s\n" "??¢????????????????????§???" int y = Q[headQ]; y Q[headQ] Q headQ if(headQ + 1 == MAX)
			headQ = 0;
		else
			headQ++; headQ + 1 == MAX headQ + 1 headQ 1 MAX headQ = 0 headQ 0 headQ++ headQ return y; y private static void initialize(){
		head = tail = 0;
	} initialize {
		head = tail = 0;
	} head = tail = 0 head tail = 0 tail 0 private static boolean isEmpty(){
		return head == tail;
	} isEmpty {
		return head == tail;
	} return head == tail; head == tail head tail private static boolean isFull(){
		return head == (tail + 1) % MAX;
	} isFull {
		return head == (tail + 1) % MAX;
	} return head == (tail + 1) % MAX; head == (tail + 1) % MAX head (tail + 1) % MAX (tail + 1) tail 1 MAX public static void enqueue(String x){
		if(isFull())
			System.out.printf("%s\n", "???????????????????????§???");
		P[tail] = x;
		if(tail + 1 == MAX)
			tail = 0;
		else
			tail++;
	} enqueue {
		if(isFull())
			System.out.printf("%s\n", "???????????????????????§???");
		P[tail] = x;
		if(tail + 1 == MAX)
			tail = 0;
		else
			tail++;
	} if(isFull())
			System.out.printf("%s\n", "???????????????????????§???"); isFull() isFull System.out.printf("%s\n", "???????????????????????§???") System.out.printf System.out System System.out "%s\n" "???????????????????????§???" P[tail] = x P[tail] P tail x if(tail + 1 == MAX)
			tail = 0;
		else
			tail++; tail + 1 == MAX tail + 1 tail 1 MAX tail = 0 tail 0 tail++ tail String x x public static String dequeue(){
		if(isEmpty())
			System.out.printf("%s\n", "??¢????????????????????§???");
		String x = P[head];
		if(head + 1 == MAX)
			head = 0;
		else
			head++;
		return x;
	} dequeue {
		if(isEmpty())
			System.out.printf("%s\n", "??¢????????????????????§???");
		String x = P[head];
		if(head + 1 == MAX)
			head = 0;
		else
			head++;
		return x;
	} if(isEmpty())
			System.out.printf("%s\n", "??¢????????????????????§???"); isEmpty() isEmpty System.out.printf("%s\n", "??¢????????????????????§???") System.out.printf System.out System System.out "%s\n" "??¢????????????????????§???" String x = P[head]; x P[head] P head if(head + 1 == MAX)
			head = 0;
		else
			head++; head + 1 == MAX head + 1 head 1 MAX head = 0 head 0 head++ head return x; x public class Main{
	private static final Scanner scan = new Scanner(System.in);
	private static final int MAX = 100_001;
	private static String[] P = new String[MAX];
	private static int[] Q = new int[MAX];
	private static int head, tail;
	private static int headQ, tailQ;

	public static void main(String[] args){

		initialize();
		initializeQ();
		int n = scan.nextInt();
		int q = scan.nextInt();
		String[] p = new String[n];
		for(int i = 0; i < n; i++){
			String s = scan.next();
			int m = scan.nextInt();
			enqueue(s);
			enqueueQ(m);
		}
		int total = 0;
		for(;;){
			String s = dequeue();
			int m = dequeueQ();
			if(m >q){
				total += q;
				m = m - q;
				enqueue(s);
				enqueueQ(m);
			}else{
				total += m;
				System.out.printf("%s ", s);
				System.out.printf("%d\n", total);
				if(isEmpty() && isEmptyQ())
					break;
			}
		}
	}

	private static void initializeQ(){
		headQ = tailQ = 0;
	}
	private static boolean isEmptyQ(){
		return headQ == tailQ;
	}
	private static boolean isFullQ(){
		return headQ == (tailQ + 1) % MAX;
	}
	public static void enqueueQ(int y){
		if(isFullQ())
			System.out.printf("%s\n", "???????????????????????§???");
		Q[tailQ] = y;
		if(tailQ + 1 == MAX)
			tailQ = 0;
		else
			tailQ++;
	}
	public static int dequeueQ(){
		if(isEmptyQ())
			System.out.printf("%s\n", "??¢????????????????????§???");
		int y = Q[headQ];
		if(headQ + 1 == MAX)
			headQ = 0;
		else
			headQ++;
		return y;
	}

	private static void initialize(){
		head = tail = 0;
	}
	private static boolean isEmpty(){
		return head == tail;
	}
	private static boolean isFull(){
		return head == (tail + 1) % MAX;
	}
	public static void enqueue(String x){
		if(isFull())
			System.out.printf("%s\n", "???????????????????????§???");
		P[tail] = x;
		if(tail + 1 == MAX)
			tail = 0;
		else
			tail++;
	}
	public static String dequeue(){
		if(isEmpty())
			System.out.printf("%s\n", "??¢????????????????????§???");
		String x = P[head];
		if(head + 1 == MAX)
			head = 0;
		else
			head++;
		return x;
	}
} public class Main{
	private static final Scanner scan = new Scanner(System.in);
	private static final int MAX = 100_001;
	private static String[] P = new String[MAX];
	private static int[] Q = new int[MAX];
	private static int head, tail;
	private static int headQ, tailQ;

	public static void main(String[] args){

		initialize();
		initializeQ();
		int n = scan.nextInt();
		int q = scan.nextInt();
		String[] p = new String[n];
		for(int i = 0; i < n; i++){
			String s = scan.next();
			int m = scan.nextInt();
			enqueue(s);
			enqueueQ(m);
		}
		int total = 0;
		for(;;){
			String s = dequeue();
			int m = dequeueQ();
			if(m >q){
				total += q;
				m = m - q;
				enqueue(s);
				enqueueQ(m);
			}else{
				total += m;
				System.out.printf("%s ", s);
				System.out.printf("%d\n", total);
				if(isEmpty() && isEmptyQ())
					break;
			}
		}
	}

	private static void initializeQ(){
		headQ = tailQ = 0;
	}
	private static boolean isEmptyQ(){
		return headQ == tailQ;
	}
	private static boolean isFullQ(){
		return headQ == (tailQ + 1) % MAX;
	}
	public static void enqueueQ(int y){
		if(isFullQ())
			System.out.printf("%s\n", "???????????????????????§???");
		Q[tailQ] = y;
		if(tailQ + 1 == MAX)
			tailQ = 0;
		else
			tailQ++;
	}
	public static int dequeueQ(){
		if(isEmptyQ())
			System.out.printf("%s\n", "??¢????????????????????§???");
		int y = Q[headQ];
		if(headQ + 1 == MAX)
			headQ = 0;
		else
			headQ++;
		return y;
	}

	private static void initialize(){
		head = tail = 0;
	}
	private static boolean isEmpty(){
		return head == tail;
	}
	private static boolean isFull(){
		return head == (tail + 1) % MAX;
	}
	public static void enqueue(String x){
		if(isFull())
			System.out.printf("%s\n", "???????????????????????§???");
		P[tail] = x;
		if(tail + 1 == MAX)
			tail = 0;
		else
			tail++;
	}
	public static String dequeue(){
		if(isEmpty())
			System.out.printf("%s\n", "??¢????????????????????§???");
		String x = P[head];
		if(head + 1 == MAX)
			head = 0;
		else
			head++;
		return x;
	}
} Main
import java.util.*;

public class Main{
	private static final Scanner scan = new Scanner(System.in);
	private static final int MAX = 100_001;
	private static String[] P = new String[MAX];
	private static int[] Q = new int[MAX];
	private static int head, tail;
	private static int headQ, tailQ;

	public static void main(String[] args){

		initialize();
		initializeQ();
		int n = scan.nextInt();
		int q = scan.nextInt();
		String[] p = new String[n];
		for(int i = 0; i < n; i++){
			String s = scan.next();
			int m = scan.nextInt();
			enqueue(s);
			enqueueQ(m);
		}
		int total = 0;
		for(;;){
			String s = dequeue();
			int m = dequeueQ();
			if(m >q){
				total += q;
				m = m - q;
				enqueue(s);
				enqueueQ(m);
			}else{
				total += m;
				System.out.printf("%s ", s);
				System.out.printf("%d\n", total);
				if(isEmpty() && isEmptyQ())
					break;
			}
		}
	}

	private static void initializeQ(){
		headQ = tailQ = 0;
	}
	private static boolean isEmptyQ(){
		return headQ == tailQ;
	}
	private static boolean isFullQ(){
		return headQ == (tailQ + 1) % MAX;
	}
	public static void enqueueQ(int y){
		if(isFullQ())
			System.out.printf("%s\n", "???????????????????????§???");
		Q[tailQ] = y;
		if(tailQ + 1 == MAX)
			tailQ = 0;
		else
			tailQ++;
	}
	public static int dequeueQ(){
		if(isEmptyQ())
			System.out.printf("%s\n", "??¢????????????????????§???");
		int y = Q[headQ];
		if(headQ + 1 == MAX)
			headQ = 0;
		else
			headQ++;
		return y;
	}

	private static void initialize(){
		head = tail = 0;
	}
	private static boolean isEmpty(){
		return head == tail;
	}
	private static boolean isFull(){
		return head == (tail + 1) % MAX;
	}
	public static void enqueue(String x){
		if(isFull())
			System.out.printf("%s\n", "???????????????????????§???");
		P[tail] = x;
		if(tail + 1 == MAX)
			tail = 0;
		else
			tail++;
	}
	public static String dequeue(){
		if(isEmpty())
			System.out.printf("%s\n", "??¢????????????????????§???");
		String x = P[head];
		if(head + 1 == MAX)
			head = 0;
		else
			head++;
		return x;
	}
}