import java.util.*;
import java.io.*;
public class B {
	public static void main(String[] args) throws IOException {
		// Scanner in = new Scanner(System.in);
		Scanner in = new Scanner(System.in);
		int P = in.nextInt();
		int[] indicies = new int[P];
		int[] ns = new int[P];
		for (int i = 0;i < P ;i++ ) {
			int index = in.nextInt();
			int n = in.nextInt();
			indicies[i] = index;
			ns[i] = n;
		}
		for (int i = 0; i < P; i++ ) {
			System.out.println((i+1) + " " + findMax(ns[i]));
		}
	}
	public static int findMax(int n) {
		int max = n;
		while(n != 1) {
			if (n % 2 == 0) {
				n /= 2;
			} else {
				n = 3 * n + 1;
			}
			if (n > max) {
				max = n;
			}
		}
		return max;
	}
}