#include <bits/stdc++.h>
using namespace std;
long long n, k, op[100];
int main() {
  for (int i = 1; i <= 31; i++) op[i] = op[i - 1] * 4LL + 1LL;
  int t;
  scanf("%d", &t);
  while (t--) {
    scanf("%I64d%I64d", &n, &k);
    if (n > 31) {
      printf("YES %I64d\n", n - 1);
      continue;
    }
    long long tot = 0, now = 1, j = 0, re = 0;
    while (now + tot <= k && j < n) {
      tot += now;
      now = now * 2 + 1;
      j++;
      re += op[n - j] * (now - 2);
    }
    if (k > tot + re)
      printf("NO\n");
    else
      printf("YES %I64d\n", n - j);
  }
  return 0;
}
