#include <bits/stdc++.h>
using namespace std;
long long a, b, c, n, m, k = 0, T, maxx = -0x3f3f3f3f;
int main() {
  scanf("%lld", &T);
  while (T--) {
    scanf("%lld%lld", &n, &k);
    long long t = 0, tmp = 0;
    if (n == 2 && k == 3) {
      cout << "No" << endl;
      continue;
    }
    while (t < k) {
      t = t * 4 + 1;
      if (t > k) break;
      tmp++;
    }
    if (tmp > n || (tmp == n && k != t))
      cout << "NO\n";
    else {
      if (t > k) t = (t - 1) / 4;
      cout << "YES ";
      long long s = ((1ll) << tmp);
      tmp = n - tmp;
      t = k - t;
      if (t >= 2 * s - 1)
        cout << tmp - 1 << endl;
      else
        cout << tmp << endl;
    }
  }
}
