import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class DigitSeq {

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader()
		{
			br = new BufferedReader(new
					InputStreamReader(System.in));
		}

		String next()
		{
			while (st == null || !st.hasMoreElements())
			{
				try
				{
					st = new StringTokenizer(br.readLine());
				}
				catch (IOException  e)
				{
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt()
		{
			return Integer.parseInt(next());
		}

		long nextLong()
		{
			return Long.parseLong(next());
		}

		double nextDouble()
		{
			return Double.parseDouble(next());
		}

		String nextLine()
		{
			String str = "";
			try
			{
				str = br.readLine();
			}
			catch (IOException e)
			{
				e.printStackTrace();
			}
			return str;
		}
	}

	public static void main(String[] args) {

		FastReader sc = new FastReader();
		OutputStream outputstream = System.out;
		PrintWriter out = new PrintWriter(outputstream);

		long n = sc.nextLong();
		long[] arr = new long[14];
		for(int i = 1; i <= 13; i++){
			arr[i] = (long)Math.pow(10, i)-(long)Math.pow(10, i-1);
		}
		long total = 0;
		/*for(int i = 1; i <= 13; i++) out.print(arr[i] + " ");
		out.println();*/
		for(int i = 1; i <= 13; i++){
			if(total+(long)i*arr[i]>=n){
				long ans = n-total;
				long rest = ans;
				//System.out.println(rest);
				if(ans%i!=0){
					ans /= i;
					ans++;
				} else {
					ans /= i;
				}
				ans += (long)Math.pow(10, i-1)-1;
				String str = Long.toString(ans);
				int ind = (rest%i==0) ? i-1 : (int)(rest%i)-1;
				//System.out.println(ind);
				out.println(str.charAt(ind));
				break;
			}
			total = total+(long)i*arr[i];
			//System.out.println(total);
		}
		out.close();
	}

}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

public class A {
    void solve(){
        long k = readLong();

       long x = 9;
       long y = 1;
       while(k > x * y){
           k -= x * y;
           x *= 10;
           y++;
       }

       long w = k / y + (k % y == 0 ? 0 : 1);
       long e = (k % y - 1 % y + y) % y;

       long num = x/9 + w - 1;
       String s = Long.toString(num);
       out.print(s.charAt((int) e) - '0');
    }

    public static void main(String[] args) {
        new A().run();
    }

    void run(){
        init();
        solve();
        out.close();
    }

    BufferedReader in;
    PrintWriter out;

    StringTokenizer tok = new StringTokenizer("");

    void init(){
        in = new BufferedReader(new InputStreamReader(System.in));
        out  = new PrintWriter(System.out);
    }

    String readLine(){
        try{
            return in.readLine();
        }catch(Exception ex){
            throw new RuntimeException(ex);
        }
    }
    String readString(){
        while(!tok.hasMoreTokens()){
            String nextLine = readLine();
            if(nextLine == null) return null;
            tok = new StringTokenizer(nextLine);
        }
        return tok.nextToken();
    }

    int readInt(){
        return Integer.parseInt(readString());
    }

    long readLong(){
        return Long.parseLong(readString());
    }

    double readDouble(){
        return Double.parseDouble(readString());
    }
}


// Don't place your source in a package

import java.math.BigInteger;
import java.util.*;
import java.lang.*;
import java.io.*;

// Please name your class Main
public class Main {
    static FastScanner fs=new FastScanner();
    static class FastScanner {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st=new StringTokenizer("");
        public String next() {
            while (!st.hasMoreElements())
                try {
                    st=new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }
        int Int() {
            return Integer.parseInt(next());
        }

        long Long() {
            return Long.parseLong(next());
        }

        String Str(){
            return next();
        }
    }

    public static void main (String[] args) throws java.lang.Exception {
        PrintWriter out = new PrintWriter(System.out);

        int T=1;
        for(int t=0;t<T;t++){
            long k=Long();
            Solution sol=new Solution(out);
            sol.solution(k);
        }
        out.flush();

    }

    public static int Int(){
        return fs.Int();
    }
    public static long Long(){
        return fs.Long();
    }
    public static String Str(){
        return fs.Str();
    }

}

class Solution{
    PrintWriter out;
    public Solution(PrintWriter out){
        this.out=out;
    }

    long f[]=new long[15];
    public void solution(long k){
        f[0]=9;
        for(int i=1;i<f.length;i++){
            f[i]=10*f[i-1];
        }
        for(int i=1;i<f.length;i++){
            f[i]*=(i+1);
        }

        long l=1,r=1000000000000l;
        long res=-1;
        long count=0;
        while(l<=r){
            long mid=l+(r-l)/2;
            long cnt=get(mid);
            if(cnt>=k){
                res=mid;
                count=cnt;
                r=mid-1;
            }
            else{
                l=mid+1;
            }
        }

        int extra=(int)(count-k);
        String s=res+"";
        out.println(s.charAt(s.length()-1-extra));
    }

    public long get(long n){
        long res=0;
        long base=0;
        int i=0;
        while(true){
            if(n<=base*10+9){
                res=res+(i+1)*(n-base);
                break;
            }
            res+=(f[i]);
            i++;
            base=base*10+9;
        }
        return res;
    }

}

/*
                             ;\
                            |' \
         _                  ; : ;
        / `-.              /: : |
       |  ,-.`-.          ,': : |
       \  :  `. `.       ,'-. : |
        \ ;    ;  `-.__,'    `-.|
         \ ;   ;  :::  ,::'`:.  `.
          \ `-. :  `    :.    `.  \
           \   \    ,   ;   ,:    (\
            \   :., :.    ,'o)): ` `-.
           ,/,' ;' ,::"'`.`---'   `.  `-._
         ,/  :  ; '"      `;'          ,--`.
        ;/   :; ;             ,:'     (   ,:)
          ,.,:.    ; ,:.,  ,-._ `.     \""'/
          '::'     `:'`  ,'(  \`._____.-'"'
             ;,   ;  `.  `. `._`-.  \\
             ;:.  ;:       `-._`-.\  \`.
              '`:. :        |' `. `\  ) \
      -hrr-      ` ;:       |    `--\__,'
                   '`      ,'
                        ,-'

                      free bug dog
*/


//package test_1177a;

import java.util.Scanner;

import java.util.Scanner;

    public class test1177b{
        public  static  void main(String[] args){
            Scanner sc = new Scanner(System.in);
            long k =  sc.nextLong();
            long k1 =0,k2 = 0;
            long p = 1;
            String str="";
            for (int i=1; i<=12;i++){
                if (k>= k1 && k <= k1 + p * 9 *i){
                    // Нашли порядок
                    long kk = ((k - k1) % i);

                    k2 = p  + (k - k1) / i -1;
                    if (kk != 0) k2 ++;
                    str =""+ k2;
                    if(str.length() > i) {
                        k2--;
                        str =""+ k2;
                        kk =0;
                    }
                    if(kk > 0){
                        System.out.println(str.charAt((int)kk-1));
                    }else{
                        System.out.println(str.charAt(i-1));
                    }
                    break;
                }else {
                    k1 += p * 9 *i;
                    p = p * 10;
                }
            }

        }
    }


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class CodeForces1177B {

	public static char custBinSearch(long lower, long upper, long lowIndex, int ten, long position) {
		long half = Math.round((lower + upper) / 2.0);

		long lowBound = lowIndex + (half - lower)*(ten + 1);
		long upBound = lowBound + ten;

		if(position < lowBound) { //Less than the lowest index of half
			return custBinSearch(lower, half - 1, lowIndex, ten, position);

		} else if (position > upBound) { //Remember to update lowIndex here.
			lowIndex += (half + 1 - lower)*(ten + 1);
			return custBinSearch(half + 1, upper, lowIndex, ten, position);

		} else {
			return Long.toString(half).charAt((int) (position - lowBound)); //The final number will at max be 11 characters long, thus it is safe to convert and cast.

		}

	}

	public static void main(String[] args) throws IOException  {
		BufferedReader inputs = new BufferedReader(new InputStreamReader(System.in));

		long indexPosition = Long.parseLong(inputs.readLine());

		inputs.close();

		//Isolate possible combinations so that all further numbers will have the same length.
		int tenFactor = 0;
		long lowerBound = 1;
		long upperBound = (long) (Math.pow(10, 12));
		long lowerIndexBound = 1;
		long redIndex = 0;
		redIndex += indexPosition;

		while(redIndex > 0) {
			redIndex -= (long) (9*Math.pow(10, tenFactor)*(tenFactor + 1));
			if(redIndex <= 0) { //Stage 1: Completed Successfully.
				lowerBound = (long) (Math.pow(10, tenFactor));
				upperBound = (long) (Math.pow(10, tenFactor + 1) - 1);
				break;
			}

			lowerIndexBound += (long) (9*Math.pow(10, tenFactor)*(tenFactor + 1));
			tenFactor++;

		}

		System.out.println(custBinSearch(lowerBound, upperBound, lowerIndexBound, tenFactor, indexPosition));

	}
}


import java.util.Scanner;

public class Main {

	public static Character solve(long a, long b, long c) {
		long min = a;
		long max;
		long xth = 0;
		long index;

		for (index = String.valueOf(a).length() - 1;; index++) {
			long numOfDigits = 0;
			max = (long) Math.pow(10, index + 1) - 1;
			long count = (max - min) / b + 1;
			numOfDigits += count * (index + 1);

			if (c - numOfDigits <= 0) {
				break;
			}
			c -= numOfDigits;
			min = min + count * b;

		}

		// find xth
		if (c % (index + 1) == 0) {
			xth = c / (index + 1);
		} else {
			xth = c / (index + 1) + 1;
		}
		long lastNum = min + b * (xth - 1);

		int pos = (int) (c % (index + 1));

		// here is the output
		if (pos == 0) {
			return String.valueOf(lastNum).charAt((int) index);
		} else {
			return String.valueOf(lastNum).charAt(pos - 1);
		}
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long tc;
		tc = sc.nextLong();
		System.out.println(solve(1, 1, tc));
		}

}


import java.util.Scanner;

public class B1177 {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        long N = in.nextLong();
        long answer = solve(N, 0, 1, 1);
        System.out.println(answer);
    }

    static long solve(long N, long offset, long start, int digits) {
        long thisSection = digits*start*9;
        long fromOffset = N-offset;
        if (fromOffset > thisSection) {
            return solve(N, offset+thisSection, 10*start, digits+1);
        }
        long number = start + (fromOffset-1)/digits;
        long posInNumber = digits - 1 - (fromOffset-1)%digits;
        while (posInNumber > 0) {
            posInNumber--;
            number /= 10;
        }
        return number%10;
    }

}


import java.util.Scanner;
public class Solution {
    public static void main(String[] args) {
        long b=0;long p=1;
        Scanner s=new Scanner(System.in);
        long m=s.nextLong();
        long x=1;
        do{
            p=(m+b)/x;
            b=10*b+10;
            x++;
        }while(p/(long)Math.pow(10, x-1)!=0);
        rest :
        x--;b=b/10-1;
        b=x*p-b;
        b=m-b;
        b=x-b-1;
        p/=(long)Math.pow(10, b);
        p%=10;
        System.out.println(p);
    }
}


import java.util.*;
import java.io.*;

public class Main {
	public static void main(String args[]) {new Main().run();}

	FastReader in = new FastReader();
	PrintWriter out = new PrintWriter(System.out);
	void run(){
		int q=in.nextInt();
		for(int i=0;i<q;i++) {
			work();
		}
		out.flush();
	}
	long mod=1000000007;
	long gcd(long a,long b) {
		return a==0?b:b>a?gcd(b%a,a):gcd(b,a);
	}
	void work() {
		long n=in.nextLong();
		long k=in.nextLong();
		if(k==0) {
			out.println("YES"+" "+n);
		}
		long a=0,b=0,c=1,d=1;
		while(--n>=0&&a<=k) {
			b+=c;
			c*=4;
			a+=d;
			d=d*2+1;
			long t=count(c-d,n);
			if(a<=k&&b>=k-t) {
				out.println("YES"+ " "+n);
				return;
			}
		}
		out.println("NO");
	}
	private long count(long l, long n) {
		if(n==0)return 0;
		n--;
		long ret=l;
		for(int i=1;i<=n;i++) {
			long t=ret;
			ret*=4;
			if(ret/4!=t)return Long.MAX_VALUE;
		}
		return ret;
	}
}

class FastReader
{
	BufferedReader br;
	StringTokenizer st;

	public FastReader()
	{
		br=new BufferedReader(new InputStreamReader(System.in));
	}

	public String next()
	{
		if(st==null || !st.hasMoreElements())
		{
			try {
				st = new StringTokenizer(br.readLine());
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return st.nextToken();
	}

	public int nextInt()
	{
		return Integer.parseInt(next());
	}

	public long nextLong()
	{
		return Long.parseLong(next());
	}
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class D {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            int T = in.ni();
            for (int t = 0; t < T; t++) {
                long n = in.nl(), k = in.nl();
                if (n == 2 && k == 3) {
                    out.println("NO");
                    continue;
                }

                boolean possible = false;
                long size = n;
                long rem = k;
                for (int i = 0; i <= 31 && size > 0 && rem > 0; i++) {
                    long splits = 1L << (i * 2);
                    //System.out.println("splits = " + splits);
                    rem -= splits;
                    size--;
                }
                if (rem > 0) {
                    //System.out.println("rem = " + rem);
                    out.println("NO");
                    continue;
                }
                long path = 1;
                long i = 0;
                size = n;
                long ans = 0;

                while (path <= k && size > 0) {
                    //System.out.printf("path=%d k=%d size=%d%n", path, k, size);
                    k -= path;
                    path = (1L << i + 2) - 1;
                    size--;
                    i++;
                }

                //System.out.printf("size=%d k=%d%n", size, k);
                out.println("YES " + size);

            }
        }

    }

    static class FastScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public FastScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String ns() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

        public int ni() {
            return Integer.parseInt(ns());
        }

        public long nl() {
            return Long.parseLong(ns());
        }

    }
}


public class D {

	public Object solve() {
		long N = sc.nextLong(), K = sc.nextLong() - 1;
		if (N >= 32)
			return print("YES", N-1);

		long A = 1L << (N-1), C = 4, T = (A*A - 1) / 3;

		while (A > 1 && K > T) {
			A /= 2;
			K -= (C-1);
			C *= 2;
			T += (C-3) * (A*A - 1) / 3;
		}

		if (K >= 0 && K <= T)
			return print("YES", Long.numberOfTrailingZeros(A));
		else
			return print("NO");
	}

	private static final boolean ONE_TEST_CASE = false;

	private static void init() {
	}

	//////////////////////////////////////////////////////////////////////////////////// OFF
	private static IOUtils.MyScanner sc = new IOUtils.MyScanner();
	private static Object print (Object o, Object ... A) { IOUtils.print(o, A); return null; }
	private static class IOUtils {
		public static class MyScanner {
			public String next() { newLine(); return line[index++]; }
			public int nextInt() { return Integer.parseInt(next()); }
			public long nextLong() { return Long.parseLong(next()); }
			//////////////////////////////////////////////
			private boolean eol() { return index == line.length; }
			private String readLine() {
				try {
					return r.readLine();
				} catch (Exception e) {
					throw new Error (e);
				}
			}
			private final java.io.BufferedReader r;
			private MyScanner () { this(new java.io.BufferedReader(new java.io.InputStreamReader(System.in))); }
			private MyScanner (java.io.BufferedReader r) {
				try {
					this.r = r;
					while (!r.ready())
						Thread.sleep(1);
					start();
				} catch (Exception e) {
					throw new Error(e);
				}
			}
			private String [] line;
			private int index;
			private void newLine() {
				if (line == null || eol()) {
					line = split(readLine());
					index = 0;
				}
			}
			private String [] split(String s) { return s.length() > 0 ? s.split(" ") : new String [0]; }
		}
		private static String build(Object o, Object ... A) { return buildDelim(" ", o, A); }
		private static String buildDelim(String delim, Object o, Object ... A) {
			StringBuilder b = new StringBuilder();
			append(b, o, delim);
			for (Object p : A)
				append(b, p, delim);
			return b.substring(delim.length());
		}
		//////////////////////////////////////////////////////////////////////////////////
		private static final java.text.DecimalFormat formatter = new java.text.DecimalFormat("#.#########");
		private static void start() { if (t == 0) t = millis(); }
		private static void append(java.util.function.Consumer<Object> f, java.util.function.Consumer<Object> g, final Object o) {
			if (o.getClass().isArray()) {
				int len = java.lang.reflect.Array.getLength(o);
				for (int i = 0; i < len; ++i)
					f.accept(java.lang.reflect.Array.get(o, i));
			}
			else if (o instanceof Iterable<?>)
				((Iterable<?>)o).forEach(f::accept);
			else
				g.accept(o instanceof Double ? formatter.format(o) : o);
		}
		private static void append(final StringBuilder b, Object o, final String delim) {
			append(x -> { append(b, x, delim); }, x -> b.append(delim).append(x), o);
		}
		private static java.io.PrintWriter pw = new java.io.PrintWriter(System.out);
		private static Object print(Object o, Object ... A) {
			pw.println(build(o, A));
			if (DEBUG)
				System.err.println(build(o, A));
			 return null;
		}
		private static void err(Object o, Object ... A) { System.err.println(build(o, A)); }
		private static boolean PRINT, DEBUG;
		private static void write(Object o) {
			err(o, '(', time(), ')');
			if (PRINT)
				pw.println(o);
		}
		private static void exit() {
			IOUtils.pw.close();
			System.out.flush();
			err("------------------");
			err(time());
			System.exit(0);
		}
		private static long t;
		private static long millis() { return System.currentTimeMillis(); }
		private static String time() { return "Time: " + (millis() - t) / 1000.0; }
		private static void run(int N) {
			try {
				DEBUG = System.getProperties().containsKey("DEBUG");
				PRINT = System.getProperties().containsKey("PRINT");
			}
			catch (Throwable t) {}

			for (int n = 1; n <= N; ++n) {
				Object res = new D().solve();
				if (res != null)
					write("Case #" + n + ": " + build(res));
			}
			exit();
		}
	}
	////////////////////////////////////////////////////////////////////////////////////
	public static void main(String[] args) {
		init();
		int N = ONE_TEST_CASE ? 1 : sc.nextInt();
		IOUtils.run(N);
	}
}


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) {
                        k -= cc;
                        cc += (1l << ind);
                        cs--;
                        ind++;
                    } else {
//                    if (cs > 0 && k < cc) {
//                        out.println("YES " + cs);
//                        continue o;
//                    }
                        end = ind;
                        break;
                    }
                }

                long fcs = cs;

                if (k == 0) {
                    out.println("YES " + cs);
                    continue;
                }

                k -= vala[(int) n - 1];

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

                long rv = 5;

                long sind = 3;

                while (k > 0 && ind < end) {
                    k -= rv * vala[(int) cs - 1];
                    rv += (1l << sind);
                    sind++;
                    cs--;
                    ind++;
                }

                if (k <= 0) {
                    out.println("YES " + fcs);
                } else {
                    out.println("NO");
                }
            }
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void print(Object... objects) {
            for (int i = 0; i < objects.length; i++) {
                if (i != 0) {
                    writer.print(' ');
                }
                writer.print(objects[i]);
            }
        }

        public void println(Object... objects) {
            print(objects);
            writer.println();
        }

        public void close() {
            writer.close();
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}


