#include <bits/stdc++.h>
using namespace std;
const int N = (int)123;
long long dp[N];
void solve() {
  long long n, k;
  scanf("%lld %lld", &n, &k);
  if (k == 1) {
    printf("YES %lld\n", n - 1);
    return;
  }
  if (n > 31) {
    printf("YES %d\n", n - 1);
    return;
  }
  long long cur = 0;
  for (int i = 1; i <= n; i++) {
    cur += ((1LL << i) - 1);
    if (k - cur < 0) {
      puts("NO");
      return;
    }
    if (k <= dp[n] - ((1LL << (i + 1)) - 1) * dp[n - i]) {
      printf("YES %lld\n", n - i);
      return;
    }
  }
  puts("NO");
}
void precalc() {
  for (int i = 1; i <= 31; i++) {
    dp[i] = dp[i - 1] * 1LL * 4 + 1;
  }
}
int main() {
  precalc();
  int test;
  scanf("%d", &test);
  while (test--) {
    solve();
  }
}
