#include <bits/stdc++.h>
using namespace std;
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
long long int f(long long int n) {
  long long int ans = 1;
  if (n > 30) return 1000000000000000000LL;
  while (n--) {
    ans *= 4;
  }
  return (ans - 1) / 3;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t, i;
  cin >> t;
  while (t--) {
    long long int n, k;
    cin >> n >> k;
    if (n < 31) {
      if (f(n) < k) {
        cout << "NO" << endl;
        continue;
      }
    }
    if (k == 0) {
      cout << "YES " << n << endl;
      continue;
    }
    bool good = false;
    long long int L = 0, R = 0, coeff = -1, fn;
    for (i = 1; L <= k; ++i) {
      coeff += 1LL << i;
      long long int oldL = L;
      L += (1LL << i) - 1;
      fn = f(n - i);
      if (fn == 1000000000000000000LL)
        R = fn;
      else
        R = R - oldL + L + coeff * f(n - i);
      if (k >= L and k <= R) {
        good = true;
        break;
      }
    }
    if (good)
      cout << "YES " << n - i << endl;
    else
      cout << "NO" << endl;
  }
  return 0;
}