import javafx.util.*;
import java.util.*;
import java.io.*;
import java.math.*;

public class Test4 {

    PrintWriter pw = new PrintWriter(System.out); InputStream is = System.in;
    Random rnd = new Random();
    int a;

    void run(){
        a = ni();
        for(int q=0; q<a; q++){
            long nj = ni(), kj = nl();
            BigInteger n = BigInteger.valueOf(nj), k = BigInteger.valueOf(kj);
            if((nj<40 && (k.compareTo(BigInteger.valueOf(2).pow(2*(int)nj).divide(BigInteger.valueOf(3)))>0))){
                System.out.println("NO");
                continue;
            }
            if(nj>=40){
                System.out.println("YES "+(nj-1));
                continue;
            }
            long log=nj;
            BigInteger maxop = BigInteger.valueOf(2).pow(2*(int)nj).divide(BigInteger.valueOf(3)), pth = BigInteger.ONE;
            for(BigInteger c = BigInteger.ONE; log>0; log--, c=c.multiply(BigInteger.valueOf(2)).add(BigInteger.ONE)){
                if(k.compareTo(c)<0) break;
                pth = c.multiply(BigInteger.valueOf(2)).add(BigInteger.ONE);
                k=k.subtract(c);
                maxop=maxop.subtract(c);
            }
            maxop = maxop.subtract(pth.multiply(BigInteger.valueOf(2).pow(2*(int)log).divide(BigInteger.valueOf(3))));
            if(k.compareTo(maxop)<=0) System.out.println("YES "+log);
            else System.out.println("NO");
        }
        pw.flush();
    }

