import java.io.IOException;
import java.util.Scanner;
class Main{
	public static void main(String[] args)throws NumberFormatException, IOException{
//		System.out.println(" ");
		Scanner scan = new Scanner(System.in);
		int queueAmount = scan.nextInt();
		int qTime = scan.nextInt();
		int totalTime = 0;
		int[] proNum = new int[queueAmount+1];	//?????°?????????????????????1????????¨??????
		String[] proID = new String[queueAmount+1];

		for(int i=0; i<queueAmount; i++){
			proID[i] = scan.next();
			proNum[i] = scan.nextInt();
		}
		int dataTop = 0;
		int dataBottom = queueAmount-1;
		proNum[queueAmount] = 0;
		
		while(true){
			//?????????????????????????????????????????????
			if(proNum[dataTop] <= qTime){			
				totalTime = totalTime + proNum[dataTop];
				System.out.println(proID[dataTop]+" "+(totalTime) );
				//???????????§?????£??????break
				if(dataTop == dataBottom) break;
				
				dataTop += 1;
				if(dataTop > queueAmount){
					dataTop = 0;
				}
			}
			else{
				proNum[dataTop] -= qTime;
				totalTime += qTime;
				//????????????????°????1???????????????????????§????????£??????0?????????
//				System.out.println("?????? "+proID[dataTop]+" "+proNum[dataTop]);
				dataBottom += 1;
				if(dataBottom > queueAmount){
					dataBottom = 0;
				}
				//???????°???????????????????????????£??\
				proNum[dataBottom] = proNum[dataTop];
				proID[dataBottom] = proID[dataTop];
				dataTop += 1;
				if(dataTop > queueAmount){
					dataTop = 0;
				}
			}
//			System.out.println("totaltime is "+totalTime);
		}
	}
} import java.io.IOException; IOException java.io import java.util.Scanner; Scanner java.util class Main{
	public static void main(String[] args)throws NumberFormatException, IOException{
//		System.out.println(" ");
		Scanner scan = new Scanner(System.in);
		int queueAmount = scan.nextInt();
		int qTime = scan.nextInt();
		int totalTime = 0;
		int[] proNum = new int[queueAmount+1];	//?????°?????????????????????1????????¨??????
		String[] proID = new String[queueAmount+1];

		for(int i=0; i<queueAmount; i++){
			proID[i] = scan.next();
			proNum[i] = scan.nextInt();
		}
		int dataTop = 0;
		int dataBottom = queueAmount-1;
		proNum[queueAmount] = 0;
		
		while(true){
			//?????????????????????????????????????????????
			if(proNum[dataTop] <= qTime){			
				totalTime = totalTime + proNum[dataTop];
				System.out.println(proID[dataTop]+" "+(totalTime) );
				//???????????§?????£??????break
				if(dataTop == dataBottom) break;
				
				dataTop += 1;
				if(dataTop > queueAmount){
					dataTop = 0;
				}
			}
			else{
				proNum[dataTop] -= qTime;
				totalTime += qTime;
				//????????????????°????1???????????????????????§????????£??????0?????????
//				System.out.println("?????? "+proID[dataTop]+" "+proNum[dataTop]);
				dataBottom += 1;
				if(dataBottom > queueAmount){
					dataBottom = 0;
				}
				//???????°???????????????????????????£??\
				proNum[dataBottom] = proNum[dataTop];
				proID[dataBottom] = proID[dataTop];
				dataTop += 1;
				if(dataTop > queueAmount){
					dataTop = 0;
				}
			}
//			System.out.println("totaltime is "+totalTime);
		}
	}
} Main public static void main(String[] args)throws NumberFormatException, IOException{
//		System.out.println(" ");
		Scanner scan = new Scanner(System.in);
		int queueAmount = scan.nextInt();
		int qTime = scan.nextInt();
		int totalTime = 0;
		int[] proNum = new int[queueAmount+1];	//?????°?????????????????????1????????¨??????
		String[] proID = new String[queueAmount+1];

		for(int i=0; i<queueAmount; i++){
			proID[i] = scan.next();
			proNum[i] = scan.nextInt();
		}
		int dataTop = 0;
		int dataBottom = queueAmount-1;
		proNum[queueAmount] = 0;
		
		while(true){
			//?????????????????????????????????????????????
			if(proNum[dataTop] <= qTime){			
				totalTime = totalTime + proNum[dataTop];
				System.out.println(proID[dataTop]+" "+(totalTime) );
				//???????????§?????£??????break
				if(dataTop == dataBottom) break;
				
				dataTop += 1;
				if(dataTop > queueAmount){
					dataTop = 0;
				}
			}
			else{
				proNum[dataTop] -= qTime;
				totalTime += qTime;
				//????????????????°????1???????????????????????§????????£??????0?????????
//				System.out.println("?????? "+proID[dataTop]+" "+proNum[dataTop]);
				dataBottom += 1;
				if(dataBottom > queueAmount){
					dataBottom = 0;
				}
				//???????°???????????????????????????£??\
				proNum[dataBottom] = proNum[dataTop];
				proID[dataBottom] = proID[dataTop];
				dataTop += 1;
				if(dataTop > queueAmount){
					dataTop = 0;
				}
			}
//			System.out.println("totaltime is "+totalTime);
		}
	} main {
//		System.out.println(" ");
		Scanner scan = new Scanner(System.in);
		int queueAmount = scan.nextInt();
		int qTime = scan.nextInt();
		int totalTime = 0;
		int[] proNum = new int[queueAmount+1];	//?????°?????????????????????1????????¨??????
		String[] proID = new String[queueAmount+1];

		for(int i=0; i<queueAmount; i++){
			proID[i] = scan.next();
			proNum[i] = scan.nextInt();
		}
		int dataTop = 0;
		int dataBottom = queueAmount-1;
		proNum[queueAmount] = 0;
		
		while(true){
			//?????????????????????????????????????????????
			if(proNum[dataTop] <= qTime){			
				totalTime = totalTime + proNum[dataTop];
				System.out.println(proID[dataTop]+" "+(totalTime) );
				//???????????§?????£??????break
				if(dataTop == dataBottom) break;
				
				dataTop += 1;
				if(dataTop > queueAmount){
					dataTop = 0;
				}
			}
			else{
				proNum[dataTop] -= qTime;
				totalTime += qTime;
				//????????????????°????1???????????????????????§????????£??????0?????????
//				System.out.println("?????? "+proID[dataTop]+" "+proNum[dataTop]);
				dataBottom += 1;
				if(dataBottom > queueAmount){
					dataBottom = 0;
				}
				//???????°???????????????????????????£??\
				proNum[dataBottom] = proNum[dataTop];
				proID[dataBottom] = proID[dataTop];
				dataTop += 1;
				if(dataTop > queueAmount){
					dataTop = 0;
				}
			}
//			System.out.println("totaltime is "+totalTime);
		}
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int queueAmount = scan.nextInt(); queueAmount scan.nextInt() scan.nextInt scan int qTime = scan.nextInt(); qTime scan.nextInt() scan.nextInt scan int totalTime = 0; totalTime 0 int[] proNum = new int[queueAmount+1]; proNum new int[queueAmount+1] queueAmount+1 queueAmount 1 String[] proID = new String[queueAmount+1]; proID new String[queueAmount+1] queueAmount+1 queueAmount 1 for(int i=0; i<queueAmount; i++){
			proID[i] = scan.next();
			proNum[i] = scan.nextInt();
		} int i=0; int i=0; i 0 i<queueAmount i queueAmount i++ i++ i {
			proID[i] = scan.next();
			proNum[i] = scan.nextInt();
		} {
			proID[i] = scan.next();
			proNum[i] = scan.nextInt();
		} proID[i] = scan.next() proID[i] proID i scan.next() scan.next scan proNum[i] = scan.nextInt() proNum[i] proNum i scan.nextInt() scan.nextInt scan int dataTop = 0; dataTop 0 int dataBottom = queueAmount-1; dataBottom queueAmount-1 queueAmount 1 proNum[queueAmount] = 0 proNum[queueAmount] proNum queueAmount 0 while(true){
			//?????????????????????????????????????????????
			if(proNum[dataTop] <= qTime){			
				totalTime = totalTime + proNum[dataTop];
				System.out.println(proID[dataTop]+" "+(totalTime) );
				//???????????§?????£??????break
				if(dataTop == dataBottom) break;
				
				dataTop += 1;
				if(dataTop > queueAmount){
					dataTop = 0;
				}
			}
			else{
				proNum[dataTop] -= qTime;
				totalTime += qTime;
				//????????????????°????1???????????????????????§????????£??????0?????????
//				System.out.println("?????? "+proID[dataTop]+" "+proNum[dataTop]);
				dataBottom += 1;
				if(dataBottom > queueAmount){
					dataBottom = 0;
				}
				//???????°???????????????????????????£??\
				proNum[dataBottom] = proNum[dataTop];
				proID[dataBottom] = proID[dataTop];
				dataTop += 1;
				if(dataTop > queueAmount){
					dataTop = 0;
				}
			}
//			System.out.println("totaltime is "+totalTime);
		} true {
			//?????????????????????????????????????????????
			if(proNum[dataTop] <= qTime){			
				totalTime = totalTime + proNum[dataTop];
				System.out.println(proID[dataTop]+" "+(totalTime) );
				//???????????§?????£??????break
				if(dataTop == dataBottom) break;
				
				dataTop += 1;
				if(dataTop > queueAmount){
					dataTop = 0;
				}
			}
			else{
				proNum[dataTop] -= qTime;
				totalTime += qTime;
				//????????????????°????1???????????????????????§????????£??????0?????????
//				System.out.println("?????? "+proID[dataTop]+" "+proNum[dataTop]);
				dataBottom += 1;
				if(dataBottom > queueAmount){
					dataBottom = 0;
				}
				//???????°???????????????????????????£??\
				proNum[dataBottom] = proNum[dataTop];
				proID[dataBottom] = proID[dataTop];
				dataTop += 1;
				if(dataTop > queueAmount){
					dataTop = 0;
				}
			}
//			System.out.println("totaltime is "+totalTime);
		} if(proNum[dataTop] <= qTime){			
				totalTime = totalTime + proNum[dataTop];
				System.out.println(proID[dataTop]+" "+(totalTime) );
				//???????????§?????£??????break
				if(dataTop == dataBottom) break;
				
				dataTop += 1;
				if(dataTop > queueAmount){
					dataTop = 0;
				}
			}
			else{
				proNum[dataTop] -= qTime;
				totalTime += qTime;
				//????????????????°????1???????????????????????§????????£??????0?????????
//				System.out.println("?????? "+proID[dataTop]+" "+proNum[dataTop]);
				dataBottom += 1;
				if(dataBottom > queueAmount){
					dataBottom = 0;
				}
				//???????°???????????????????????????£??\
				proNum[dataBottom] = proNum[dataTop];
				proID[dataBottom] = proID[dataTop];
				dataTop += 1;
				if(dataTop > queueAmount){
					dataTop = 0;
				}
			} proNum[dataTop] <= qTime proNum[dataTop] proNum dataTop qTime {			
				totalTime = totalTime + proNum[dataTop];
				System.out.println(proID[dataTop]+" "+(totalTime) );
				//???????????§?????£??????break
				if(dataTop == dataBottom) break;
				
				dataTop += 1;
				if(dataTop > queueAmount){
					dataTop = 0;
				}
			} totalTime = totalTime + proNum[dataTop] totalTime totalTime + proNum[dataTop] totalTime proNum[dataTop] proNum dataTop System.out.println(proID[dataTop]+" "+(totalTime) ) System.out.println System.out System System.out proID[dataTop]+" "+(totalTime) proID[dataTop]+" "+(totalTime) proID[dataTop] proID dataTop " " (totalTime) if(dataTop == dataBottom) break; dataTop == dataBottom dataTop dataBottom break; dataTop += 1 dataTop 1 if(dataTop > queueAmount){
					dataTop = 0;
				} dataTop > queueAmount dataTop queueAmount {
					dataTop = 0;
				} dataTop = 0 dataTop 0 {
				proNum[dataTop] -= qTime;
				totalTime += qTime;
				//????????????????°????1???????????????????????§????????£??????0?????????
//				System.out.println("?????? "+proID[dataTop]+" "+proNum[dataTop]);
				dataBottom += 1;
				if(dataBottom > queueAmount){
					dataBottom = 0;
				}
				//???????°???????????????????????????£??\
				proNum[dataBottom] = proNum[dataTop];
				proID[dataBottom] = proID[dataTop];
				dataTop += 1;
				if(dataTop > queueAmount){
					dataTop = 0;
				}
			} proNum[dataTop] -= qTime proNum[dataTop] proNum dataTop qTime totalTime += qTime totalTime qTime dataBottom += 1 dataBottom 1 if(dataBottom > queueAmount){
					dataBottom = 0;
				} dataBottom > queueAmount dataBottom queueAmount {
					dataBottom = 0;
				} dataBottom = 0 dataBottom 0 proNum[dataBottom] = proNum[dataTop] proNum[dataBottom] proNum dataBottom proNum[dataTop] proNum dataTop proID[dataBottom] = proID[dataTop] proID[dataBottom] proID dataBottom proID[dataTop] proID dataTop dataTop += 1 dataTop 1 if(dataTop > queueAmount){
					dataTop = 0;
				} dataTop > queueAmount dataTop queueAmount {
					dataTop = 0;
				} dataTop = 0 dataTop 0 String[] args args
import java.io.IOException;
import java.util.Scanner;
class Main{
	public static void main(String[] args)throws NumberFormatException, IOException{
//		System.out.println(" ");
		Scanner scan = new Scanner(System.in);
		int queueAmount = scan.nextInt();
		int qTime = scan.nextInt();
		int totalTime = 0;
		int[] proNum = new int[queueAmount+1];	//?????°?????????????????????1????????¨??????
		String[] proID = new String[queueAmount+1];

		for(int i=0; i<queueAmount; i++){
			proID[i] = scan.next();
			proNum[i] = scan.nextInt();
		}
		int dataTop = 0;
		int dataBottom = queueAmount-1;
		proNum[queueAmount] = 0;
		
		while(true){
			//?????????????????????????????????????????????
			if(proNum[dataTop] <= qTime){			
				totalTime = totalTime + proNum[dataTop];
				System.out.println(proID[dataTop]+" "+(totalTime) );
				//???????????§?????£??????break
				if(dataTop == dataBottom) break;
				
				dataTop += 1;
				if(dataTop > queueAmount){
					dataTop = 0;
				}
			}
			else{
				proNum[dataTop] -= qTime;
				totalTime += qTime;
				//????????????????°????1???????????????????????§????????£??????0?????????
//				System.out.println("?????? "+proID[dataTop]+" "+proNum[dataTop]);
				dataBottom += 1;
				if(dataBottom > queueAmount){
					dataBottom = 0;
				}
				//???????°???????????????????????????£??\
				proNum[dataBottom] = proNum[dataTop];
				proID[dataBottom] = proID[dataTop];
				dataTop += 1;
				if(dataTop > queueAmount){
					dataTop = 0;
				}
			}
//			System.out.println("totaltime is "+totalTime);
		}
	}
}