#include <bits/stdc++.h>
using namespace std;
const long long INF = (long long)1 << 62;
const long long MOD = 1e9 + 7;
const int iINF = 1 << 30;
const double PI = 3.14159265359;
vector<long long> f;
void solve() {
  long long n, k;
  cin >> n >> k;
  if (n > 31) {
    cout << "YES " << n - 1 << "\n";
    return;
  }
  if (n == 2 && k == 3) {
    cout << "NO\n";
    return;
  }
  long long adder = 1;
  long long multiplier = 1;
  while (n > 0) {
    k -= adder + multiplier * f[n - 1];
    if (k <= 0) {
      cout << "YES " << n - 1 << "\n";
      return;
    }
    adder = adder * 2 + 1;
    multiplier = multiplier * 2 + 3;
    n--;
  }
  cout << "NO\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long pow4 = 1;
  while (pow4 <= INF >> 2) {
    f.push_back((pow4 - 1) / 3);
    pow4 *= 4;
  }
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
