#include <bits/stdc++.h>
bool kTooLarge(long long n, long long k) {
  long long s = 1;
  while (n > 0 && k > 0) {
    n -= 1;
    k -= s;
    s *= 4;
  }
  return k > 0;
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    long long n, k;
    scanf("%lld%lld", &n, &k);
    if (n == 2 && k == 3 || kTooLarge(n, k)) {
      printf("NO\n");
      continue;
    }
    long long s = 2;
    while (n > 0 && k >= s - 1) {
      n -= 1;
      k -= s - 1;
      s *= 2;
    }
    printf("YES %d\n", n);
  }
  return 0;
}
