#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 7;
const int inf = INT_MAX;
const long long inff = 1e18;
const int mod = 1e9 + 7;
long long a[50];
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  a[0] = 0;
  for (long long i = 1; i <= 31; i++) {
    a[i] = 4 * a[i - 1] + 1;
  }
  long long t;
  cin >> t;
  while (t--) {
    long long n, k;
    cin >> n >> k;
    if (n <= 30 && k > a[n])
      cout << "NO" << endl;
    else if (k < 5) {
      if (k == 3 && n == 2)
        cout << "NO" << endl;
      else if (n == 2) {
        if (k == 1 || k == 2)
          cout << "YES 1" << endl;
        else
          cout << "YES 0" << endl;
      } else {
        cout << "YES " << n - 1 << endl;
      }
    } else {
      cout << "YES ";
      long long now;
      for (long long i = 1; i <= 31; i++) {
        if (a[i] >= k) {
          now = i;
          break;
        }
      }
      now--;
      if (a[now + 1] - k <= (((1ll << now) - 1) * ((1ll << now) - 1)))
        cout << n - now - 1 << endl;
      else
        cout << n - now << endl;
    }
  }
}
