import java.util.*;

import static java.lang.System.out;

/**
 * Created by Vince on 2017-01-14.
 */
public class leveltwo {


    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int I = sc.nextInt();
        int mem[] = new int[I];
        for (int i = 0; i < I; i++) {
            sc.nextInt();
            mem[i] = sc.nextInt();
        }

        for (int i = 0; i < I; i++) {
            int current = mem[i];
            int result = mem[i];

            while (current != 1){
                if ((current % 2) == 0) {
                    current = current / 2;
                    if (current >= result) {
                        result = current;
                    }
                } else {
                    current = 3 * current + 1;
                    if (current >= result) {
                        result = current;
                    }
                }
            }
            out.printf(String.valueOf(i + 1) + " " + String.valueOf(result) + "\n");


        }

    }


}