#include <bits/stdc++.h>
using namespace std;
const long long inf = 1LL << 60;
long long read() {
  char c = getchar();
  long long x = 0, f = 1;
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * f;
}
long long fpow(long long x, int k) {
  long long ans = 1;
  while (k) {
    if (k & 1) {
      if (ans > inf / x)
        ans = inf;
      else
        ans = ans * x;
    }
    if (x > inf / x)
      x = inf;
    else
      x = x * x;
    k >>= 1;
  }
  return ans;
}
int main() {
  int t = read();
  while (t--) {
    int n = read();
    long long k = read();
    if (n > 31) {
      printf("YES %d\n", n - 1);
      continue;
    }
    long long l = 0, r = 0;
    int flag = 0;
    for (int i = 1; i <= n; i++) {
      l += fpow(2, i) - 1;
      r += (fpow(2, i + 1) - 3) * (fpow(4, n - i) - 1) / 3;
      if (l <= k && k <= l + r) {
        printf("YES %d\n", n - i);
        flag = 1;
        break;
      }
    }
    if (flag == 0) printf("NO\n");
  }
  return 0;
}
