#include <bits/stdc++.h>
using namespace std;
const int maxn = 35;
long long pow2[maxn], pow4[maxn];
void pre() {
  long long temp = 1;
  for (int i = 0; i <= 62; i++) {
    pow2[i] = temp;
    temp *= 2;
  }
  for (int i = 0; i <= 31; i++) {
    pow4[i] = pow2[i * 2];
  }
}
int main() {
  pre();
  int T;
  cin >> T;
  for (int i = 1; i <= T; i++) {
    long long n, k;
    cin >> n >> k;
    if (n >= 32) {
      cout << "YES " << n - 1 << '\n';
      continue;
    }
    if (k > (pow4[n] - 1) / 3) {
      cout << "NO" << '\n';
      continue;
    }
    int x = lower_bound(pow4, pow4 + 31, 3 * k + 1) - pow4;
    if (pow4[x] >= 3 * k + 1)
      x--;
    else
      x = 0;
    k -= (pow4[x] - 1) / 3;
    if (k >= pow2[x + 1] - 1)
      cout << "YES " << n - x - 1 << '\n';
    else if (n - x > 0 && k <= (pow4[x] - pow2[x + 1] + 1) * pow4[n - x - 1])
      cout << "YES " << n - x << '\n';
    else
      cout << "NO" << '\n';
  }
  return 0;
}
