#include <bits/stdc++.h>
using namespace std;
template <class T>
using VV = vector<vector<T>>;
template <class T>
inline T SMIN(T& a, const T b) {
  return a = (a > b) ? b : a;
}
template <class T>
inline T SMAX(T& a, const T b) {
  return a = (a < b) ? b : a;
}
template <class Iter>
void dumpc(Iter begin, Iter end) {
  if (false) {
    for (; begin != end; ++begin) {
      cerr << *begin << ',';
    }
    cerr << endl;
  }
}
int T;
long long N, K;
long long P4[32], P2[63];
void solve() {
  P4[0] = P2[0] = 1;
  for (int i = 0; i < (31); ++i) P4[i + 1] = P4[i] * 4LL;
  for (int i = 0; i < (62); ++i) P2[i + 1] = P2[i] * 2LL;
  const long long Inf = (long long)4e18;
  for (int x = (1); x <= (min(31, (int)N)); ++x) {
    if (false) {
      cerr << "x"
           << " = " << (x) << endl;
    };
    long long ub = P4[x];
    ub = (ub - 1) / 3;
    if (N - x >= 32)
      ub = Inf;
    else {
      if (false) {
        cerr << "2 * x"
             << " = " << (2 * x) << ", "
             << "x"
             << " = " << (x) << ", "
             << "N"
             << " = " << (N) << ", "
             << "N - x"
             << " = " << (N - x) << endl;
      };
      long long a = P2[2 * x] - P2[x + 1] + 1;
      long long b = (P4[N - x] - 1) / 3;
      ub += a * b;
    }
    long long lb = P2[x + 1] - x - 2;
    if (false) {
      cerr << "x"
           << " = " << (x) << ", "
           << "lb"
           << " = " << (lb) << ", "
           << "K"
           << " = " << (K) << ", "
           << "ub"
           << " = " << (ub) << endl;
    };
    if (lb <= K && K <= ub) {
      fprintf(stdout, "YES %lld", N - x), putchar('\n');
      ;
      return;
    }
  }
  fprintf(stdout, "NO"), putchar('\n');
  ;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> T;
  for (int i = 0; i < (T); ++i) {
    cin >> N >> K;
    solve();
  }
  return 0;
}
