#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    long long int n, k;
    scanf("%I64d%I64d", &n, &k);
    if (n > 31ll) {
      printf("YES %I64d\n", n - 1);
      continue;
    }
    long long int lim = ((1ll << (2 * n)) - 1) / 3ll;
    if (k > lim) {
      printf("NO\n");
      continue;
    }
    if (n == 2 && k == 3)
      printf("NO\n");
    else {
      printf("YES ");
      long long int ac = 1ll, tp = 4ll, cnt = 0ll;
      while (ac <= k) {
        ac += tp - 1;
        tp *= 2ll;
        ++cnt;
      }
      printf("%I64d\n", max(n - cnt, 0ll));
    }
  }
  return 0;
}