    static class PyraSort {

        private static int heapSize;

        public static void sort(int[] a) {
            buildHeap(a);
            while (heapSize > 1) {
                swap(a, 0, heapSize - 1);
                heapSize--;
                heapify(a, 0);
            }
        }

        private static void buildHeap(int[] a) {
            heapSize = a.length;
            for (int i = a.length / 2; i >= 0; i--) {
                heapify(a, i);
            }
        }

        private static void heapify(int[] a, int i) {
            int l = 2 * i + 2;
            int r = 2 * i + 1;
            int largest = i;
            if (l < heapSize && a[i] < a[l]) {
                largest = l;
            }
            if (r < heapSize && a[largest] < a[r]) {
                largest = r;
            }
            if (i != largest) {
                swap(a, i, largest);
                heapify(a, largest);
            }
        }

        private static void swap(int[] a, int i, int j) {
            a[i] ^= a[j] ^= a[i];
            a[j] ^= a[i];
        }
    }

    public static void main(String[] args) {
        new Test4().run();
    }

    private byte[] inbuf = new byte[1024];
    public int lenbuf = 0, ptrbuf = 0;

    private int readByte()
    {
        if(lenbuf == -1)throw new InputMismatchException();
        if(ptrbuf >= lenbuf){
            ptrbuf = 0;
            try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
            if(lenbuf <= 0)return -1;
        }
        return inbuf[ptrbuf++];
    }

    private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
    private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }

    private double nd() { return Double.parseDouble(ns()); }
    private char nc() { return (char)skip(); }

    private String ns()
    {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while(!(isSpaceChar(b))){
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    private char[] ns(int n)
    {
        char[] buf = new char[n];
        int b = skip(), p = 0;
        while(p < n && !(isSpaceChar(b))){
            buf[p++] = (char)b;
            b = readByte();
        }
        return n == p ? buf : Arrays.copyOf(buf, p);
    }

    private char[][] nm(int n, int m)
    {
        char[][] map = new char[n][];
        for(int i = 0;i < n;i++)map[i] = ns(m);
        return map;
    }

    private int[] na(int n)
    {
        int[] a = new int[n];
        for(int i = 0;i < n;i++)a[i] = ni();
        return a;
    }

    private int ni()
    {
        int num = 0, b;
        boolean minus = false;
        while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
        if(b == '-'){
            minus = true;
            b = readByte();
        }
        while(true){
            if(b >= '0' && b <= '9'){
                num = num * 10 + (b - '0');
            }else{
                return minus ? -num : num;
            }
            b = readByte();
        }
    }

    private long nl()
    {
        long num = 0;
        int b;
        boolean minus = false;
        while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
        if(b == '-'){
            minus = true;
            b = readByte();
        }
        while(true){
            if(b >= '0' && b <= '9'){
                num = num * 10 + (b - '0');
            }else{
                return minus ? -num : num;
            }
            b = readByte();
        }
    }
}


import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

    static ArrayList<BigInteger> bs = new ArrayList<>();

    static void getBs(int n, BigInteger k) {
        BigInteger four = BigInteger.valueOf(4);
        BigInteger tmp4 = BigInteger.valueOf(1);
        BigInteger sum = BigInteger.ZERO;
        for (int i = 1; i <= n; i++) {
            sum = sum.add(tmp4);
            bs.add(sum);
            if (sum.compareTo(k) >= 0) break;
            tmp4 = tmp4.multiply(four);
        }
    }

    static int ss(int n, BigInteger k) {
        bs = new ArrayList<>();
        BigInteger two = BigInteger.valueOf(2);
        BigInteger s1;
        BigInteger ts = BigInteger.ZERO;
        getBs(n - 1, k);
        int idx = bs.size() - 1;
        BigInteger tx = BigInteger.valueOf(-1);
        int ans = -1;
        for (int i = 1; i <= n; i++) {
            two = two.shiftLeft(1);
            s1 = two.add(BigInteger.valueOf(-i - 2));
            if (idx >= 0) {
                tx = tx.add(BigInteger.ONE).multiply(BigInteger.valueOf(2)).add(BigInteger.ONE);
                ts = ts.add(tx.multiply(bs.get(idx--)));
            }
            if (k.compareTo(s1) >= 0) {
                if (k.subtract(s1).compareTo(ts) <= 0) {
                    ans = n - i;
                    break;
                }
            }
        }
        return ans;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int T = sc.nextInt();
        while (T-- > 0) {
            int n = sc.nextInt();
            BigInteger k = sc.nextBigInteger();
            int ans = ss(n, k);
            if (ans == -1) {
                System.out.println("NO");
            } else {
                System.out.println("YES " + ans);
            }
        }
    }
}


import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.StringTokenizer;

/**
 * Created by timur on 28.03.15.
 */

public class TaskD {
    boolean eof;
    BufferedReader br;
    StringTokenizer st;
    PrintWriter out;

    public static void main(String[] args) throws IOException {
        new TaskD().run();
    }

