#include <bits/stdc++.h>
using namespace std;
long long i, j, k, l, n, m, p, q, r, d, su, sx, sy,
    prod = 1, maxi, a, b, w, x, y, o, e, f, mini = 10000000000000, t, cnt;
string s, s1, s2;
long long ans[100005];
long long val[100005];
vector<pair<pair<long long, long long>, long long> > v;
map<long long, vector<pair<long long, long long> > > ma;
set<long long> se;
long long modularExponentiation(long long x, long long n) {
  if (n == 0)
    return 1;
  else if (n % 2 == 0)
    return modularExponentiation((x * x) % 998244353, n / 2);
  else
    return (x * modularExponentiation((x * x) % 998244353, (n - 1) / 2)) %
           998244353;
}
bool sortbysec(const pair<long long, long long> &a,
               const pair<long long, long long> &b) {
  return (a.second < b.second);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  unsigned long long ar[61];
  for (int i = 0; i < 61; i++) {
    ar[i] = (unsigned long long)pow(2, i + 1) - i - 2;
  }
  int ti = 1;
  cin >> ti;
  while (ti--) {
    cin >> n >> k;
    if (2 * n < ceil(log2l((long double)(3 * k + 1))) || (n == 2 && k == 3))
      cout << "NO" << endl;
    else {
      t = upper_bound(ar, ar + 61, k) - ar;
      t--;
      cout << "YES " << max(0LL, n - t) << endl;
    }
  }
  return 0;
}
