#include <bits/stdc++.h>
using namespace std;
bool calc(long long n, long long m) {
  return (double)n >= (double)log(3.0 * (double)m + 1.0) / 2.0 / log(2.0);
}
int main() {
  int t;
  long long i, n, m, cnt, sum, l, s;
  cin >> t;
  while (t--) {
    cin >> n >> m;
    if (n >= 32) {
      cout << "YES " << n - 1 << endl;
      continue;
    }
    l = cnt = sum = 0;
    for (i = 0; i < n; i++) {
      cnt = cnt * 2 + 1;
      sum += cnt;
      s = (pow(((1 << (i + 1)) - 1), 2) - pow(((1 << (i + 1)) - 2), 2)) *
          ((pow(4, n - i - 1) - 1) / 3);
      l += s + cnt;
      if (sum <= m && m <= l) {
        cout << "YES " << n - i - 1 << endl;
        break;
      }
    }
    if (i == n) cout << "NO\n";
  }
}
