#include <bits/stdc++.h>
int T, ans = -1;
long long n, k, po[70], sum[70], s[70];
int main() {
  po[0] = 1;
  for (int i = 1; i <= 35; i++) po[i] = po[i - 1] * 4;
  for (scanf("%d", &T); T--; ans = -1) {
    std::cin >> n >> k;
    for (int i = n, j = 0; ~i; i--, j++) {
      long long Min = 0, Max = 0, Delt = 2;
      for (int p = 1; p <= j; p++, Delt <<= 1ll) Min += Delt - 1;
      Delt--;
      if (n > 31)
        Max = j ? 1e18 + 7 : 0;
      else
        Max = (po[n] - 1) / 3 - 1ll * Delt * (po[n - j] - 1) / 3;
      if (Min <= k && k <= Max) {
        ans = i;
        break;
      }
    }
    if (ans == -1)
      puts("NO");
    else
      printf("YES %d\n", ans);
  }
}
