#include <bits/stdc++.h>
using namespace std;
long long cuts(long long n) {
  if (2 * n >= 62) return -1;
  return ((1LL << (2 * n)) - 1) / 3;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long n, k;
    cin >> n >> k;
    bool ok = false;
    long long ans;
    for (ans = n - 1; ans >= 0; ans--) {
      long long di = n - ans;
      if (2 * di >= 62) break;
      long long sq = (1 << di) - 1;
      sq *= sq;
      long long oc = cuts(ans);
      if (oc == -1) {
        ok = true;
        break;
      }
      long long add = oc * sq;
      if (sq > 0 && add / sq != oc) {
        ok = true;
        break;
      }
      long long mini = (1 << (di + 1)) - n + ans - 2;
      long long maxi = cuts(di) + add;
      if (k >= mini && k <= maxi) {
        ok = true;
        break;
      }
    }
    if (ok) {
      cout << "YES " << ans << endl;
    } else {
      cout << "NO" << endl;
    }
  }
  return 0;
}
