#include <iostream>

int main(int argc, char** argv) {
    std::ios_base::sync_with_stdio(0);
    std::cin.tie(0);
    int n, set, x, m;
    std::cin >> n;
    for(int i = 0 ; i < n; i++) {
        std::cin >> set >> x;
        std::cout << set << " ";
        m = x;
        while(x != 1) {
            if(x % 2) {
                x = 3*x + 1;
                if(x > m)
                    m = x;
            } else {
                x = x >> 1;
            }
        }
        std::cout << m << std::endl;
    }
return 0; 
}