#include <bits/stdc++.h>
using namespace std;
long long n, k;
long long solve() {
  if (k == 3 && n >= 3) return n - 1;
  for (long long x = 1, ans = n; ans >= 1;) {
    if (k <= (x - 1) * (x - 1))
      return ans;
    else if (x + x - 1 <= k && k <= x * x)
      return ans - 1;
    else if (k > x * x) {
      k -= x * x;
      x *= 2;
      ans--;
    } else {
      return -1;
    }
  }
  return -1;
}
int main() {
  int test;
  cin >> test;
  for (int cas = 1; cas <= test; cas++) {
    cin >> n >> k;
    long long ret = solve();
    if (ret == -1)
      cout << "NO\n";
    else
      cout << "YES " << ret << "\n";
  }
}
