#include <bits/stdc++.h>
using namespace std;
long long t[32];
int main() {
  for (int i = 1; i <= 31; i++) t[i] = t[i - 1] * 4 + 1;
  long long n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    long long x, y;
    cin >> x >> y;
    if (x == 2 && y == 3)
      cout << "NO" << endl;
    else {
      long long vt = 0;
      for (int j = 1; j <= 31; j++)
        if (y > t[j]) vt = j;
      if (vt >= x)
        cout << "NO" << endl;
      else if (y == 3)
        cout << "YES " << x - 1 << endl;
      else
        cout << "YES " << x - (long long)roundf(log10(3 * y + 1) / log10(4))
             << endl;
    }
  }
}
