#include <bits/stdc++.h>
using namespace std;
int main() {
  int _;
  scanf("%d", &_);
  while (_--) {
    long long n, k;
    scanf("%lld%lld", &n, &k);
    if (n == 2 && k == 3) {
      printf("NO\n");
    } else if (n >= 33) {
      printf("YES ");
      printf("%lld\n", (n - 1));
    } else {
      long long ans = 1;
      for (int i = 2; i <= n; i++) ans = ans * 4ll + 1ll;
      if (ans >= k) {
        int flag = 0;
        for (int i = 1; i <= n; i++) {
          long long low = (1ll << (i + 1)) - 2 - i;
          long long high = ((1ll << (2 * (i))) - 1) / 3;
          if (k <= high && k >= low) {
            flag = 1;
            printf("YES %d\n", n - i);
            break;
          } else if (k <= low) {
            flag = 1;
            printf("YES %d\n", n - i + 1);
            break;
          }
        }
        if (flag == 0) printf("YES 0\n");
      } else
        printf("NO\n");
    }
  }
  return 0;
}
