#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int t;
  cin >> t;
  for (int i = 0; i < t; ++i) {
    ll n, k;
    cin >> n >> k;
    ll minsplits = 0;
    ll maxsplits = 0;
    bool done = false;
    for (ll a = n; a >= 0; --a) {
      if (minsplits > k) {
        cout << "NO\n";
        done = true;
        break;
      }
      ll maxbefnsplits = -1;
      if (a > 0) {
        ll smin1 = (1 << (n - a)) - 1;
        ll subs = smin1 * smin1;
        if (subs > 0) {
          maxbefnsplits = maxsplits;
          for (ll j = a; j > 0; --j) {
            maxbefnsplits += subs;
            subs *= 4;
            if (maxbefnsplits >= k) break;
          }
        }
      }
      if (maxsplits >= k || maxbefnsplits >= k) {
        cout << "YES " << a << "\n";
        done = true;
        break;
      }
      maxsplits *= 4;
      maxsplits += 1;
      minsplits += (1 << (n - a + 1)) - 1;
    }
    if (!done) cout << "NO\n";
  }
}
