#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long tt = 1;
  cin >> tt;
  while (tt--) {
    long long n, k;
    cin >> n >> k;
    vector<long long> a, b;
    long long p = 1, q = 3;
    a.push_back(0);
    b.push_back(0);
    b.push_back(1);
    for (long long i = 0; i < 100; i++) {
      a.push_back(p);
      b.push_back(p + q);
      if (p >= k) break;
      p = p * 4 + 1;
      q = q * 2 + 1;
    }
    if (n < a.size() - 1)
      cout << "NO" << '\n';
    else if (k == 3) {
      if (n >= 3)
        cout << "YES"
             << " " << n - 1 << '\n';
      else
        cout << "NO" << '\n';
    } else {
      cout << "YES"
           << " ";
      long long ans = 0;
      for (long long i = 0; i < b.size(); i++) {
        if (b[i] > k) {
          ans = i - 1;
          break;
        }
      }
      cout << n - ans << '\n';
    }
  }
  return 0;
}
