#include <bits/stdc++.h>
using namespace std;
long long maxmov[32], n, k;
void solve() {
  cin >> n >> k;
  if (n >= 32) {
    cout << "YES" << ' ' << n - 1 << '\n';
    return;
  }
  if (k > maxmov[min(n, 31ll)]) {
    cout << "NO" << '\n';
    return;
  }
  long long ans = n;
  map<long long, long long> mapp;
  mapp[n] = 1;
  for (int i = 0; i < n && k > 0; ++i) {
    long long required = (1ll << (i + 1)) - 1;
    if (required <= k) {
      mapp[ans] -= required;
      if (mapp[ans] == 0) mapp.erase(ans);
      mapp[ans - 1] += 4 * required;
      ans--;
      k -= required;
    } else
      break;
  }
  mapp[ans] -= (1 << (n - ans + 1)) - 1;
  if (mapp[ans] == 0) mapp.erase(ans);
  while (k > 0 && mapp.size()) {
    pair<long long, long long> pf = *mapp.rbegin();
    long long sz = pf.first;
    long long cnt = pf.second;
    if (sz == 0)
      break;
    else {
      k -= cnt * maxmov[min(31ll, sz)];
      mapp.erase(sz);
    }
  }
  if (k <= 0) {
    cout << "YES" << ' ' << ans << '\n';
  } else {
    cout << "NO" << '\n';
  }
}
int main(int argc, char const *argv[]) {
  ios_base::sync_with_stdio(false), cin.tie(NULL);
  maxmov[0] = 0;
  for (int i = 1; i < 32; ++i) {
    maxmov[i] = (4 * maxmov[i - 1] + 1);
  }
  long long t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
