#include <bits/stdc++.h>
using namespace std;
int T;
long long N, K;
long long inf = (long long)(1e18) + 1;
long long shred(long long N) {
  if (2 * N >= 62LL) return inf;
  return ((1LL << (2 * N)) - 1) / 3;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> T;
  while (T--) {
    cin >> N >> K;
    long long Cut = 1, Sh = shred(N - 1);
    long long Rnd = 1;
    long long Pie = 3;
    while (Cut < inf && Sh < inf && K > Cut + Sh) {
      Rnd++;
      Cut += Pie;
      Sh += (Pie * 2 - 1) * shred(N - Rnd);
      Pie = Pie * 2 + 1;
      if (Cut > K) {
        Rnd = inf;
        break;
      }
    }
    if (N >= Rnd)
      cout << "YES " << N - Rnd << '\n';
    else
      cout << "NO" << '\n';
  }
  return 0;
}
