#include <bits/stdc++.h>
using namespace std;
const int maxn = 510;
long long sum[maxn];
int main() {
  long long n, k;
  int t;
  cin >> t;
  while (t--) {
    cin >> n >> k;
    if (n >= 32) {
      cout << "YES"
           << " " << n - 1 << endl;
    } else {
      memset(sum, 0, sizeof(sum));
      int ans = -1;
      long long total = (pow(4, n) - 1) / 3;
      if (k > total) {
        cout << "NO" << endl;
        continue;
      }
      long long temp = pow(2, n - 1) * 2 - 1, cnt = 0;
      while (temp) {
        sum[++cnt] = 2 * (temp / 2) + 1;
        temp /= 2;
      }
      for (int i = cnt; i >= 1; i--) sum[i] += sum[i + 1];
      for (int i = 1; i <= cnt; i++)
        if (sum[i] <= k && total - sum[1] >= k - sum[i]) {
          ans = i;
          break;
        }
      if (ans == -1)
        cout << "NO" << endl;
      else
        cout << "YES"
             << " " << ans - 1 << endl;
    }
  }
}
