#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000010;
long long n, jc[40], k;
void init() {
  jc[1] = 1;
  for (int i = 2; i <= 31; i++) {
    jc[i] = jc[i - 1] * 4 + 1;
  }
}
int main() {
  init();
  int T;
  cin >> T;
  while (T--) {
    cin >> n >> k;
    if (n >= 32) {
      printf("YES %d\n", n - 1);
      continue;
    }
    long long minn = 0, res = 0, ans = -1, maxx;
    for (int i = 1; i <= n; i++) {
      res = 2 * res + 1;
      minn = minn + res;
      maxx = jc[n] - (2 * res + 1) * (jc[n - i]);
      if (minn <= k && k <= maxx) {
        ans = n - i;
        break;
      }
    }
    if (ans != -1) {
      printf("YES %lld\n", ans);
    } else {
      puts("NO");
    }
  }
}
