#include <iostream>
#include <cmath>
using namespace std;

int n, i, a;


int main(){
  cin >> n;
  int bigger = 1;

  while (n--){
    cin >> i >> a;
    bigger = a;

   while (a!=1){
    if (a%2==0){
      a = a/2;
      bigger = max(bigger, a);
    }
    else {
     a = 3*a+1; 
     bigger = max(bigger, a);
    }
  }  
   cout << i << ' ' << bigger << '\n';
 }

  return 0;
}