#include <bits/stdc++.h>
using namespace std;
long long n, k, T;
long long tw[110];
int tot = 0;
int main() {
  for (tot = 1;; tot++) {
    tw[tot] = tw[tot - 1] * 4 + 1;
    if (tw[tot] >= 1e18) break;
  }
  cin >> T;
  while (T--) {
    cin >> n >> k;
    if (n >= 32) {
      printf("YES %lld\n", n - 1);
      continue;
    }
    long long t1 = 1, t2 = 0;
    long long tn = n;
    long long tmp = 0;
    while (k >= t1 && tn) {
      k -= t1;
      tn--;
      tmp += tw[tn] * (t2 * 4 + 1);
      t1 = t1 * 2 + 1;
      t2 = t2 * 2 + 1;
    }
    if (k <= tmp) {
      printf("YES %lld\n", tn);
    } else
      puts("NO");
  }
}
