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

typedef long long ll;
int N, K;
ll A, M;

int main() {
  ios::sync_with_stdio(0);
  cin.tie();

  cin >> N;
  while (N--) {
    cin >> K >> A;
    M = 1;
    while (A != 1) {
      M = max(M, A);
      if (A & 1) {
        A = 3 * A + 1;
      } else {
        A = A / 2;
      }
    }
    cout << K << " " << M << endl;
  }

  return 0;
}