#include <bits/stdc++.h>
using namespace std;
using ull = unsigned long long;
ull pw(ull x, ull a) {
  ull ret = 1;
  while (a) {
    while (!(a & 1)) {
      x *= x;
      a >>= 1;
    }
    ret *= x;
    a--;
  }
  return ret;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int i, j, t;
  cin >> t;
  ull mx = pw(10, 18);
  for (i = 0; i < t; i++) {
    ull n, k, res = 0;
    bool flag = true;
    cin >> n >> k;
    if (n == 2 && k == 3) {
      cout << "NO" << endl;
      continue;
    }
    if (n <= 30) {
      for (j = 0; j < n; j++) {
        res += pw(4, j);
        if (res >= k) break;
        if (j == n - 1) {
          cout << "NO" << endl;
          flag = false;
        }
      }
    }
    if (!flag) continue;
    cout << "YES ";
    res = 0;
    for (j = 1; j <= n; j++) {
      res += (pw(2, j) - 1);
      if (res >= k) {
        cout << n - j + (res != k) << endl;
        break;
      }
      if (j == n) cout << 0 << endl;
    }
  }
}
