#include <bits/stdc++.h>
using namespace std;
long long n, m, a, b, c, d, e, f, g, h, x, y, p, q, r, s, t, k;
long long l(long long x) {
  for (long long i = 0; i <= n; i++)
    if (x + i + 2 < (1ll << (i + 1))) return i;
  return n + 1;
}
int main(void) {
  for (cin >> t; t--;) {
    cin >> n >> k;
    if (n < 32 && pow(4, n) < k * 3 + 1)
      cout << "NO\n";
    else {
      a = l(k) - 1;
      if (n == 2 && k == 3)
        cout << "NO\n";
      else
        cout << "YES " << n - a << '\n';
    }
  }
}
