#include <bits/stdc++.h>
using namespace std;
long long int rem[100];
int main() {
  int T;
  scanf("%d", &T);
  for (int i = 1; rem[i - 1] <= 1e18; i++) {
    rem[i] = rem[i - 1] * 4 + 1;
  }
  while (T--) {
    int x, n;
    long long int k, tem = 1, num = 3;
    scanf("%d%lld", &n, &k);
    if (n > 31) {
      printf("YES %d\n", n - 1);
      continue;
    }
    bool flag = false;
    for (x = n; x > 0; x--) {
      if (k >= tem && k <= rem[n] - num * rem[x - 1]) {
        flag = true;
        break;
      }
      tem += num;
      num = num * 2 + 1;
    }
    if (flag)
      printf("%s %d\n", "YES", x - 1);
    else
      printf("NO\n");
  }
}
