#include <bits/stdtr1c++.h>

using namespace std;

typedef long double ld;
typedef long long ll;
typedef pair<ll, ll> pii;
typedef complex<ld> pt;

int main() {
	ios::sync_with_stdio(0);
	int t; cin >> t;
	while (t--) {
		ll s, a; cin >> s >> a;
		cout << s << " ";
		
		ll ans = 1;
		while (a != 1) {
			ans = max(ans, a);
			if (a%2 == 0) a /= 2;
			else a = 3*a + 1;
		}
		cout << ans << endl;
	}
	return 0;
}