#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') f = -1;
  for (; isdigit(ch); ch = getchar()) x = (x << 3) + (x << 1) + ch - '0';
  return x * f;
}
inline int reead() {
  int x = 0, f = 1;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') f = -1;
  for (; isdigit(ch); ch = getchar()) x = (x << 3) + (x << 1) + ch - '0';
  return x * f;
}
inline int rewad() {
  int x = 0, f = 1;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') f = -1;
  for (; isdigit(ch); ch = getchar()) x = (x << 3) + (x << 1) + ch - '0';
  return x * f;
}
const int maxxx = 1000000;
signed main() {
  long long T;
  cin >> T;
  while (T--) {
    long long nw = 0;
    long long t = 2;
    long long res = 0;
    long long n;
    long long k;
    cin >> n >> k;
    long long mx = 0;
    long long tt = 1;
    for (long long i = 1; i <= n; i++) {
      mx += tt, tt *= 4;
      if (mx > k) break;
    }
    if (mx < k) {
      printf("NO\n");
      continue;
    }
    if (n == 2 && k == 3) {
      cout << "NO" << endl;
      continue;
    }
    for (long long i = 0;; i++) {
      if (k < nw + t - 1) {
        printf("YES %I64d\n", max(0ll, n - i));
        break;
      }
      nw += t - 1;
      t *= 2;
    }
  }
  return 0;
}
