#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  vector<long long> f;
  vector<long long> side;
  side.push_back(1);
  f.push_back(0);
  while (f.back() < 1.1e18) f.push_back(f.back() * 4 + 1);
  while (side.back() < 1.1e18) side.push_back(side.back() * 2 + 1);
  int T;
  cin >> T;
  while (T--) {
    long long n, k;
    cin >> n >> k;
    if (n == 1) {
      cout << (k == 1 ? "YES 0\n" : "NO\n");
    } else if (n == 2) {
      constexpr int ans[] = {-1, 1, 1, -1, 0, 0};
      if (k <= 5 and k != 3)
        cout << "YES " << ans[k] << '\n';
      else
        cout << "NO\n";
    } else if (n < f.size() and k > f[n]) {
      cout << "NO\n";
    } else {
      int i = upper_bound(f.begin(), f.end(), k) - f.begin() - 1;
      cout << "YES ";
      if (i < side.size() and k - f[i] > side[i])
        cout << n - i - 1 << '\n';
      else
        cout << n - i << '\n';
    }
  }
}
