#include <bits/stdc++.h>
using namespace std;
long long cuts[100];
int main() {
  long long i, j, k, l, m, n, t, p, q;
  cuts[1] = 1;
  for (i = 2; i <= 32; i++) cuts[i] = cuts[i - 1] * 4 + 1;
  cin >> t;
  while (t--) {
    cin >> n >> k;
    if (n >= 33 || k - 1 <= cuts[n - 1]) {
      cout << "YES " << n - 1 << endl;
      continue;
    }
    if (k > cuts[n]) {
      cout << "NO\n";
      continue;
    }
    l = 3;
    m = 2;
    p = 0;
    while (k - 1 - (l + p) >= 0 && n >= m) {
      long long av = 0;
      i = 1;
      q = 1;
      while (i <= m) {
        av += cuts[n - i] * (q * 4 - (q * 2 + 1));
        q = q * 2 + 1;
        i++;
      }
      if (k - 1 - (l + p) <= av) {
        cout << "YES " << n - m << endl;
        break;
      }
      p += l;
      l = l * 2 + 1;
      m++;
    }
    if (k - 1 - l < 0 || m > n) cout << "NO\n";
  }
}
