#include <bits/stdc++.h>
using namespace std;
long long MIN_I = -10000000000000;
long long MAX_I = 1000000000000;
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  int t;
  cin >> t;
  for (int i = 0; i < t; ++i) {
    long long n, k;
    cin >> n >> k;
    long long countOthers = 1;
    long long countMandatory = 1;
    long long lengthOthers = n - 1;
    long long lengthMandatory = n;
    while (k >= countMandatory && lengthMandatory > 0) {
      k -= countMandatory;
      countMandatory *= 2;
      countMandatory++;
      lengthMandatory--;
    }
    if (k == 0) {
      cout << "YES "
           << " " << lengthMandatory << "\n";
      continue;
    }
    long long z = 5;
    while (k >= countOthers && lengthOthers > 0) {
      k -= countOthers;
      lengthOthers--;
      countOthers *= 4;
      countOthers += z;
      z = z * 2 + 3;
    }
    if ((k <= countOthers && lengthOthers > 0) || k == 0) {
      cout << "YES "
           << " " << lengthMandatory << "\n";
    } else {
      cout << "NO\n";
    }
  }
  return 0;
}