    public String nextToken() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                eof = true;
                return "-1";
            }
        }
        return st.nextToken();
    }

    public int nextInt() {
        return Integer.parseInt(nextToken());
    }

    public long nextLong() {
        return Long.parseLong(nextToken());
    }

    double nextDouble() {
        return Double.parseDouble(nextToken());
    }

    String nextLine() throws IOException {
        return br.readLine();
    }

    void run() throws IOException {
        InputStream input = System.in;
        PrintStream output = System.out;
        try {
            File f = new File("a.in");
            if (f.exists() && f.canRead()) {
                input = new FileInputStream(f);
                output = new PrintStream("a.out");
            }
        } catch (Throwable e) {
        }
        br = new BufferedReader(new InputStreamReader(input));
        out = new PrintWriter(output);
        solve();
        br.close();
        out.close();
    }

    long md(long x, long y, long x1, long y1) {
        return Math.abs(x - x1) + Math.abs(y - y1);
    }

    double md(double x, double y, double x1, double y1) {
        return Math.abs(x - x1) + Math.abs(y - y1);
    }

    double ed(double x, double y, double x1, double y1) {
        return Math.sqrt((x - x1) * (x - x1) + (y - y1) * (y - y1));
    }

    void solve() {
        int t = nextInt();
        long n, k;
        int m = 34;
        long[] res = new long[m];
        res[1] = 0;
        res[2] = 1;
        for (int i = 3; i < m; i++) {
            res[i] = res[i - 1] * 4L;
        }
        long[] l = new long[m];
        long[] r = new long[m];
        l[0] = 0;
        l[1] = 1;
        r[0] = 0;
        r[1] = 1;
        for (int i = 2; i < m; i++) {
            l[i] = l[i - 1] * 2 + 1;
            r[i] = r[i - 1] * 4;
        }

        long[] mi = new long[m];
        long[] ma = new long[m];
        for (int i = 1; i < m; i++) {
            mi[i] = mi[i - 1] + l[i];
            ma[i] = ma[i - 1] + r[i];
        }

//        for (int i = 0; i < m - 1; i++) {
//            for (int j = 0; j <= i; j++) {
//                out.println(i + " " + j + " " + mi[(int)i - j] + " " + (ma[(int)i] - l[(int)i - j + 1] * ma[j]));
//            }
//        }

        for (int i = 0; i < t; i++) {
            n = nextLong();
            k = nextLong();
            if (n >= 32) {
                out.println("YES " + (n - 1));
            } else {
                if (k > ma[(int)n]) {
                    out.println("NO");
                } else {
                    for (int j = 0; j <= n; j++) {
                        if (mi[(int)n - j] <= k && ma[(int)n] - l[(int)n - j + 1] * ma[j] >= k) {
                            out.println("YES " + j);
                            break;
                        }
                        if (j == n - 1) {
                            out.println("NO");
                        }
                    }
                }
            }
        }
    }

}


import java.math.*;
import java.text.*;
import java.util.*;
public class Main {

    public static void main(String args[]) {
        Scanner sca = new Scanner(System.in);
        long k,n;
        long ans;
        long[] pw = new long[33];
        pw[1]=4;
        pw[0]=1;
        for(int i=2;i<=31;i++)
            pw[i]=pw[i-1]<<2;
        int t;
        t = sca.nextInt();
        for(int cas=1;cas<=t;cas++) {
            n = sca.nextLong();
            k = sca.nextLong();
            ans = n;
            long last, path = 1;
            for (int i = 0; ; i++) {
                if ((pw[i + 1] - 1) / 3 > k) {
                    ans -= i;
                    last = k - (pw[i] - 1) / 3;
                    break;
                }
                path *= 2;
            }
            long sp = path * 2 - 1;
            if (ans < 0 || (ans == 0 && last > 0)) {
                System.out.println("NO");
                continue;
            }
            BigInteger sq = BigInteger.valueOf(path).multiply(BigInteger.valueOf(path)).subtract(BigInteger.valueOf(sp));
            if (ans == 1 && sq.compareTo(BigInteger.valueOf(last))==-1 && last < sp) {
                System.out.println("NO");
                continue;
            } else if (ans == 1 && last >= sp) {
                ans--;
            }
            System.out.println("YES "+ans);
        }

    }
}


import java.io.*;
import java.util.StringTokenizer;

import static java.lang.Math.max;
import static java.lang.Math.min;

public class Main {
    FastScanner in;
    PrintWriter out;

    void run() {
        in = new FastScanner();
        out = new PrintWriter(System.out);
        solve();
        out.close();
    }

    class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public FastScanner(String s) {
            try {
                br = new BufferedReader(new FileReader(s));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        public String nextToken() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextToken());
        }

        public long nextLong() {
            return Long.parseLong(nextToken());
        }

        public double nextDouble() {
            return Double.parseDouble(nextToken());
        }
    }

    public static void main(String[] args) {
        new Main().run();
    }

    void solve() {
        int t = in.nextInt();

        for (int sdfsdf = 0; sdfsdf < t; sdfsdf++) {
            long n = in.nextLong();
            long k = in.nextLong();

            if (n == 1) {
                if (k == 1)  {
                    out.println("YES 0");
                } else {
                    out.println("NO");
                }
                continue;
            }

            if (k == 3) {
                if (n == 2) {
                    out.println("NO");
                } else {
                    out.println("YES " + (n - 1));
                }
                continue;
            }

            long cuts = 1;
            long squares = 4;
            int zoom = 1;

            while (k > cuts + squares) {
                cuts += squares;
                squares *= 4;
                zoom++;
            }

            if (zoom > n) {
                out.println("NO");
                continue;
            }

            if (zoom == n && k > cuts) {
                out.println("NO");
                continue;
            }

            long current_cuts = k - cuts;

            if (current_cuts > squares - (2L * Math.sqrt(squares) - 1L)) {
                out.println("YES " + (n - zoom - 1L));
            } else {
                out.println("YES " + (n - zoom));
            }
        }
    }
}


import java.awt.List;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.PriorityQueue;
import java.util.Random;
import java.util.TreeSet;

public final class CF_524_D2_D {

	static boolean verb=true;
	static void log(Object X){if (verb) System.err.println(X);}
	static void log(Object[] X){if (verb) {for (Object U:X) System.err.print(U+" ");System.err.println("");}}
	static void log(int[] X){if (verb) {for (int U:X) System.err.print(U+" ");System.err.println("");}}
	static void log(int[] X,int L){if (verb) {for (int i=0;i<L;i++) System.err.print(X[i]+" ");System.err.println("");}}
	static void log(long[] X){if (verb) {for (long U:X) System.err.print(U+" ");System.err.println("");}}

	static void logWln(Object X){if (verb) System.err.print(X);}
	static void info(Object o){	System.out.println(o);}
	static void output(Object o){outputWln(""+o+"\n");	}
	static void outputWln(Object o){try {out.write(""+ o);} catch (Exception e) {}}

	// Global vars
	static BufferedWriter out;
	static InputReader reader;

	static long mod=1000000007;

	static void process() throws Exception {

		out = new BufferedWriter(new OutputStreamWriter(System.out));
		reader=new InputReader(System.in);

		long mymax=1L<<62;
		log(mymax);

		long cut=0;
		int it=0;
		long squares=1;
		int GX=32;
		long[] maxgen=new long[GX];
		while (cut<2000000000000000000L){
			maxgen[it]=cut;
			//log("squares:"+squares+" cut:"+cut+" it:"+it+" size:"+(1L<<it));
			it++;
			cut=1+4*cut;
			squares*=4;

		}
		//log(maxgen);

		int T=reader.readInt();
		for (int t=0;t<T;t++){
			int n=reader.readInt();
			long k=reader.readLong();

			if (n>=GX){
				output("YES "+(n-1));
			} else {
				// do first cut
				long pieces=3;
				long minc=1;
				int size=n-1;
				long maxc=1+maxgen[size];
				while (size>0 && maxc<k){
					minc+=pieces;
					maxc+=pieces+maxgen[size-1]*(2*pieces-1);
					size--;
					pieces=2*pieces+1;

				}
				if (minc<=k && maxc>=k){
					output("YES "+size);
				} else {
					output("NO");
					//log("//check:"+maxc+" "+maxgen[n]);
				}
				//log("size:"+size+" minc:"+minc+" maxc:"+maxc);
			}

		}

		try {
			out.close();
		}
		catch (Exception EX){}

	}

	public static void main(String[] args) throws Exception {
		process();

	}

	static final class InputReader {
		private final InputStream stream;
		private final byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;

		public InputReader(InputStream stream) {
			this.stream = stream;
		}

		private int read() throws IOException {
			if (curChar >= numChars) {
				curChar = 0;
				numChars = stream.read(buf);
				if (numChars <= 0) {
					return -1;
				}
			}
			return buf[curChar++];
		}

