#include <bits/stdc++.h>
int t, n;
long long k;
int answer() {
  int lv = 0;
  long long a = 1;
  for (; a * a < k; a *= 2) {
    k -= a * a;
    ++lv;
  }
  if (n <= lv) return -1;
  if (n == 2 && k == 2) return -1;
  if (k >= a * a - (a - 1) * (a - 1)) return lv + 1;
  return lv;
}
int main() {
  for (scanf("%d", &t); t--;) {
    scanf("%d %lld", &n, &k);
    int ret = answer();
    if (ret != -1)
      printf("YES %d\n", n - ret);
    else
      printf("NO\n");
  }
  return 0;
}
