#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
long long T;
long long n, k;
long long now, res, t;
long long f[200020];
void work(long long k) {
  while (n) {
    now += t;
    if (n > 31)
      res = 1000000000000000000ll;
    else if ((1000000000000000000ll - res - 1) / (2ll * t - 1ll) + 1ll <
             f[n - 1])
      res = 1000000000000000000ll;
    else
      res += (2ll * t - 1ll) * f[n - 1];
    res = (res > 1000000000000000000ll ? 1000000000000000000ll : res);
    n--;
    if (now <= k && k <= now + res) {
      printf("YES %lld\n", n);
      return;
    }
    t = 2ll * t + 1ll;
  }
  puts("NO");
}
int main() {
  T = read();
  f[1] = 1;
  for (int i = 2; i <= 40; i++) f[i] = f[i - 1] * 4ll + 1;
  while (T--) {
    n = read(), k = read();
    now = 0, res = 0, t = 1;
    work(k);
  }
}
