#include <bits/stdc++.h>
using namespace std;
long long getsum(long long n) {
  long long sum = 0;
  long long a = 1;
  for (int i = 0; i < n; i++) {
    sum += (a << i) * (a << i);
  }
  return sum;
}
pair<long long, long long> getnum(long long n) {
  long long ret = 0;
  long long a = 1;
  long long k = 0;
  for (int i = 0; n - (2 * (a << i) - 1) >= 0; i++) {
    ret += 2 * (a << i) - 1;
    n -= (2 * (a << i) - 1);
    k = i + 1;
  }
  return make_pair(ret, k);
}
void f(long long n, long long k) {
  long long a = 1;
  cin >> n >> k;
  pair<long long, long long> p;
  p = getnum(k);
  if (n > p.second + 1) {
    cout << "YES " << n - p.second << endl;
    return;
  }
  long long sum = getsum(n);
  if (sum < k) {
    cout << "NO" << endl;
    return;
  }
  if (p.second >= n) {
    cout << "YES " << 0 << endl;
    return;
  }
  long long number = 0;
  for (int i = 0; i <= p.second; i++) {
    number = (2 * (a << i) - 1);
  }
  sum -= p.first;
  sum -= (number * getsum(n - p.second));
  if (sum >= k - p.first) {
    cout << "YES " << n - p.second << endl;
    return;
  } else {
    cout << "NO" << endl;
    return;
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int t;
  cin >> t;
  for (int i = 1; i <= t; i++) {
    long long n, k;
    f(n, k);
  }
  return 0;
}
