#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
const int mod = 1e9 + 7;
long long int powmod(long long int a, long long int b) {
  long long int res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
int nxt() {
  int x;
  scanf("%d", &x);
  return x;
}
inline long long int getLen(long long int n, long long int k) {
  long long int divisions = 1;
  k--;
  long long int len = 1;
  while (divisions < n && k >= 4 * len - 1) {
    k -= 4 * len - 1;
    len *= 2;
    divisions++;
  }
  return n - divisions;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long int n, k;
    cin >> n >> k;
    if (n == 2 && k == 3) {
      puts("NO");
      continue;
    }
    long long int _k = k, _n = n;
    if (n <= 60) {
      long long int pow4 = 1;
      while (n--) {
        k -= pow4;
        pow4 *= 4;
      }
      if (k > 0)
        puts("NO");
      else
        printf("YES %lld\n", getLen(_n, _k));
    } else
      printf("YES %lld\n", getLen(_n, _k));
  }
  return 0;
}
