#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
long long modexp(long long x, long long y, long long p) {
  long long res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout << setprecision(2);
  cout << fixed;
  long long t;
  cin >> t;
  long long ar[32] = {0};
  long long ar2[61] = {0};
  long long z = 1;
  long long zz = 1;
  for (long long i = 0, _n = (32); i < _n; i++) {
    ar[i] = z;
    z *= 4;
  }
  for (long long i = 0, _n = (61); i < _n; i++) {
    ar2[i] = (zz - 1);
    zz *= 2;
  }
  while (t--) {
    long long n, k;
    cin >> n >> k;
    if (n <= 31) {
      z = (ar[n] - 1) / 3;
    }
    if (n >= 32) {
      cout << "YES " << n - 1 << endl;
    } else if (n <= 31 && z < k) {
      cout << "NO" << endl;
    } else {
      long long p = 0;
      long long k1 = 0;
      long long j = 0;
      for (long long i = 1; i <= min(31ll, n); i++) {
        if (k < p + ar2[i]) {
          break;
        } else {
          p += ar2[i];
          k1++;
          z = (ar[k1] - 1) / 3;
          zz = (ar[n - k1] - 1) / 3;
          j += z * zz;
        }
      }
      k -= p;
      if (j >= k || n > 2)
        cout << "YES " << n - k1 << endl;
      else {
        cout << "NO" << endl;
      }
    }
  }
  return 0;
}
