#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:256000000")
#pragma gcc optimize(O3)
using namespace std;
const double eps = 1e-9;
const double pi = acos(-1.0);
const double dinf = 1e250;
const long long INF = static_cast<long long>(2e18);
const unsigned long long inf = static_cast<unsigned long long>(1e9 + 7);
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
template <class T>
void OUT(T a) {
  cout << a;
  exit(0);
}
template <typename T>
bool amax(T& a, T b) {
  if (b > a) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool amin(T& a, T b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}
mt19937 rng(static_cast<uint32_t>(
    chrono::steady_clock::now().time_since_epoch().count()));
chrono::time_point<chrono::steady_clock> cl;
double time_since_start() {
  return (chrono::steady_clock::now() - cl).count() / 1e9;
}
void get_time();
vector<long long> precalc;
void rec(unsigned long long n, unsigned long long cur, unsigned long long& k,
         map<unsigned long long, unsigned long long>& s,
         unsigned long long& w) {
  w = n;
  if (!n) return;
  if (!k) return;
  if (k >= 2 * cur - 1) {
    k -= 2 * cur - 1;
    rec(n - 1, cur * 2, k, s, w);
    s[n - 1] += 2 * cur - 3;
  }
}
void solve() {
  map<unsigned long long, unsigned long long> m;
  unsigned long long n, k;
  cin >> n >> k;
  unsigned long long cur = 1;
  while (k >= cur * cur && n) {
    k -= cur * cur;
    cur *= 2;
    n -= 1;
  }
  if (!n && k) {
    cout << "NO" << endl;
    return;
  }
  unsigned long long w;
  rec(n, cur, k, m, w);
  m[n] += (cur - 1) * (cur - 1);
  for (unsigned long long i = n; i > 0; --i) {
    if (k >= m[i]) {
      k -= m[i];
      m[i - 1] += 4 * m[i];
    }
    if (k < m[i]) {
      cout << "YES " << w << endl;
      return;
    }
  }
  if (!k) {
    cout << "YES " << n << endl;
    return;
  }
  if (k) {
    cout << "NO" << endl;
    return;
  }
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(10);
  cl = chrono::steady_clock::now();
  cin.tie(0);
  unsigned long long cur = 1;
  for (unsigned long long i = 0; i < 32; ++i) {
    precalc.push_back(cur);
    cur *= 4;
  }
  for (unsigned long long i = 1; i < 32; ++i) {
    precalc[i] += precalc[i - 1];
  }
  unsigned long long q;
  cin >> q;
  while (q--) {
    solve();
  }
  return 0;
}
void get_time() {}
