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

long long getLargest(long long n, long long& largest) {
  if (n == 1) {
    return 1;
  }
  largest = max(n, largest);
  if (n & 1) {
    return getLargest(n * 3 + 1, largest);
  } else {
    return getLargest(n / 2, largest);
  }
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long p;
  long long num, n;
  cin >> p;
  while (p--) {
    long long largest = 1;
    cin >> num >> n;
    getLargest(n, largest);
    cout << num << ' ' << largest << '\n';
  }
  return 0;
}