#include <bits/stdc++.h>
namespace ringo {
template <class T>
inline void read(T &x) {
  x = 0;
  register char c = getchar();
  register bool f = 0;
  while (!isdigit(c)) f ^= c == '-', c = getchar();
  while (isdigit(c)) x = x * 10 + c - '0', c = getchar();
  if (f) x = -x;
}
template <class T>
inline void print(T x) {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) print(x / 10);
  putchar('0' + x % 10);
}
const long long inf = 9223372036854775807ll;
long long n, k, t[100];
long long T;
bool check(long long x, long long y) {
  double a = (double)x / inf;
  double b = (double)y / inf;
  return (a * b - 1e-4) >= 1;
}
void main() {
  read(T), t[0] = 0;
  t[1] = 1;
  for (long long i = 2; i <= 31; i++)
    t[i] = t[i - 1] + (1ll << i - 1) * (1ll << i - 1);
  while (T--) {
    read(n);
    read(k);
    long long ans = -1;
    if (n >= 32 || t[n - 1] + 1 >= k) {
      printf("YES %d\n", n - 1);
      continue;
    }
    long long now = 1, nowcan = t[n - 1], cnt = 1;
    for (long long i = 2; i <= n + 1 && now <= k && i <= 31; i++) {
      if (k - now <= nowcan) {
        ans = n - i + 1;
        break;
      }
      if (i == n + 1) break;
      now += (cnt + 2ll);
      cnt = (1ll << i + 1) - 3;
      if (check(t[n - i], cnt))
        nowcan = inf;
      else
        nowcan += t[n - i] * cnt;
    }
    if (ans != -1)
      printf("YES %d\n", ans);
    else
      printf("NO\n");
  }
  return;
}
}  // namespace ringo
signed main() { return ringo::main(), 0; }
