#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 44;
const long long INF = 1e11 + 9;
const double eps = 1e-12;
int main() {
  int t;
  scanf("%d", &t);
  long long n, k;
  while (t--) {
    scanf("%lld", &n);
    scanf("%lld", &k);
    long long a = 1, b = 0;
    long long tt = n - 1;
    long long lu = 3;
    int flag = 0;
    int ff = 0;
    long long cnt = 0;
    long long tm = 1;
    for (int i = 0; i <= n - 2; i++) {
      cnt += tm;
      b += tm;
      if (cnt >= k) {
        ff = 1;
        break;
      }
      tm = tm * 4;
    }
    while (true) {
      if (tt == -1) break;
      if (ff == 1 || a > k) break;
      if (a <= k && a + b >= k) {
        ff = 1;
        break;
      }
      a += lu;
      long long tmp = lu * 4;
      tt--;
      lu = 2 * lu + 1;
      tmp -= lu;
      tm = tm / 4;
      cnt -= tm;
      b += cnt * tmp;
    }
    if (tt >= 0 && ff == 1)
      printf("YES %lld\n", tt);
    else
      printf("NO\n");
  }
  return 0;
}