		public final String readString() throws IOException {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			StringBuilder res=new StringBuilder();
			do {
				res.append((char)c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public final int readInt() throws IOException {
			int c = read();
			boolean neg=false;
			while (isSpaceChar(c)) {
				c = read();
			}
			char d=(char)c;
			//log("d:"+d);
			if (d=='-') {
				neg=true;
				c = read();
			}
			int res = 0;
			do {
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			//log("res:"+res);
			if (neg)
				return -res;
			return res;

		}

		public final long readLong() throws IOException {
			int c = read();
			boolean neg=false;
			while (isSpaceChar(c)) {
				c = read();
			}
			char d=(char)c;
			//log("d:"+d);
			if (d=='-') {
				neg=true;
				c = read();
			}
			long res = 0;
			do {
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			//log("res:"+res);
			if (neg)
				return -res;
			return res;

		}

		private boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}
	}

}


//package round524;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;

public class D {
	InputStream is;
	PrintWriter out;
	String INPUT = "";

	long I = 4000000000000000007L;

	void solve()
	{
		// 1 5 13
		outer:
		for(int T = ni();T > 0;T--){
			long n = nl(), K = nl();
			long inf = 0;
			long sup = 0;
			for(int d = 1;d <= n;d++){
				inf += pow(2,d)-1;
				if(inf >= I)inf = I;
				sup += pow(2,d)-1 + mul(pow(2,d+1)-3, (pow(4,n-d)-1)/3);
				if(sup >= I)sup = I;
//				tr(d, inf, sup);
				if(inf <= K && K <= sup){
					out.println("YES " + (n-d));
					continue outer;
				}
			}
			out.println("NO");
		}
	}

	long mul(long a, long b)
	{
		if((double)a*b > I)return I;
		return a*b;
	}

	long pow(int b, long d)
	{
		long v = 1;
		for(int i = 1;i <= d;i++){
			if((double)v*b > I)return I;
			v = v * b;
		}
		return v;
	}

	void run() throws Exception
	{
		is = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		out = new PrintWriter(System.out);

		long s = System.currentTimeMillis();
		solve();
		out.flush();
		tr(System.currentTimeMillis()-s+"ms");
	}

	public static void main(String[] args) throws Exception { new D().run(); }

	private byte[] inbuf = new byte[1024];
	public int lenbuf = 0, ptrbuf = 0;

	private int readByte()
	{
		if(lenbuf == -1)throw new InputMismatchException();
		if(ptrbuf >= lenbuf){
			ptrbuf = 0;
			try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
			if(lenbuf <= 0)return -1;
		}
		return inbuf[ptrbuf++];
	}

	private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
	private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }

	private double nd() { return Double.parseDouble(ns()); }
	private char nc() { return (char)skip(); }

	private String ns()
	{
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	private char[] ns(int n)
	{
		char[] buf = new char[n];
		int b = skip(), p = 0;
		while(p < n && !(isSpaceChar(b))){
			buf[p++] = (char)b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}

	private char[][] nm(int n, int m)
	{
		char[][] map = new char[n][];
		for(int i = 0;i < n;i++)map[i] = ns(m);
		return map;
	}

	private int[] na(int n)
	{
		int[] a = new int[n];
		for(int i = 0;i < n;i++)a[i] = ni();
		return a;
	}

	private int ni()
	{
		int num = 0, b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}

		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private long nl()
	{
		long num = 0;
		int b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}

		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private boolean oj = System.getProperty("ONLINE_JUDGE") != null;
	private void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }
}


import java.io.*;
import java.math.BigInteger;
import java.util.StringTokenizer;
import java.util.function.Function;

public class D {
    public static void main(String[] args) throws IOException {
        try (Input input = new StandardInput(); PrintWriter writer = new PrintWriter(System.out)) {
            long[] s = new long[40];
            for (int i = 1; i < s.length; i++) {
                s[i] = 1 + 4 * s[i - 1];
                if (i >= 32) {
                    s[i] = Long.MAX_VALUE;
                }
            }
            Function<Integer, Long> getS = (i) -> (i < s.length) ? s[i] : Long.MAX_VALUE;
            int t = input.nextInt();
            testCase:
            for (int tt = 0; tt < t; tt++) {
                int n = input.nextInt();
                long k = input.nextLong();
                long kk = 1;
                BigInteger maxDivisions = BigInteger.ZERO;
                for (int division = 1; division <= n; division++) {
                    long needToDivide = (1L << division) - 1;
                    if (needToDivide > k) {
                        writer.println("NO");
                        continue testCase;
                    }
                    k -= needToDivide;
                    maxDivisions = maxDivisions.add(BigInteger.valueOf(kk).multiply(BigInteger.valueOf(getS.apply(n - division))));
                    if (maxDivisions.compareTo(BigInteger.valueOf(k)) >= 0) {
                        writer.println("YES " + (n - division));
                        continue testCase;
                    }
                    kk += (1L << division + 1);
                }
                writer.println("NO");
            }
        }
    }

    interface Input extends Closeable {
        String next() throws IOException;

        default int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        default long nextLong() throws IOException {
            return Long.parseLong(next());
        }
    }

    private static class StandardInput implements Input {
        private final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

        private StringTokenizer stringTokenizer;

        @Override
        public void close() throws IOException {
            reader.close();
        }

        @Override
        public String next() throws IOException {
            if (stringTokenizer == null || !stringTokenizer.hasMoreTokens()) {
                stringTokenizer = new StringTokenizer(reader.readLine());
            }
            return stringTokenizer.nextToken();
        }
    }
}


import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.*;
import java.util.*;
import java.util.LinkedList;
import java.math.*;
import java.lang.*;
import java.util.PriorityQueue;
import static java.lang.Math.*;
@SuppressWarnings("unchecked")
public class Solution implements Runnable {
    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private SpaceCharFilter filter;
        private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars==-1)
                throw new InputMismatchException();

            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                }
                catch (IOException e) {
                    throw new InputMismatchException();
                }

                if(numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            }
            catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
        public int nextInt() {
            int c = read();

            while(isSpaceChar(c))
                c = read();

            int sgn = 1;

            if (c == '-') {
                sgn = -1;
                c = read();
            }

            int res = 0;
            do {
                if(c<'0'||c>'9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));

            return res * sgn;
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;

            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));
                return res * sgn;
        }

        public double nextDouble() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            double res = 0;
            while (!isSpaceChar(c) && c != '.') {
                if (c == 'e' || c == 'E')
                    return res * Math.pow(10, nextInt());
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            if (c == '.') {
                c = read();
                double m = 1;
                while (!isSpaceChar(c)) {
                    if (c == 'e' || c == 'E')
                        return res * Math.pow(10, nextInt());
                    if (c < '0' || c > '9')
                        throw new InputMismatchException();
                    m /= 10;
                    res += (c - '0') * m;
                    c = read();
                }
            }
            return res * sgn;
        }

        public String readString() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            }
            while (!isSpaceChar(c));

            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public String next() {
            return readString();
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }
    }
    public static long min(long a,long b)
    {
        if(a>b)
        {
            return b;
        }
        return a;
    }
    public static int min(int a,int b)
    {
        if(a>b)
        {
            return b;
        }
        return a;
    }
    public static long max(long a,long b)
    {
        if(a>b)
        {
            return a;
        }
        return b;
    }
    public static int max(int a,int b)
    {
        if(a>b)
        {
            return a;
        }
        return b;
    }
    static class pair
    {
      long x;
      long y;
      pair(long x,long y)
      {
        this.x = x;
        this.y = y;
      }
      public String toString()
      {
        return x+" "+y;
      }
    }
    public static int gcd(int a,int b)
    {
        if(a==0)
        return b;
        if(b==0)
        return a;
        while((a%=b)!=0&&(b%=a)!=0);
        return a^b;
    }
    static int num = (int)1e6;
    public static int random(int min,int max)
    {
      return min+(int)((max-min)*Math.random());
    }
    float min(float a,float b)
    {
        if(a>b)
        {
            return b;
        }
        return a;
    }
    float dist(float x1,float y1,float x2,float y2)
    {
        return (float)Math.sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
    }
    float mod(float x)
    {
        if(x>0)
        {
            return x;
        }
        return -x;
    }
    public static long pow(long n,int pow)
    {
        long res = 1;
        while(pow!=0)
        {
            if((pow&1)==1)
            {
                res *= n;
            }
            n *= n;
            pow = pow>>1;
        }
        return res;
    }
    public static int bsearch(int n,long k)
    {
        int l = 1;
        int r = n;
        while(r>l)
        {
            int mid = (l+r+1)>>1;
            if(pow(2,mid+1)-mid-2<=k)
            {
                l = mid;
            }
            else
            {
                r = mid-1;
            }
        }
        if(pow(2,l+1)-l-2==0&&pow(2,l+1)-l-2==k)
        {
            return 0;
        }
        else if(pow(2,l+1)-l-2<=k)
        {
            return l;
        }
        return 0;
    }
    public static boolean valid(int n,long k,int steps)
    {
        long total_max = (pow(4,n)-1)/3;
        long cant_be = ((pow(4,n-steps)-1)/3)*(pow(2,steps+1)-1);
        long available = total_max-cant_be;
        if(available>=k)
        {
            return true;
        }
        return false;
    }
    public static void main(String args[]) throws Exception {
        new Thread(null, new Solution(),"Main",1<<26).start();
    }    public void run() {
      InputReader sc  = new InputReader(System.in);
      PrintWriter out = new PrintWriter(System.out);
      int t1 = sc.nextInt();
      while(t1-->0)
      {
        int n = sc.nextInt();
        long k = sc.nextLong();
        if(n>31)
        {
            out.println("YES "+(n-1));
            continue;
        }
        int steps = bsearch(n,k);
        if(steps==0)
        {
            if(k==0)
                out.println("YES "+n);
            else
                out.println("NO");
        }
        if(valid(n,k,steps))
        {
            out.println("YES "+(n-steps));
        }
        else
        {
            out.println("NO");
        }
      }
      out.close();
  }
}


