#include <bits/stdc++.h>
using namespace std;
long long t, n, k, l, r, md, p;
long long m[50];
int main() {
  m[0] = 0;
  for (long long i = 1; i <= 32; ++i) {
    m[i] = 1 + 4 * m[i - 1];
  }
  cin >> t;
  while (t--) {
    cin >> n >> k;
    if (n >= 32) {
      cout << "YES " << n - 1 << endl;
      continue;
    }
    if (k > m[n] || (n == 2 && k == 3)) {
      cout << "NO" << endl;
      continue;
    }
    l = 0;
    r = n - 1;
    while (l < r) {
      md = (l + r) >> 1;
      p = (1LL << (n - 1 - md));
      p = 4 * p - 3;
      p -= (n - 1 - md);
      if (p > k)
        l = md + 1;
      else
        r = md;
    }
    cout << "YES " << l << endl;
  }
  return 0;
}
