#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
typedef long long ll;
ll K[100010], N[100010];
int main()
{
    for (int i = 1; i < 100; i++)
        K[i] = K[i - 1] + (1ll << (i - 1)) - 1;
    for (int i = 1; i < 100; i++)
        N[i] = (N[i - 1] << 2) + 1;
    ll T, n, k;
    scanf("%lld", &T);
    while (T--)
    {
        scanf("%lld%lld", &n, &k);
        if (k > N[n])
            puts("NO");
        else
        {
            for (int i = 1; i < 100; i++)
            {
                if (K[i - 1] >= k)
                {
                    printf("YES %lld\n", n - i + 1);
                    break;
                }
            }
        }
    }
    return 0;
}