import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.TreeMap;

public class Main {

	static class Task {

		int NN = 500005;
		int MOD = 1000000007;
		int INF = 2000000000;
		long INFINITY = 2000000000000000000L;

		public void solve(InputReader in, PrintWriter out) {
			int t = in.nextInt();
			while(t-->0) {
				long n = in.nextLong();
				long k = in.nextLong();
				if(n < 32 && k > ((1L<<(2L*n))-1L)/3L) {
					out.println("NO");continue;
				}
				if(n == 2 && k == 3) {
					out.println("NO");continue;
				}
				if(n >= 32) {
					out.println("YES "+ (n-1));continue;
				}
				boolean done = false;
				for(long i=1;i<=n;++i) {
					if(k < (1L<<(i+2L))-i-3L) {
						done = true;
						out.println("YES " + (n - i));break;
					}
				}
				if(!done) {
					out.println("YES 0");
				}
			}
		}

	}

	static void prepareIO(boolean isFileIO) {
		//long t1 = System.currentTimeMillis();
		Task solver = new Task();
		// Standard IO
		if(!isFileIO) {
			InputStream inputStream = System.in;
	        OutputStream outputStream = System.out;
	        InputReader in = new InputReader(inputStream);
	        PrintWriter out = new PrintWriter(outputStream);
	        solver.solve(in, out);
	        //out.println("time(s): " + (1.0*(System.currentTimeMillis()-t1))/1000.0);
	        out.close();
		}
        // File IO
		else {
			String IPfilePath = System.getProperty("user.home") + "/Downloads/ip.in";
	        String OPfilePath = System.getProperty("user.home") + "/Downloads/op.out";
	        InputReader fin = new InputReader(IPfilePath);
	        PrintWriter fout = null;
	        try {
				fout = new PrintWriter(new File(OPfilePath));
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}
	        solver.solve(fin, fout);
	        //fout.println("time(s): " + (1.0*(System.currentTimeMillis()-t1))/1000.0);
	        fout.close();
		}
	}

	public static void main(String[] args) {
        prepareIO(false);
	}

	static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public InputReader(String filePath) {
        	File file = new File(filePath);
            try {
				reader = new BufferedReader(new FileReader(file));
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
            tokenizer = null;
        }

        public String nextLine() {
        	String str = "";
        	try {
				str = reader.readLine();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
        	return str;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
        	return Double.parseDouble(next());
        }

    }

}


import java.io.*;
import java.math.*;
import java.util.*;

public class OlyaAndMagicalSquare {
	public static void solveCase(FastIO io) {
		int N = io.nextInt();
		long K = io.nextLong();

		CountMap cm = new CountMap();
		cm.increment(N, BigInteger.ONE);
		long rem = K;
		int moves = 1;
		int sqSize = N;
		while (sqSize > 0) {
			long need = (1L << moves) - 1;
			BigInteger biNeed = BigInteger.valueOf(need);
			cm.decrement(sqSize, biNeed);
			if (need > rem) {
				break;
			}
			cm.increment(sqSize - 1, biNeed.multiply(BigInteger.valueOf(4)));
			rem -= need;
			++moves;
			--sqSize;
		}

		BigInteger biRem = BigInteger.valueOf(rem);
		for (int i = N; i > 0; --i) {
			BigInteger have = cm.getCount(i);
			if (have.compareTo(biRem) >= 0) {
				biRem = BigInteger.ZERO;
				break;
			}
			biRem = biRem.subtract(have);
			cm.decrement(i, have);
			cm.increment(i - 1, have.multiply(BigInteger.valueOf(4)));
		}
		if (biRem.equals(BigInteger.ZERO)) {
			io.printf("YES %d\n", sqSize);
		} else {
			io.println("NO");
		}
	}

	private static class CountMap extends HashMap<Integer, BigInteger> {
		public void increment(int k, BigInteger v) {
			put(k, getCount(k).add(v));
		}

		public void decrement(int k, BigInteger v) {
			BigInteger next = getCount(k).subtract(v);
			if (next.equals(BigInteger.ZERO)) {
				remove(k);
			} else {
				put(k, next);
			}
		}

		public BigInteger getCount(int k) {
			return getOrDefault(k, BigInteger.ZERO);
		}
	}

	public static void solve(FastIO io) {
		int T = io.nextInt();

		for (int t = 0; t < T; ++t) {
			solveCase(io);
		}
	}

	public static class FastIO {
		private InputStream reader;
		private PrintWriter writer;

		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;

		public FastIO(InputStream r, OutputStream w) {
			reader = r;
			writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(w)));
		}

		public int read() {
			if (numChars == -1)
				throw new InputMismatchException();
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = reader.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public String nextLine() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndOfLine(c));
			return res.toString();
		}

		public String nextString() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public long nextLong() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public int nextInt() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		// TODO: read this byte-by-byte like the other read functions.
		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

		public int[] nextIntArray(int n) {
			return nextIntArray(n, 0);
		}

		public int[] nextIntArray(int n, int off) {
			int[] arr = new int[n + off];
			for (int i = 0; i < n; i++) {
				arr[i + off] = nextInt();
			}
			return arr;
		}

		public long[] nextLongArray(int n) {
			return nextLongArray(n, 0);
		}

		public long[] nextLongArray(int n, int off) {
			long[] arr = new long[n + off];
			for (int i = 0; i < n; i++) {
				arr[i + off] = nextLong();
			}
			return arr;
		}

		private boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		private boolean isEndOfLine(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}

		public void print(Object... objects) {
			for (int i = 0; i < objects.length; i++) {
				if (i != 0) {
					writer.print(' ');
				}
				writer.print(objects[i]);
			}
		}

		public void println(Object... objects) {
			print(objects);
			writer.println();
		}

		public void printArray(int[] arr) {
			for (int i = 0; i < arr.length; i++) {
				if (i != 0) {
					writer.print(' ');
				}
				writer.print(arr[i]);
			}
		}

		public void printArray(long[] arr) {
			for (int i = 0; i < arr.length; i++) {
				if (i != 0) {
					writer.print(' ');
				}
				writer.print(arr[i]);
			}
		}

		public void printlnArray(int[] arr) {
			printArray(arr);
			writer.println();
		}

		public void printlnArray(long[] arr) {
			printArray(arr);
			writer.println();
		}

		public void printf(String format, Object... args) {
			print(String.format(format, args));
		}

		public void flush() {
			writer.flush();
		}
	}

	public static void main(String[] args) {
		FastIO io = new FastIO(System.in, System.out);
		solve(io);
		io.flush();
	}
}


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 Rustam Musin (t.me/musin_acm)
 */
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);
        DOlyaIMagicheskiiKvadrat solver = new DOlyaIMagicheskiiKvadrat();
        solver.solve(1, in, out);
        out.close();
    }

    static class DOlyaIMagicheskiiKvadrat {
        long inf = (long) 1e18 + 1;
        long[] maxLen;

        public void solve(int testNumber, InputReader in, OutputWriter out) {
            maxLen = new long[100];
            maxLen[1] = 0;
            for (int i = 1; i < maxLen.length; i++) {
                maxLen[i] = Math.min(inf, maxLen[i - 1] * 4 + 1);
            }
            if (false) {
                for (int n = 1; n <= 3; n++) {
                    for (int k = 1; k <= maxSplitCount(n) + 20; k++) {
                        out.print(n + " " + k + " ");
                        int res = solve(n, k);
                        if (res == -1) {
                            out.printLine("NO");
                        } else {
                            out.printLine("YES " + res);
                        }
                    }
                }
                return;
            }
            int q = in.readInt();
            while (q-- > 0) {
                int n = in.readInt();
                long k = in.readLong();
                int res = solve(n, k);
                if (res == -1) {
                    out.printLine("NO");
                    continue;
                }
                out.printLine("YES " + res);
            }
        }

        long maxSplitCount(int n) {
            if (n >= maxLen.length) {
                return inf;
            }
            return maxLen[n];
        }

        int solve(int n, long k) {
            if (maxSplitCount(n) < k) {
                return -1;
            }
            int at = 0;
            while (maxSplitCount(at + 1) <= k) {
                at++;
            }
            int curSideLog = n - at;
            k -= maxSplitCount(at);
            double sideLen = Math.pow(2, n - curSideLog);
            double pathLen = sideLen * 2 - 1;
            if (curSideLog > 0 && pathLen <= k) {
                return curSideLog - 1;
            }
            double area = sideLen * sideLen;
            double otherArea = area - pathLen;
            if (otherArea * (double) maxSplitCount(curSideLog) >= k) {
                return curSideLog;
            }
            return -1;
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int readInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public long readLong() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void print(Object... objects) {
            for (int i = 0; i < objects.length; i++) {
                if (i != 0) {
                    writer.print(' ');
                }
                writer.print(objects[i]);
            }
        }

        public void printLine(Object... objects) {
            print(objects);
            writer.println();
        }

        public void close() {
            writer.close();
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author kessido
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        DOlyaAndMagicalSquare solver = new DOlyaAndMagicalSquare();
        int testCount = Integer.parseInt(in.next());
        for (int i = 1; i <= testCount; i++)
            solver.solve(i, in, out);
        out.close();
    }

    static class DOlyaAndMagicalSquare {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.NextInt();
            long k = in.NextLong();
            if (k == 0) {
                out.println("YES " + n);
                return;
            }
            long operationTillNow = 0, numberOfCubeOnTheSide = 1;
            ArrayList<CubeCount> cubes = new ArrayList<>();

            for (int i = n - 1; i >= 0; i--) {
                cubes.add(new CubeCount(i, (numberOfCubeOnTheSide - 1) * 2 * 2 + 1));
                operationTillNow = operationTillNow + 2 * numberOfCubeOnTheSide - 1;
                numberOfCubeOnTheSide *= 2;
                long operationLeft = k - operationTillNow;
                if (operationLeft == 0) {
                    out.println("YES " + i);
                    return;
                } else if (operationLeft < 0) {
                    out.println("NO");
                    return;
                }
                for (CubeCount c : cubes) {
                    if (!c.hasLessThen(operationLeft)) {
                        out.println("YES " + i);
                        return;
                    } else {
                        operationLeft = c.removeMeFrom(operationLeft);
                    }
                }
                if (operationLeft <= 0) {
                    out.println("YES " + i);
                    return;
                }
            }
            out.println("NO");
            return;
        }

        class CubeCount {
            int sideSizeLogScale;
            long repeats;

            public CubeCount(int sideSizeLogScale, long repeats) {
                this.repeats = repeats;
                this.sideSizeLogScale = sideSizeLogScale;
            }

            public boolean hasLessThen(long k) {
                return hasLessThen(k, sideSizeLogScale, repeats);
            }

            private boolean hasLessThen(long k, int sideLog, long repeats) {
                while (true) {
                    if (k <= 0) return false;
                    if (sideLog == 0) return true;
                    k -= repeats;
                    sideLog--;
                    repeats *= 4;
                }
            }

            public long removeMeFrom(long k) {
                return removeMeFrom(k, sideSizeLogScale, repeats);
            }

            private long removeMeFrom(long k, int sideLog, long repeats) {
                while (true) {
                    if (sideLog == 0) return k;
                    k -= repeats;
                    sideLog--;
                    repeats *= 4;
                }
            }

        }

    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine(), " \t\n\r\f,");
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int NextInt() {
            return Integer.parseInt(next());
        }

        public long NextLong() {
            return Long.parseLong(next());
        }

    }
}


