#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;

#define endl '\n'

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