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

typedef long long ll;

int main() {
  ios::sync_with_stdio(0);
  int p; cin >> p;
  for (int P = 1; P <= p; P++) {
    ll a, n; cin >> a >> n;
    ll mx = n;
    while (n != 1) {
      mx = max(mx,n);
      if (n % 2)
        n = n*3+1;
      else
        n /= 2;
    }
    cout << P << " " << mx << "\n";
  }
  return 0;
}