import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;

public class D {

    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
//        System.err.println(f(1));

//        System.err.println(f(4));
        int tc = sc.nextInt();
        out: while(tc-->0){
            long n = sc.nextInt();

            long k = sc.nextLong();
            if(n >= 32){
                pw.println("YES " + (n-1));
                continue;
            }

            long steps = 0;
            for (int i = 1;; i++) {
                long cnt = ((1l<<(i+1))-1);
                steps += ((1l<<(i))-1);
                if(steps > k)
                    break;
                if(steps > f(n))
                    break;
//                long rem = k-((1<<i)-1);
                long rem = k-steps;
//                System.err.println("steps:" + steps + " cnt:" + cnt + " f:"  + f(n-i));
//                System.err.println("rem: " + (f(n) - steps - cnt*f(n-i)));
                if(rem <= f(n) - steps - cnt*f(n-i)){
                    pw.println("YES " + (n-i));
                    continue out;
                }
            }

            pw.println("NO");
        }

        pw.flush();
        pw.close();
    }

    static long f(long n){
        if(n == 0)
            return 0;
        long ans = 0;
        for (int i = 0; i < n; i++) {
            ans += 1l<<(2*i);
        }
        return ans;
    }

    static int[][] matMul(int[][] A, int[][] B, int p, int q, int r)	//C(p x r) = A(p x q) x (q x r) -- O(p x q x r)
    {
        int[][] C = new int[p][r];
        for(int i = 0; i < p; ++i)
            for(int j = 0; j < r; ++j)
                for(int k = 0; k < q; ++k)
                    C[i][j] += A[i][k] * B[k][j];
        return C;
    }

    /*
     * 4. Square Matrix Exponentiation
     */
    static int[][] matPow(int[][] base, int p)
    {
        int n = base.length;
        int[][] ans = new int[n][n];
        for(int i = 0; i < n; i++)
            ans[i][i] = 1;
        while(p != 0)
        {
            if((p & 1) == 1)
                ans = matMul(ans, base, n, n, n);
            base = matMul(base, base, n, n, n);
            p >>= 1;
        }

        return ans;
    }

    static int[][] packU(int n, int[] from, int[] to) {
        int[][] g = new int[n][];
        int[] p = new int[n];
        for (int f : from)
            p[f]++;
        for (int t : to)
            p[t]++;
        for (int i = 0; i < n; i++)
            g[i] = new int[p[i]];
        for (int i = 0; i < from.length; i++) {
            g[from[i]][--p[from[i]]] = to[i];
            g[to[i]][--p[to[i]]] = from[i];
        }
        return g;
    }
    static int pow(int n, int p){
        int ans = 1;
        for (int i = 0; i < p; i++) {
            ans *= n;
        }
        return ans;
    }

    static int[][] packD(int n, int[] from, int[] to) {
        int[][] g = new int[n][];
        int[] p = new int[n];
        for (int f : from) if(f != -1) p[f]++;
        for (int i = 0; i < n; i++) g[i] = new int[p[i]];
        for (int i = 0; i < from.length; i++) if(from[i] != -1) {g[from[i]][--p[from[i]]] = to[i];}
        return g;
    }

    static void shuffle(int[] a)
    {
        int n = a.length;
        for(int i = 0; i < n; i++)
        {
            int r = i + (int)(Math.random() * (n - i));
            int tmp = a[i];
            a[i] = a[r];
            a[r] = tmp;
        }
    }

    static class Scanner
    {
        StringTokenizer st; BufferedReader br;
        public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}
        public Scanner(String s) throws FileNotFoundException {	br = new BufferedReader(new FileReader(new File(s)));}
        public String next() throws IOException {while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine());return st.nextToken();}
        public int nextInt() throws IOException {return Integer.parseInt(next());}
        public long nextLong() throws IOException {return Long.parseLong(next());}
        public String nextLine() throws IOException {return br.readLine();}
        public boolean ready() throws IOException {return br.ready();}
    }
}


import java.io.*;
import java.math.*;
import java.util.*;

public class OlyaAndMagicalSquare {
	public static void solveCase(FastIO io) {
		int N = io.nextInt();
		long K = io.nextLong();

		CountMap cm = new CountMap();
		cm.increment(N, BigInteger.ONE);
		long rem = K;
		int moves = 1;
		int sqSize = N;
		while (sqSize > 0) {
			long need = (1L << moves) - 1;
			BigInteger biNeed = BigInteger.valueOf(need);
			cm.decrement(sqSize, biNeed);
			if (need > rem) {
				break;
			}
			cm.increment(sqSize - 1, biNeed.multiply(BigInteger.valueOf(4)));
			rem -= need;
			++moves;
			--sqSize;
		}

		BigInteger biRem = BigInteger.valueOf(rem);
		for (int i = N; i > 0; --i) {
			BigInteger have = cm.getCount(i);
			if (have.compareTo(biRem) >= 0) {
				biRem = BigInteger.ZERO;
				break;
			}
			biRem = biRem.subtract(have);
			cm.decrement(i, have);
			cm.increment(i - 1, have.multiply(BigInteger.valueOf(4)));
		}
		if (biRem.equals(BigInteger.ZERO)) {
			io.printf("YES %d\n", sqSize);
		} else {
			io.println("NO");
		}

		// long N = io.nextLong();
		// long K = io.nextLong();

		// // io.println(1L << 62);

		// boolean good;
		// if (N >= 31) {
		// 	good = true;
		// } else {
		// 	good = ((1L << (N << 1)) / 3 >= K);
		// }

		// if (!good) {
		// 	io.println("NO");
		// 	return;
		// }

		// int split = getMaxSplit(K);

		// if (N >= 40) {
		// 	io.printf("YES %d\n", N - split);
		// 	return;
		// }

		// long used = (1L << split) - 1;
		// long rem = K - used;

	}

	private static class CountMap extends HashMap<Integer, BigInteger> {
		public void increment(int k, BigInteger v) {
			put(k, getCount(k).add(v));
		}

		public void decrement(int k, BigInteger v) {
			BigInteger next = getCount(k).subtract(v);
			if (next.equals(BigInteger.ZERO)) {
				remove(k);
			} else {
				put(k, next);
			}
		}

		public BigInteger getCount(int k) {
			return getOrDefault(k, BigInteger.ZERO);
		}
	}

