#include <bits/stdc++.h>
using namespace std;
unsigned long long t, n, k, cur;
unsigned long long res;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> t;
  while (t--) {
    cin >> n >> k;
    if (n >= 32) {
      cout << "YES " << n - 1 << '\n';
      continue;
    }
    res = ((1LL << (2 * n)) - 1) / 3;
    cur = n;
    unsigned long long need = 0;
    if (res < k) {
      cout << "NO\n";
      continue;
    }
    cur--;
    k--;
    res--;
    need = 3;
    while (k >= need && cur > 0) {
      k -= need;
      res -= need;
      cur--;
      need = 2 * need + 1;
    }
    unsigned long long tmp = ((1LL << (2 * cur)) - 1) / 3;
    if (res - need * tmp >= k) {
      cout << "YES " << cur << '\n';
    } else {
      cout << "NO\n";
    }
  }
  return 0;
}
