#include <iostream>
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int cases;
    cin >> cases;
    for (int test = 0; test < cases; ++test) {
        long long i, n, m;
        cin >> i >> n;
        m = n;
        while (n != 1) {
            if (n > m) m = n;
            if (n % 2 == 0) n = n / 2;
            else n = n * 3 + 1;
        }
        cout << i << ' ' << m << '\n';
    }
    return 0;
}