#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int q;
  cin >> q;
  while (q--) {
    long long int n, k;
    cin >> n >> k;
    if (n >= 32) {
      cout << "YES " << n - 1 << endl;
    } else {
      long long int val = ((long long int)1 << (2 * n));
      val = (val - 1) / 3;
      if (k > val) {
        cout << "NO" << endl;
        continue;
      }
      long long int l_sum = 0;
      long long int r_sum = 0;
      long long int ans = 0;
      for (long long int i = 1; i <= n; ++i) {
        l_sum += ((long long int)1 << i) - 1;
        r_sum += (((long long int)1 << (2 * (n - i))) - 1) / 3;
        if (k - l_sum < 0) {
          break;
        }
        if (k - l_sum <= r_sum) {
          ans = n - i;
          break;
        }
      }
      if (k - l_sum < 0)
        cout << "NO" << endl;
      else
        cout << "YES " << ans << endl;
    }
  }
  return 0;
}
