import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author prakharjain
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD {
        long maxk = (long) 1e18;

        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int t = in.nextInt();

            long maxn = 1;
            long val = 0;
            for (long i = 1; ; i++) {
                val = 1 + 4 * val;
                if (val >= maxk) {
                    maxn = i;
                    break;
                }
            }

            long[] vala = new long[(int) maxn + 1];

            vala[1] = 1;

            for (int i = 2; i <= maxn; i++) {
                vala[i] = 1 + 4 * vala[i - 1];
            }

            o:
            while (t-- > 0) {
                long n = in.nextInt();
                long k = in.nextLong();

                if (n - 1 >= maxn) {
                    out.println("YES " + (n - 1));
                    continue;
                }

                k--;

                if (k <= vala[(int) n - 1]) {
                    out.println("YES " + (n - 1));
                    continue;
                }

                long cs = n - 1;
                long cc = 3;
                int ind = 2;

                long end = -1;
                while (k > 0) {
                    if (k >= cc && cs > 0) {
       ... What is the time complexity of the previous code?