#include <bits/stdc++.h>
using namespace std;
const int MAXR = 10000000;
char _READ_[MAXR], _PRINT_[MAXR];
int _READ_POS_, _PRINT_POS_, _READ_LEN_;
inline char readc() {
  if (!_READ_POS_) _READ_LEN_ = fread(_READ_, 1, MAXR, stdin);
  char c = _READ_[_READ_POS_++];
  if (_READ_POS_ == MAXR) _READ_POS_ = 0;
  if (_READ_POS_ > _READ_LEN_) return 0;
  return c;
}
template <typename T>
inline void read(T &x, T base = 10) {
  x = 0;
  register int flag = 1, c;
  while (((c = readc()) < '0' || c > '9') && c != '-')
    ;
  if (c == '-')
    flag = -1;
  else
    x = c - '0';
  while ((c = readc()) >= '0' && c <= '9') x = x * base + c - '0';
  x *= flag;
}
inline int reads(char *s) {
  register int len = 0, c;
  while (isspace(c = readc()) || !c)
    ;
  s[len++] = c;
  while (!isspace(c = readc()) && c) s[len++] = c;
  s[len] = 0;
  return len;
}
inline void ioflush() {
  fwrite(_PRINT_, 1, _PRINT_POS_, stdout), _PRINT_POS_ = 0;
  fflush(stdout);
}
inline void printc(char c) {
  _PRINT_[_PRINT_POS_++] = c;
  if (_PRINT_POS_ == MAXR) ioflush();
}
inline void prints(char *s) {
  for (int i = 0; s[i]; i++) printc(s[i]);
}
template <typename T>
inline void print(T x, char c = '\n') {
  if (x < 0) printc('-'), x = -x;
  if (x) {
    static char sta[20];
    register int tp = 0;
    for (; x; x /= 10) sta[tp++] = x % 10 + '0';
    while (tp > 0) printc(sta[--tp]);
  } else
    printc('0');
  printc(c);
}
long long power(long long a, int b) {
  long long res = 1;
  for (; b; b >>= 1) {
    if (b & 1) res = res * a;
    a = a * a;
  }
  return res;
}
int main() {
  int T, n;
  long long k;
  for (read(T); T--;) {
    read(n), read(k);
    if (n <= 31 && k > (power(2, 2 * n) - 1) / 3) {
      prints("NO\n");
    } else {
      long long kk = k;
      for (int i = 1;; ++i) {
        long long t = (1LL << i) - 1;
        if (k < t || i == n + 1) {
          if (n <= 30 && kk > (power(2, 2 * n) - 1) / 3 -
                                  t * (power(2, 2 * (n - i + 1)) - 1) / 3)
            prints("NO\n");
          else
            prints("YES "), print(n - i + 1);
          break;
        } else
          k -= t;
      }
    }
  }
  ioflush();
  return 0;
}
