#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
long long powmod(long long a, long long b, long long MOD) {
  long long ans = 1;
  while (b) {
    if (b % 2) ans = ans * a % MOD;
    a = a * a % MOD;
    b /= 2;
  }
  return ans;
}
const int N = 2e5 + 11;
int t, a, b;
long long f[N];
long long n, k;
int c() {
  for (int i = 0; i < n; i++) {
    int j = n - i;
    long long ans = 0;
    for (int k = 1; k <= j; k++) {
      ans += (1ll << k) - 1;
    }
    if (ans > k) continue;
    if (f[n] - f[i] * ((2 * (1ll << (j))) - 1) < k) continue;
    return i;
  }
  return -1;
}
int main() {
  ios::sync_with_stdio(false);
  f[1] = 1;
  for (int i = 2; i <= 31; i++) f[i] = 4ll * f[i - 1] + 1;
  for (cin >> t; t; t--) {
    cin >> n >> k;
    if (n > 31)
      cout << "YES " << n - 1 << '\n';
    else {
      int ans = c();
      if (ans == -1)
        cout << "No\n";
      else
        cout << "YES " << ans << endl;
    }
  }
  return 0;
}