	private static int getMaxSplit(long k) {
		for (int i = 1;; ++i) {
			if ((1L << (i + 1)) - 2 - i > k) {
				return i - 1;
			}
		}
	}

	public static void solve(FastIO io) {
		int T = io.nextInt();

		for (int t = 0; t < T; ++t) {
			solveCase(io);
		}
	}

	public static class FastIO {
		private InputStream reader;
		private PrintWriter writer;

		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;

		public FastIO(InputStream r, OutputStream w) {
			reader = r;
			writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(w)));
		}

		public int read() {
			if (numChars == -1)
				throw new InputMismatchException();
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = reader.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public String nextLine() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndOfLine(c));
			return res.toString();
		}

		public String nextString() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public long nextLong() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public int nextInt() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		// TODO: read this byte-by-byte like the other read functions.
		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

		public int[] nextIntArray(int n) {
			return nextIntArray(n, 0);
		}

		public int[] nextIntArray(int n, int off) {
			int[] arr = new int[n + off];
			for (int i = 0; i < n; i++) {
				arr[i + off] = nextInt();
			}
			return arr;
		}

		public long[] nextLongArray(int n) {
			return nextLongArray(n, 0);
		}

		public long[] nextLongArray(int n, int off) {
			long[] arr = new long[n + off];
			for (int i = 0; i < n; i++) {
				arr[i + off] = nextLong();
			}
			return arr;
		}

		private boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		private boolean isEndOfLine(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}

		public void print(Object... objects) {
			for (int i = 0; i < objects.length; i++) {
				if (i != 0) {
					writer.print(' ');
				}
				writer.print(objects[i]);
			}
		}

		public void println(Object... objects) {
			print(objects);
			writer.println();
		}

		public void printArray(int[] arr) {
			for (int i = 0; i < arr.length; i++) {
				if (i != 0) {
					writer.print(' ');
				}
				writer.print(arr[i]);
			}
		}

		public void printArray(long[] arr) {
			for (int i = 0; i < arr.length; i++) {
				if (i != 0) {
					writer.print(' ');
				}
				writer.print(arr[i]);
			}
		}

		public void printlnArray(int[] arr) {
			printArray(arr);
			writer.println();
		}

		public void printlnArray(long[] arr) {
			printArray(arr);
			writer.println();
		}

		public void printf(String format, Object... args) {
			print(String.format(format, args));
		}

		public void flush() {
			writer.flush();
		}
	}

	public static void main(String[] args) {
		FastIO io = new FastIO(System.in, System.out);
		solve(io);
		io.flush();
	}
}


import java.util.Scanner;

public class Solution {
    public static void main(String[] args) {
        Solution solution = new  Solution();
        solution.solve();
    }

    private void solve() {
        Scanner in = new Scanner(System.in);
        int t = in.nextInt();
        while (t -- > 0) {
            long n = in.nextLong();
            long k = in.nextLong();

            System.out.println(solve(n, k));
        }
    }

    private String solve(long n, long k) {
        if (n > 31) return "YES " + (n - 1);
        if (k > f(n)) return "NO";

        long square = 1;
        long splitDone = 0;
        long size = n;
        long splitLeft = 0;

        while (splitDone + square <= k && size > 0) {
            splitDone += square;
            --size;
            splitLeft += (square * 2 - 1) * f(size);
            square = square * 2 + 1;
        }
//        System.out.println(square + " " + splitDone + " " + size + " " + splitLeft);
        if (k > splitDone + splitLeft) return "NO";
        else return "YES " + size;
    }

    private long f(long x) {
        return ((1L << (2 * x)) - 1) / 3;
    }
}


import java.util.*;
import java.io.*;

// Solution

public class Main
{
  public static void main (String[] argv)
  {
	  new Main();
  }

  boolean test = false;

  final int MOD = 998244353;

  public Main()   {
	 FastReader in = new FastReader(new BufferedReader(new InputStreamReader(System.in)));
	 //FastReader in = new FastReader(new BufferedReader(new FileReader("Main.in")));
     final int N = 50; //big enough
     long[] f = new long[N];
     int maxN = 50;
     f[0] = 0;
     for (int i = 1; i < N; i++) {
         if (Long.MAX_VALUE / 4 <= f[i-1]) {
             maxN = i - 1;
             break;
         }
         f[i] = f[i-1] * 4 + 1;
     }

     long[] a = new long[N];
     long[] b = new long[N];

     int nt = in.nextInt();

     for (int ii = 1; ii <= nt; ii++) {
         int n = in.nextInt();
         long k = in.nextLong();

         if (k == 0) {
             System.out.println("YES " + n);
             continue;
         }

         if (n - 1> maxN || k <= 1 + f[n-1]) {
             System.out.println("YES " + (n - 1));
             continue;
         }
         if (n - 1 == maxN) {
             System.out.println("YES " + (n - 2));
             continue;
         }

         // now: n <= maxN
         if (k > f[n]) {
             System.out.println("NO");
             continue;
         }

         if (n == 2) {
             if (k==3) System.out.println("NO");
             else System.out.println("YES 0");
             continue;
         }

         a[1] = 1;
         b[1] = f[n-1];
         int ret = 0;
         for (int i = 2; i <= n; i++) {
             a[i] = a[i-1] + (1L << i) - 1;
             b[i] = b[i-1] + (2 * (1L << i) - 3) * f[n-i];
             if (a[i] + b[i] >= k) {
                 ret = n - i;
                 break;
             }
         }
         System.out.println("YES " + ret);
     }
  }

  private int dist(int x, int y, int xx, int yy) {
      return abs(x - xx) + abs(y - yy);
  }

  private boolean less(int x, int y, int xx, int yy) {
      return x < xx || y > yy;
  }

  private int mul(int x, int y) {
      return (int)(1L * x * y % MOD);
  }

  private int add(int x, int y) {
      return (x + y) % MOD;
  }

  private int nBit1(int v) {
      int v0 = v;
      int c = 0;
      while (v != 0) {
          ++c;
          v = v & (v - 1);
      }
      return c;
  }

  private long abs(long v) {
      return v > 0 ? v : -v;
  }

  private int abs(int v) {
      return v > 0 ? v : -v;
  }

  private int common(int v) {
      int c = 0;
      while (v != 1) {
          v = (v >>> 1);
          ++c;
      }

      return c;
  }

  private void reverse(char[] a, int i, int j) {
      while (i < j) {
          swap(a, i++, j--);
      }
  }

  private void swap(char[] a, int i, int j) {
      char t = a[i];
      a[i] = a[j];
      a[j] = t;
  }

  private int gcd(int x, int y) {
      if (y == 0) return x;
      return gcd(y, x % y);
  }
  private long gcd(long x, long y) {
      if (y == 0) return x;
      return gcd(y, x % y);
  }
  private int max(int a, int b) {
      return a >  b ? a : b;
  }

  private long max(long a, long b) {
      return a >  b ? a : b;
  }

  private int min(int a, int b) {
      return a >  b ? b : a;
  }

  private long min(long a, long b) {
      return a >  b ? b : a;
  }

  static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader(BufferedReader in)
        {
            br = in;
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    String line = br.readLine();
                    if (line == null || line.length() == 0) return "";
                    st = new StringTokenizer(line);
                }
                catch (IOException  e)
                {
                    return "";
                    //e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                return "";
                //e.printStackTrace();
            }
            return str;
        }
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @author Don Li
 */
public class OlyaAndMagicalSquare {
    void solve() {
        long[] dp = new long[32];
        dp[0] = 0;
        for (int i = 1; i < 32; i++) {
            dp[i] = 4 * dp[i - 1] + 1;
        }

        int T = in.nextInt();
        L:
        while (T-- > 0) {
            int n = in.nextInt(); long k = in.nextLong();

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

            long tot = 0;
            for (int a = n - 1; a >= 0; a--) {
                k -= (1L << (n - a)) - 1;
                if (k < 0) break;
                if (k == 0) {
                    out.println("YES " + a);
                    continue L;
                }
                long limit = (1L << (n + 1 - a)) - 3;
                if (k <= tot || dp[a] > 0 && (k - tot + dp[a] - 1) / dp[a] <= limit) {
                    out.println("YES " + a);
                    continue L;
                }
                tot += dp[a] * limit;
            }
            out.println("NO");
        }
    }

    public static void main(String[] args) {
        in = new FastScanner(new BufferedReader(new InputStreamReader(System.in)));
        out = new PrintWriter(System.out);
        new OlyaAndMagicalSquare().solve();
        out.close();
    }

    static FastScanner in;
    static PrintWriter out;

    static class FastScanner {
        BufferedReader in;
        StringTokenizer st;

        public FastScanner(BufferedReader in) {
            this.in = in;
        }

        public String nextToken() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(in.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextToken());
        }

        public long nextLong() {
            return Long.parseLong(nextToken());
        }

        public double nextDouble() {
            return Double.parseDouble(nextToken());
        }
    }
}