#include <bits/stdc++.h>
using namespace std;
void Exgcd(int a, int b, int &g, int &x, int &y) {
  if (!b) {
    g = a;
    x = 1;
    y = 0;
    return;
  }
  Exgcd(b, a % b, g, y, x);
  y -= (a / b) * x;
}
int Gcd(int a, int b) {
  if (!b) return a;
  return Gcd(b, a % b);
}
void Work() {
  long long n, k;
  scanf("%I64d %I64d", &n, &k);
  if (n == 2 && k == 3) {
    printf("NO\n");
    return;
  }
  bool f1 = 0;
  long long num = 1, sum = 1;
  if (k == 1) f1 = 1;
  for (long long i = 2; i <= n; i++) {
    num *= 4;
    sum += num;
    if (sum >= k) {
      f1 = 1;
      break;
    }
  }
  if (!f1) {
    printf("NO\n");
    return;
  }
  num = 1, sum = 1;
  long long ans = 1;
  f1 = 0;
  for (long long i = 2; i <= n; i++) {
    num = num * 2 + 1;
    sum += num;
    if (sum > k) {
      ans = i - 1;
      f1 = 1;
      break;
    }
  }
  if (!f1) ans = n;
  printf("YES %I64d\n", n - ans);
}
int main() {
  int T_num;
  cin >> T_num;
  while (T_num--) Work();
}
