#include <bits/stdc++.h>
using namespace std;
const int mod = (int)1e9 + 7;
const int inf = (int)2e9;
const long long INF = (long long)2e18;
const int M = (int)1e6 + 10;
const int N = 500500;
int t;
long long n, k;
long long lvl, sum, lft, a;
vector<long long> v;
void solve() {
  sum = lvl = lft = a = 0;
  v.clear();
  cin >> n >> k;
  while (sum + (1ll << (lvl + 1)) - 1 <= k && (lvl + 1) <= n) {
    lvl++;
    sum += (1ll << lvl) - 1;
  }
  lft = k - sum;
  a = n - lvl;
  long long cur = 0;
  long long d = 0;
  while (d + 1 <= min(n, 59 * 1ll)) {
    d++;
    cur += (1ll << d) - 1;
    v.push_back(cur);
  }
  bool can = false;
  if ((int((v).size())) == 0) can = true;
  cur = 1;
  long long st = 1;
  for (int i = 0; i < (int((v).size())); i++) {
    if (cur - v[i] >= lft) {
      can = true;
      break;
    }
    st *= 4;
    cur += st;
  }
  if (!can) {
    cout << "NO\n";
    return;
  }
  cout << "YES " << a << "\n";
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  cin >> t;
  for (int i = 1; i <= t; i++) solve();
  return 0;
}
