#include <bits/stdc++.h>
using namespace std;
inline long long getLen(long long n, long long k) {
  long long divisions = 1;
  k--;
  long long len = 1;
  while (divisions < n && k >= 4 * len - 1) {
    k -= 4 * len - 1;
    len *= 2;
    divisions++;
  }
  return n - divisions;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long n, k;
    cin >> n >> k;
    if (n == 2 && k == 3) {
      cout << "NO\n";
      continue;
    }
    long long _k = k, _n = n;
    if (n <= 60) {
      long long pow4 = 1;
      while (n--) {
        k -= pow4;
        pow4 *= 4;
      }
      if (k > 0)
        cout << "NO\n";
      else
        cout << "YES " << getLen(_n, _k) << "\n";
    } else {
      cout << "YES " << getLen(_n, _k) << "\n";
    }
  }
  return 0;
}
