#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 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 {
      long long tot = 0, now = 1, j = 0, re = 0;
      while (tot + now <= k && j < n) {
        tot += now;
        now = now * 2 + 1;
        j++;
        re += 1ll * f[n - j] * (now - 2);
      }
      if (k > tot + re)
        cout << "NO\n";
      else
        cout << "YES " << n - j << endl;
    }
  }
  return 0;
}
