import java.util.ArrayList;
import java.util.Scanner;

public class B {
	private static ArrayList<Integer> arr = new ArrayList<Integer>();
	
	public static void generateArr(){
		for (int i = 0; i < 100000; i++){
			int value = i+1;
			int maxSoFar = value;
			
			while (value != 1){
				if (value % 2 == 0){
					value /= 2;
				}
				else {
					value *= 3;
					value++;
					if (value > maxSoFar){
						maxSoFar = value;
					}
				}
				if (value < arr.size() - 1){
					maxSoFar = Math.max(maxSoFar, arr.get(value - 1));
					break;
				}
			}
			arr.add(maxSoFar);
		}
	}
	
	public static void main (String [] args){
		Scanner scan = new Scanner (System.in);
		
		int tests = scan.nextInt();
		generateArr();
		
		for (int i = 1; i <= tests; i++){
			System.out.println(scan.nextInt() + " " + arr.get(scan.nextInt() - 1));
		}
		scan.close();
	}
}