#include <bits/stdc++.h>
using namespace std;
long long a[100000], b[100000], c[100000];
int main() {
  int t;
  cin >> t;
  a[0] = 0;
  a[1] = 1LL;
  for (int i = 2; i <= 31; i++) a[i] = 4LL * a[i - 1] + 1LL;
  while (t--) {
    int n;
    long long k;
    cin >> n >> k;
    if (n > 31) {
      cout << "YES " << n - 1 << endl;
      continue;
    }
    long long j = 0, now = 1, re = 0, tot = 0;
    while (tot + now <= k && j < n) {
      tot += now;
      now = now * 2 + 1;
      j++;
      re += a[n - j] * (now - 2);
    }
    if (re + tot < k) {
      cout << "NO" << endl;
      continue;
    } else {
      cout << "YES " << n - j << endl;
    }
  }
  return 0;
}
