#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int t;
  scanf("%d", &t);
  while (t--) {
    bool suc = false;
    unsigned long long int n, k;
    scanf("%lld%lld", &n, &k);
    unsigned long long int num = 0, tw = 1, now = n, ans = 1e18, r2 = 2,
                           tot = 0, ltot = 0, r1 = 2;
    while (tw <= n) {
      unsigned long long int ll = tot + r2 - 1;
      if (k >= ll) {
        unsigned long long int kk = k - ll;
        unsigned long long int ntot = 0, err = 0, lll = 1;
        for (int e = 0; e < now - 1; e++) {
          if ((lll - 1) / 3 > kk) err++;
          lll *= 4;
          if (err) break;
        }
        ntot = ((lll - 1) / 3);
        if ((double)ntot > (double)kk / (double)(2 * (r1 - 1) - 1)) {
          err++;
        } else
          ntot *= (2 * (r1 - 1) - 1);
        if ((double)ntot > (double)kk - (double)ltot) err++;
        if (err) {
          ans = now;
        }
        ntot += ltot;
        if (kk <= ntot) {
          ans = now;
          break;
        }
        ltot = ntot;
      } else
        break;
      if ((double)tot >= 2e18 - (double)(r2 - 1) + 1) break;
      tot += (r2 - 1);
      r1 *= 2;
      if (r2 >= (double)2e18 / (double)2) break;
      r2 *= 2;
      tw++;
      now--;
    }
    if (ans == 1e18)
      printf("NO\n");
    else
      printf("YES %lld\n", ans - 1);
  }
  return 0;
}
