#include <bits/stdc++.h>
using namespace std;
inline int read() {
  char ch = getchar();
  int ret = 0, f = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  for (; ch >= '0' && ch <= '9'; ch = getchar()) ret = ret * 10 + ch - '0';
  return ret * f;
}
inline void print(string name, int *arr, int len) {
  for (int i = 1; i <= len; ++i) printf("%s[%d]=%d\n", name.c_str(), i, arr[i]);
  puts("");
}
inline void print(string name, long long *arr, int len) {
  for (int i = 1; i <= len; ++i)
    printf("%s[%d]=%I64d\n", name.c_str(), i, arr[i]);
  puts("");
}
inline void print(string name, int a) {
  printf("%s=%d\n", name.c_str(), a);
  puts("");
}
const int INF = 1 << 30;
int n;
long long k;
inline void input() { cin >> n >> k; }
long long cnt[50];
inline void solve() {
  long long sum = 0, cur = 0;
  int ok = 0;
  if (n >= 33)
    ok = 1;
  else {
    for (int i = 1; i <= n; ++i) {
      cur = cur * 4 + 1;
      sum += cur;
      if (sum >= k) {
        ok = 1;
        break;
      }
    }
    if (!ok) {
      puts("NO");
      return;
    }
  }
  cur = 0;
  int inf = 0;
  long long left = 0;
  for (int i = 1; i <= 33; ++i) {
    cur = cur * 2 + 1;
    if (k >= cur && i <= n) {
      k -= cur;
      if (!inf) {
        if (n - i >= 33)
          inf = 1;
        else {
          long long t = left;
          left += cnt[n - i] * (cur * 2 - 1);
          if (left < t) inf = 1;
        }
      }
    } else if (inf || k <= left) {
      printf("YES ");
      cout << n - i + 1 << endl;
      return;
    } else {
      puts("NO");
      return;
    }
  }
  printf("YES %d\n", n - 33);
}
int main() {
  for (int i = 1; i <= 33; ++i) cnt[i] = cnt[i - 1] * 4 + 1;
  int T;
  cin >> T;
  while (T--) {
    input();
    solve();
  }
  return 0;
}
