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

int p;
int d;
long long n;
long long largest;

int main() {
    ios::sync_with_stdio(0);
    cin.tie();
	cin >> p;
	for (int i=0; i<p; i++) {
		cin >> d >> n;
		largest = 1;
		while (true) {
			if (n==1) break;
			if (n > largest) {
				largest = n;
			}
			if (n % 2 == 0) {
				n = n/2;
			} else {
				n = 3*n+1;
			}
		}
		cout << d << ' ' << largest << '\n';
	}
	return 0;
}