#include <bits/stdc++.h>
using namespace std;
unsigned long long a[100000], k;
int cnt, n;
int main() {
  a[0] = 0;
  a[1] = 1;
  cnt = 1;
  unsigned long long cur = 1;
  while (a[cnt] <= 1e18) {
    a[cnt + 1] = a[cnt];
    a[++cnt] += cur <<= 2;
  }
  int T;
  cin >> T;
  while (T--) {
    cin >> n >> k;
    if (n > cnt) {
      printf("YES %d\n", n - 1);
      continue;
    }
    if (a[n] < k) {
      puts("NO");
      continue;
    }
    unsigned long long L = 0, R = 0, x = 1;
    bool ok = 0;
    for (int i = n - 1; i >= 0; i--) {
      L += x;
      R += (2 * x - 1) * a[i];
      x = 2 * x + 1;
      if (L > k) break;
      if (L + R >= k) {
        printf("YES %d\n", i);
        ok = 1;
        break;
      }
    }
    if (!ok) puts("NO");
  }
  return 0;
}
