#include <bits/stdc++.h>
using namespace std;
long long power(long long x, long long y) {
  if (y == 0) {
    return 1;
  }
  long long x_ = power(x, y / 2) * power(x, y / 2);
  if (y & 1) {
    return x * x_;
  } else {
    return x_;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    long long n, k;
    cin >> n >> k;
    if (n >= 32) {
      cout << "YES"
           << " " << n - 1 << endl;
      continue;
    }
    vector<long long> f(32);
    f[0] = 0;
    for (long long i = 1; i <= 31; i++) {
      f[i] = 1 + 4 * (f[i - 1]);
    }
    long long x = 0;
    long long flag = 0;
    long long lower = 0;
    for (long long i = 1; i <= n; i++) {
      long long temp1 = (1 << i) - 1;
      lower += temp1;
      long long temp2 = f[n - i];
      temp2 *= ((1 << (i + 1)) - 3);
      temp1 += temp2;
      x += temp1;
      if (x >= k && lower <= k) {
        flag = 1;
        cout << "YES"
             << " ";
        cout << n - i << endl;
        break;
      }
    }
    if (!flag) {
      cout << "NO" << endl;
    }
  }
}
