#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t, i, j, n, k, bj;
  cin >> t;
  while (t--) {
    cin >> n >> k;
    if (n <= 30) {
      if (n == 2 && k == 3) {
        cout << "NO" << endl;
        continue;
      }
      bj = (pow(4, n) - 1) / 3;
      if (k > bj)
        cout << "NO" << endl;
      else {
        cout << "YES ";
        while (k > 0) {
          n--;
          k /= 4;
        }
        cout << n << endl;
      }
    } else {
      cout << "YES ";
      while (k > 0) {
        n--;
        k /= 4;
      }
      cout << n << endl;
    }
  }
  return 0;
}
