#include <bits/stdc++.h>
using namespace std;
long long U[35];
long long T, n, k, ans;
inline void work() {
  cin >> n >> k;
  if (n > 31 || U[n - 1] + 1 >= k) {
    cout << "YES " << n - 1 << endl;
    return;
  }
  if (k > U[n]) {
    puts("NO");
    return;
  }
  for (long long i = n - 2; ~i; --i) {
    if ((1ll << (n - i + 1)) + i - n - 2 > k ||
        U[n] - U[i] * ((1ll << (n - i + 1)) - 1) < k)
      continue;
    {
      cout << "YES " << i << endl;
      return;
    }
  }
  {
    puts("NO");
    return;
  }
}
int main() {
  for (int i = 1; i <= 31; ++i) U[i] = (U[i - 1] << 2) + 1;
  cin >> T;
  while (T--) work();
  return 0;
}
