#include <bits/stdc++.h>
using namespace std;
long long i, j, k, cnt = 0;
int main() {
  long long t, n, k;
  cin >> t;
  while (t--) {
    cin >> n >> k;
    if (n >= 32)
      cout << "YES " << n - 1 << endl;
    else {
      long long allop = 0, needop = 0;
      for (i = 1; i < n + 1; i++) {
        needop = needop * 2 + 1;
        allop += needop;
        if (allop > k) {
          allop -= needop;
          break;
        }
      }
      if ((1ll << 2 * n) - 1 >= 3 * k + needop * ((1ll << 2 * (n - i + 1)) - 1))
        cout << "YES " << n - i + 1 << endl;
      else
        cout << "NO" << endl;
    }
  }
  return ~~(0 ^ 0 ^ 0);
}
