#include <iostream>
using namespace std;

typedef long long ll;

#define endl '\n'

int main() {
  ios::sync_with_stdio(0);
  ll set_counter;
  cin >> set_counter;

  for (ll i = 0; i < set_counter; i++) {
    ll a,b;
    cin >> a >> b;
    ll b_largest = b;
    ll b_current = b;

    while (b_current != (1||2||4)) {
      if (b_current%2 == 0) {
        b_current = b_current / 2;
      }
      else {
        b_current = b_current * 3 + 1;
      }
      if (b_current > b_largest) {
        b_largest = b_current;
      }
    }
    cout << a << " " << b_largest << endl;
  }
  return 0;
}