#include <bits/stdc++.h>
using namespace std;
const int maxn = 10010;
const int INF = 0x3f3f3f3f;
const long long INFLL = 0x3f3f3f3f3f3f3f3fLL;
long long n, k, num[55], sum[55];
int t;
int main() {
  num[1] = 1, num[0] = 0;
  for (int i = 2; i <= 32; i++) num[i] = 4 * num[i - 1] + 1;
  scanf("%d", &t);
  while (t--) {
    scanf("%lld%lld", &n, &k);
    if (n > 31) {
      printf("YES %d\n", n - 1);
      continue;
    }
    if (k > num[n]) {
      printf("NO\n");
      continue;
    }
    long long cnt = 0, flag = 0, L = 0, R = 0;
    for (int i = n - 1; i >= 0; i--) {
      cnt = cnt * 2 + 1;
      L += cnt;
      R += cnt + num[i] * (2 * cnt - 1);
      if (L <= k && k <= R) {
        flag = 1;
        printf("YES %d\n", i);
        break;
      }
    }
    if (!flag) printf("NO\n");
  }
  return 0;
}
