#include <bits/stdc++.h>
using namespace std;
long long table[33];
void init() {
  for (int i = 1; i < 33; i++) table[i] = table[i - 1] + (1LL << (2 * (i - 1)));
}
int main(void) {
  int T;
  cin >> T;
  init();
  for (int t = 0; t < T; t++) {
    int N;
    long long K;
    cin >> N >> K;
    if (N < 33 && K > table[N])
      cout << "NO\n";
    else if (N < 33 && K <= table[N - 1] + 1)
      cout << "YES " << N - 1 << "\n";
    else if (N == 33 && K <= table[32] + 1)
      cout << "YES " << N - 1 << "\n";
    else if (N >= 33)
      cout << "YES " << N - 1 << "\n";
    else if (N >= 5)
      cout << "YES 0\n";
    else if (N == 4 && K <= 26)
      cout << "YES " << N - 2 << "\n";
    else if (N == 3 && K <= 11)
      cout << "YES " << N - 2 << "\n";
    else if (N == 2 && K < 4)
      cout << "NO\n";
    else
      cout << "YES 0\n";
  }
  return 0;
}
