#include <bits/stdc++.h>
using namespace std;
const int Max_n = 1e6 + 10;
long long t, n, k;
long long s[Max_n];
long long check(long long n, long long k) {
  long long t = 0, l = 0, r = 0;
  for (long long i = n - 1; i >= 0; i--) {
    t = t * 2 + 1;
    l += t;
    r += t + (2 * t - 1) * s[i];
    if (k >= l && k <= r) return i;
  }
  return -1;
}
int main() {
  s[0] = 0;
  for (int i = 1; i <= 30; i++) s[i] = s[i - 1] * 4 + 1;
  scanf("%lld", &t);
  while (t--) {
    scanf("%lld%lld", &n, &k);
    if (n > 31)
      printf("YES %lld\n", n - 1);
    else {
      long long ans = check(n, k);
      if (ans < 0)
        puts("NO");
      else
        printf("YES %lld\n", ans);
    }
  }
  return 0;
}
