#include <bits/stdc++.h>
using namespace std;
long long f[100];
void solve() {
  long long n, k;
  cin >> n >> k;
  long long can = 0;
  for (long long i = 1; i < n + 1; i++) {
    k -= (1LL << i) - 1;
    if (k < 0) {
      cout << "NO" << '\n';
      return;
    }
    long long temp = (1LL << (i + 1)) - 3;
    if (n > 32 or k < 1.0l * temp * f[n - i]) {
      cout << "YES " << n - i << '\n';
      return;
    }
    can += temp * f[n - i];
    if (k <= can) {
      cout << "YES " << n - i << '\n';
      return;
    }
  }
  cout << "NO" << '\n';
}
signed main() {
  f[0] = 0;
  for (long long i = 1; i < 100; i++) {
    f[i] = 4 * f[i - 1] + 1;
    if (f[i] > 1e18 + 1000000007) f[i] = 1e18 + 1000000007;
  }
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
