#include <iostream>
using namespace std;

int main() {
	// your code goes here
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int a, b, cc, e =0;
	cin >> a;
	while (a>e) {
		cin >> b;
		cin >> cc;
		long long c = cc;
		long long d = c;
		while (c>1) {
			if (c%2==0) {
				c = c/2;
			} else {
				c = c*3 + 1;
			}
			if (c>d) {
				d = c;
			}
		}
		cout << b << " " << d << endl;
		e++;
	}
	return 0;
}