#include <bits/stdc++.h>
using namespace std;
long long n, m, t, f[10005];
int main() {
  scanf("%lld", &t);
  for (int i = 1; i < 63; ++i) f[i] = f[i - 1] * 2 + 1;
  for (int i = 1; i < 63; ++i) f[i] += f[i - 1];
  while (t--) {
    scanf("%lld%lld", &n, &m);
    long long s = 1;
    for (int i = 1; i < n; ++i) {
      s = s * 4 + 1;
      if (s >= m) break;
    }
    if (s < m) {
      puts("NO");
      continue;
    }
    if (n <= 2 && m == f[n] - 1) {
      puts("NO");
      continue;
    }
    int i;
    for (i = 1; f[i] <= m; i++)
      ;
    i--;
    printf("YES %lld\n", min(n - 1, max(0LL, n - i)));
  }
  return 0;
}
