import java.util.Scanner;
import java.util.SortedMap;
import java.util.TreeMap;

public class B {
    public static void main(String[] args) {
        Scanner reader = new Scanner(System.in);
        SortedMap<Integer, Integer> numbers = new TreeMap<>();

        int cases = reader.nextInt();

        for (int i = cases; i > 0; i--) {
            int caseNo = reader.nextInt();
            int start = reader.nextInt();
            numbers.put(caseNo, start);
        }

        for (int i : numbers.keySet()) {
            System.out.print(i);
            int n = numbers.get(i);
            int biggestNum = n;
            while (n != 1) {
                if (n % 2 == 0) {
                    n /= 2;
                } else
                    n = n*3 + 1;
                if (n > biggestNum)
                    biggestNum = n;
            }
            System.out.println(" " + biggestNum);
        }
    }
}