#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <math.h>
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <stdlib.h>
#include <cassert>
#include <string.h>

#include <time.h>
#include <random>
#include <iomanip>
using namespace std;

#define ll long long
#define N 1000005


int main() {
    std::ios::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    cin >> n;
    for (ll i = 0; i < n; i++) {
        ll z, a;
        cin >> z >> a;
        ll m = a;
        while (a != 1) {
            if (a%2)
                a = a*3+1;
            else
                a/=2;
            m = max(m, a);
        }
        cout << z << " " << m << endl;
        
    }


}