#include <bits/stdc++.h>
using namespace std;
long long ksm(long long a, long long k) {
  long long ans = 1;
  while (k > 0) {
    if (k % 2 == 1) ans = ans * a;
    a = a * a;
    k /= 2;
  }
  return ans;
}
long long br(long long len) {
  long long ans = 1LL;
  for (int i = 1; i <= len - 1; i++) {
    ans = ans * 4LL + 1LL;
  }
  return ans;
}
int main() {
  double ss;
  for (long long i = 1; i <= 100; i++) {
  }
  long long t;
  cin >> t;
  long long n, k;
  long long change, tmp;
  for (long long i = 1; i <= t; i++) {
    scanf("%lld%lld", &n, &k);
    if (n == 2 && k == 3) {
      printf("NO\n");
      continue;
    }
    if (n > 31) {
      printf("YES %lld\n", (n - 1LL));
      continue;
    }
    long long a = 2;
    int flag = 0;
    for (long long i = 1; i <= n; i++) {
      long long len = n - i;
      long long block = a * a - a * 2ll + 1ll;
      long long k1 = (ksm(4ll, i) - 1ll) / 3ll;
      long long k2 = (ksm(4ll, len) - 1ll) / 3ll;
      if (k <= k1 + k2 * block) {
        flag = 1;
        printf("YES %lld\n", len);
        break;
      }
      a *= 2ll;
    }
    if (flag == 0) printf("NO\n");
  }
  return 0;
}
